Source code formating unification
[platform/framework/web/wrt.git] / src / view / common / scheme.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file       scheme.cpp
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #include "scheme.h"
23 #include <map>
24 #include <dpl/log/log.h>
25
26 namespace ViewModule {
27 namespace {
28 const char * const type2name[Scheme::COUNT] = {
29     "file",
30     "sms",
31     "mmsto",
32     "mailto",
33     "data",
34     "tel",
35     "http",
36     "https",
37     "widget",
38     "vnd.youtube",
39     "rtsp"
40 };
41
42 typedef std::map<std::string, Scheme::Type> SchemeMap;
43
44 SchemeMap PopulateMap()
45 {
46     LogInfo("Populating scheme map...");
47     SchemeMap map;
48     for (size_t st = Scheme::FILE; st < Scheme::COUNT; ++st) {
49         LogInfo(" * " << type2name[st] << "->" << st);
50         map[type2name[st]] = static_cast<Scheme::Type>(st);
51     }
52     return map;
53 }
54
55 const SchemeMap name2type = PopulateMap();
56 } // namespace
57
58 Scheme::Scheme(const std::string& name) : m_name(name), m_type(INVALID)
59 {
60     m_type = GetType(name);
61 }
62
63 std::string Scheme::GetName (Type type)
64 {
65     Assert(type >= FILE && type < COUNT);
66     return type2name[type];
67 }
68
69 Scheme::Type Scheme::GetType(const std::string& name)
70 {
71     auto it = name2type.find(name);
72     if (it == name2type.end()) {
73         LogError("Invalid scheme: " << name);
74         return INVALID;
75     }
76     return it->second;
77 }
78 } /* namespace ViewModule */