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