tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Widget / Property.h
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  *
18  *
19  * @file       Property.h
20  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #ifndef WIDGET_PROPERTY_H_
26 #define WIDGET_PROPERTY_H_
27
28 #include <string>
29 #include <Commons/Exception.h>
30
31 namespace WrtDeviceApis {
32 namespace Widget {
33
34 template<typename T>
35 class Property
36 {
37   public:
38     explicit Property() :
39         m_value(),
40         m_valid(false)
41     {
42     }
43
44     void setValue(const T& value)
45     {
46         m_value = value;
47         m_valid = true;
48     }
49
50     T getValue() const
51     {
52         if (!m_valid) {
53             Throw(Commons::PlatformException);
54         }
55         return m_value;
56     }
57
58     bool isValid() const
59     {
60         return m_valid;
61     }
62
63     virtual ~Property()
64     {
65     }
66   private:
67     T m_value;
68     bool m_valid;
69 };
70
71 typedef Property<std::string> StringProperty;
72 typedef Property<unsigned int> UIntProperty;
73 }
74 }
75 #endif