libyui
YProperty.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YProperty.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YProperty_h
26 #define YProperty_h
27 
28 #include <string>
29 #include <vector>
30 
31 
32 
33 enum YPropertyType
34 {
35  YUnknownPropertyType = 0,
36  YOtherProperty, // requires futher checking
37  YStringProperty, // const std::string &
38  YBoolProperty, // bool
39  YIntegerProperty // YCP Integer == C++ long long
40 };
41 
42 class YWidget;
43 class YProperty;
44 
45 typedef long long YInteger;
46 
47 
51 class YProperty
52 {
53 public:
58  YProperty( const std::string & name, YPropertyType type, bool isReadOnly = false )
59  : _name( name )
60  , _type( type )
61  , _isReadOnly( isReadOnly )
62  {}
63 
67  std::string name() const { return _name; }
68 
72  YPropertyType type() const { return _type; }
73 
77  bool isReadOnly() const { return _isReadOnly; }
78 
82  std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
83 
87  static std::string typeAsStr( YPropertyType type );
88 
89 private:
90 
91  std::string _name;
92  YPropertyType _type;
93  bool _isReadOnly;
94 };
95 
96 
105 {
106 public:
107 
111  YPropertyValue( const std::string & str ):
112  _type( YStringProperty ), _stringVal( str ) {}
113 
117  YPropertyValue( const char * str ):
118  _type( YStringProperty ), _stringVal( str ) {}
119 
123  explicit YPropertyValue( bool b ):
124  _type( YBoolProperty ), _boolVal( b ) {}
125 
129  explicit YPropertyValue( YInteger num ):
130  _type( YIntegerProperty ), _integerVal( num ) {}
131 
135  explicit YPropertyValue( int num ):
136  _type( YIntegerProperty ), _integerVal( num ) {}
137 
138  explicit YPropertyValue( YPropertyType type ) :
139  _type( type ) {}
140 
145  _type( YUnknownPropertyType ) {}
146 
150  ~YPropertyValue();
151 
157  bool operator==( const YPropertyValue &other ) const;
158 
163  bool operator!=( const YPropertyValue &other ) const;
164 
169  YPropertyType type() const { return _type; }
170 
174  std::string typeAsStr() const { return YProperty::typeAsStr( _type ); }
175 
180  std::string stringVal() const { return _stringVal; }
181  bool boolVal() const { return _boolVal; }
182  YInteger integerVal() const { return _integerVal; }
183 
184 
185 private:
186 
187  YPropertyType _type;
188  std::string _stringVal;
189  bool _boolVal;
190  YInteger _integerVal;
191 };
192 
193 
198 {
199 public:
203  YPropertySet();
204 
211  void check( const std::string & propertyName ) const;
212 
222  void check( const std::string & propertyName, YPropertyType type ) const;
223 
227  void check( const YProperty & prop ) const
228  { check( prop.name(), prop.type() ); }
229 
237  bool contains( const std::string & propertyName ) const throw();
238 
252  bool contains( const std::string & propertyName, YPropertyType type ) const;
253 
257  bool contains( const YProperty & prop ) const
258  { return contains( prop.name(), prop.type() ); }
259 
263  bool isEmpty() const { return _properties.empty(); }
264 
268  int size() const { return (int) _properties.size(); }
269 
273  void add( const YProperty & prop );
274 
281  void add( const YPropertySet & otherSet );
282 
283  typedef std::vector<YProperty>::const_iterator const_iterator;
284 
288  const_iterator propertiesBegin() const;
289 
293  const_iterator propertiesEnd() const;
294 
295 private:
296 
303  std::vector<YProperty> _properties;
304 };
305 
306 
307 #endif // YProperty_h
YProperty(const std::string &name, YPropertyType type, bool isReadOnly=false)
Definition: YProperty.h:58
bool isEmpty() const
Definition: YProperty.h:263
YPropertyValue()
Definition: YProperty.h:144
YPropertyValue(int num)
Definition: YProperty.h:135
Definition: YProperty.h:104
const_iterator propertiesEnd() const
Definition: YProperty.cc:171
~YPropertyValue()
Definition: YProperty.cc:50
bool contains(const std::string &propertyName) const
void add(const YProperty &prop)
Definition: YProperty.cc:146
YPropertyType type() const
Definition: YProperty.h:72
Definition: YProperty.h:197
bool operator!=(const YPropertyValue &other) const
Definition: YProperty.cc:76
bool operator==(const YPropertyValue &other) const
Definition: YProperty.cc:54
std::string typeAsStr() const
Definition: YProperty.h:82
int size() const
Definition: YProperty.h:268
std::string name() const
Definition: YProperty.h:67
const_iterator propertiesBegin() const
Definition: YProperty.cc:165
YPropertyValue(const char *str)
Definition: YProperty.h:117
std::string stringVal() const
Definition: YProperty.h:180
YPropertySet()
Definition: YProperty.cc:81
void check(const YProperty &prop) const
Definition: YProperty.h:227
Definition: YProperty.h:51
bool isReadOnly() const
Definition: YProperty.h:77
std::string typeAsStr() const
Definition: YProperty.h:174
bool contains(const YProperty &prop) const
Definition: YProperty.h:257
YPropertyValue(YInteger num)
Definition: YProperty.h:129
YPropertyValue(bool b)
Definition: YProperty.h:123
void check(const std::string &propertyName) const
Definition: YWidget.h:54
YPropertyType type() const
Definition: YProperty.h:169
YPropertyValue(const std::string &str)
Definition: YProperty.h:111