618875f39bc06734fcac838655996edc20927059
[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 #ifdef APP_SCHEME_ENABLED
39     "app",
40 #endif
41     "vnd.youtube",
42     "rtsp"
43 };
44
45 typedef std::map<std::string, Scheme::Type> SchemeMap;
46
47 SchemeMap PopulateMap()
48 {
49     LogInfo("Populating scheme map...");
50     SchemeMap map;
51     for (size_t st = Scheme::FILE; st < Scheme::COUNT; ++st) {
52         LogInfo(" * " << type2name[st] << "->" << st);
53         map[type2name[st]] = static_cast<Scheme::Type>(st);
54     }
55     return map;
56 }
57
58 const SchemeMap name2type = PopulateMap();
59 } // namespace
60
61 Scheme::Scheme(const std::string& name) : m_name(name), m_type(INVALID)
62 {
63     m_type = GetType(name);
64 }
65
66 std::string Scheme::GetName (Type type)
67 {
68     Assert(type >= FILE && type < COUNT);
69     return type2name[type];
70 }
71
72 Scheme::Type Scheme::GetType(const std::string& name)
73 {
74     auto it = name2type.find(name);
75     if (it == name2type.end()) {
76         LogError("Invalid scheme: " << name);
77         return INVALID;
78     }
79     return it->second;
80 }
81 } /* namespace ViewModule */