b366190198693381fb9b6887a96ee23cfd32c842
[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
28 namespace {
29
30 const char * const type2name[Scheme::COUNT] = {
31         "file",
32         "sms",
33         "mmsto",
34         "mailto",
35         "data",
36         "tel",
37         "http",
38         "https",
39         "widget",
40         "vnd.youtube",
41         "rtsp" };
42
43 typedef std::map<std::string, Scheme::Type> SchemeMap;
44
45 SchemeMap PopulateMap()
46 {
47     LogInfo("Populating scheme map...");
48     SchemeMap map;
49     for(size_t st = Scheme::FILE; st<Scheme::COUNT;++st) {
50         LogInfo(" * " << type2name[st] << "->" << st);
51         map[type2name[st]] = static_cast<Scheme::Type>(st);
52     }
53     return map;
54 }
55
56 const SchemeMap name2type = PopulateMap();
57
58 } // namespace
59
60 Scheme::Scheme(const std::string& name) : m_name(name), m_type(INVALID) {
61     m_type = GetType(name);
62 }
63
64 std::string Scheme::GetName (Type type)
65 {
66     Assert(type >= FILE && type < COUNT);
67     return type2name[type];
68 }
69
70 Scheme::Type Scheme::GetType(const std::string& name)
71 {
72     auto it = name2type.find(name);
73     if(it == name2type.end()) {
74         LogError("Invalid scheme: " << name);
75         return INVALID;
76     }
77     return it->second;
78 }
79
80 } /* namespace ViewModule */