libyui
 
Loading...
Searching...
No Matches
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
33enum 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
42class YWidget;
43class YProperty;
44
45typedef long long YInteger;
46
47
52{
53public:
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
89private:
90
91 std::string _name;
92 YPropertyType _type;
93 bool _isReadOnly;
94};
95
96
105{
106public:
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
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
185private:
186
187 YPropertyType _type;
188 std::string _stringVal;
189 bool _boolVal;
190 YInteger _integerVal;
191};
192
193
198{
199public:
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
295private:
296
303 std::vector<YProperty> _properties;
304};
305
306
307#endif // YProperty_h
Definition YProperty.h:198
void check(const YProperty &prop) const
Definition YProperty.h:227
void check(const std::string &propertyName) const
bool isEmpty() const
Definition YProperty.h:263
int size() const
Definition YProperty.h:268
void add(const YProperty &prop)
Definition YProperty.cc:146
void check(const std::string &propertyName, YPropertyType type) const
const_iterator propertiesBegin() const
Definition YProperty.cc:165
const_iterator propertiesEnd() const
Definition YProperty.cc:171
bool contains(const std::string &propertyName, YPropertyType type) const
bool contains(const YProperty &prop) const
Definition YProperty.h:257
YPropertySet()
Definition YProperty.cc:81
bool contains(const std::string &propertyName) const
Definition YProperty.h:105
std::string typeAsStr() const
Definition YProperty.h:174
YPropertyValue(bool b)
Definition YProperty.h:123
YPropertyValue(const std::string &str)
Definition YProperty.h:111
YPropertyValue()
Definition YProperty.h:144
std::string stringVal() const
Definition YProperty.h:180
YPropertyValue(int num)
Definition YProperty.h:135
YPropertyValue(YInteger num)
Definition YProperty.h:129
YPropertyType type() const
Definition YProperty.h:169
bool operator==(const YPropertyValue &other) const
Definition YProperty.cc:54
~YPropertyValue()
Definition YProperty.cc:50
YPropertyValue(const char *str)
Definition YProperty.h:117
bool operator!=(const YPropertyValue &other) const
Definition YProperty.cc:76
Definition YProperty.h:52
std::string name() const
Definition YProperty.h:67
YProperty(const std::string &name, YPropertyType type, bool isReadOnly=false)
Definition YProperty.h:58
std::string typeAsStr() const
Definition YProperty.h:82
bool isReadOnly() const
Definition YProperty.h:77
YPropertyType type() const
Definition YProperty.h:72
Definition YWidget.h:55