Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-key.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
18 // CLASS HEADER
19 #include <dali/public-api/object/property-key.h>
20
21 namespace Dali
22 {
23 Property::Key::Key(const std::string& key)
24 : type(Key::STRING),
25   indexKey(Property::INVALID_INDEX),
26   stringKey(key)
27 {
28 }
29
30 Property::Key::Key(Property::Index key)
31 : type(Key::INDEX),
32   indexKey(key)
33 {
34 }
35
36 Property::Key::Key(const char* key)
37 : type(Key::STRING),
38   indexKey(Property::INVALID_INDEX),
39   stringKey(key)
40 {
41 }
42
43 bool Property::Key::operator==(const std::string& rhs)
44 {
45   bool result = false;
46   if(type == Key::STRING)
47   {
48     result = (stringKey == rhs);
49   }
50   return result;
51 }
52
53 bool Property::Key::operator==(const char* rhs)
54 {
55   return operator==(std::string(rhs));
56 }
57
58 bool Property::Key::operator==(Property::Index rhs)
59 {
60   bool result = false;
61   if(type == Key::INDEX)
62   {
63     result = (indexKey == rhs);
64   }
65   return result;
66 }
67
68 bool Property::Key::operator==(const Key& rhs)
69 {
70   bool result = false;
71   if(type == Key::STRING && rhs.type == Key::STRING)
72   {
73     result = (stringKey == rhs.stringKey);
74   }
75   else if(type == Key::INDEX && rhs.type == Key::INDEX)
76   {
77     result = (indexKey == rhs.indexKey);
78   }
79   return result;
80 }
81
82 bool Property::Key::operator!=(const std::string& rhs)
83 {
84   return !operator==(rhs);
85 }
86
87 bool Property::Key::operator!=(const char* rhs)
88 {
89   return !operator==(rhs);
90 }
91
92 bool Property::Key::operator!=(Property::Index rhs)
93 {
94   return !operator==(rhs);
95 }
96
97 bool Property::Key::operator!=(const Key& rhs)
98 {
99   return !operator==(rhs);
100 }
101
102 std::ostream& operator<<(std::ostream& stream, const Property::Key& key)
103 {
104   if(key.type == Property::Key::INDEX)
105   {
106     stream << key.indexKey;
107   }
108   else
109   {
110     stream << key.stringKey;
111   }
112   return stream;
113 }
114
115 } // namespace Dali