libyui

/data/gitorious.org/libyui/libyui-master/src/YProperty.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                                      |
00032 |                                         (c) SuSE Linux Products GmbH |
00033 \----------------------------------------------------------------------/
00034 
00035   File:         YProperty.h
00036 
00037   Author:       Stefan Hundhammer <sh@suse.de>
00038 
00039 /-*/
00040 
00041 #ifndef YProperty_h
00042 #define YProperty_h
00043 
00044 #include <string>
00045 #include <vector>
00046 
00047 using std::string;
00048 
00049 
00050 enum YPropertyType
00051 {
00052     YUnknownPropertyType = 0,
00053     YOtherProperty,             // requires futher checking
00054     YStringProperty,            // const string &
00055     YBoolProperty,              // bool
00056     YIntegerProperty            // YCP Integer == C++ long long
00057 };
00058 
00059 class YWidget;
00060 class YProperty;
00061 
00062 typedef long long       YInteger;
00063 
00064 
00068 class YProperty
00069 {
00070 public:
00075     YProperty( const string & name, YPropertyType type, bool isReadOnly = false )
00076         : _name( name )
00077         , _type( type )
00078         , _isReadOnly( isReadOnly )
00079         {}
00080 
00084     string name() const { return _name; }
00085 
00089     YPropertyType type() const { return _type; }
00090 
00094     bool isReadOnly() const { return _isReadOnly; }
00095 
00099     string typeAsStr() const { return YProperty::typeAsStr( _type ); }
00100 
00104     static string typeAsStr( YPropertyType type );
00105 
00106 private:
00107 
00108     string              _name;
00109     YPropertyType       _type;
00110     bool                _isReadOnly;
00111 };
00112 
00113 
00121 class YPropertyValue
00122 {
00123 public:
00124 
00128     YPropertyValue( const string & str ):
00129         _type( YStringProperty ), _stringVal( str ) {}
00130 
00134     YPropertyValue( const char * str ):
00135         _type( YStringProperty ), _stringVal( str ) {}
00136 
00140     explicit YPropertyValue( bool b ):
00141         _type( YBoolProperty ), _boolVal( b ) {}
00142 
00146     explicit YPropertyValue( YInteger num ):
00147         _type( YIntegerProperty ), _integerVal( num ) {}
00148 
00152     explicit YPropertyValue( int num ):
00153         _type( YIntegerProperty ), _integerVal( num ) {}
00154 
00155     explicit YPropertyValue( YPropertyType type ) :
00156         _type( type ) {}
00157 
00161     YPropertyValue():
00162         _type( YUnknownPropertyType ) {}
00163 
00167     ~YPropertyValue();
00168 
00173     YPropertyType type() const { return _type; }
00174 
00178     string typeAsStr() const { return YProperty::typeAsStr( _type ); }
00179 
00184     string      stringVal()     const { return _stringVal;      }
00185     bool        boolVal()       const { return _boolVal;        }
00186     YInteger    integerVal()    const { return _integerVal;     }
00187 
00188 
00189 private:
00190 
00191     YPropertyType       _type;
00192     string              _stringVal;
00193     bool                _boolVal;
00194     YInteger            _integerVal;
00195 };
00196 
00197 
00201 class YPropertySet
00202 {
00203 public:
00207     YPropertySet();
00208 
00215     void check( const string & propertyName ) const;
00216 
00226     void check( const string & propertyName, YPropertyType type ) const;
00227 
00231     void check( const YProperty & prop ) const
00232         { check( prop.name(), prop.type() ); }
00233 
00241     bool contains( const string & propertyName ) const throw();
00242 
00256     bool contains( const string & propertyName, YPropertyType type ) const;
00257 
00261     bool contains( const YProperty & prop ) const
00262         { return contains( prop.name(), prop.type() ); }
00263 
00267     bool isEmpty() const { return _properties.empty(); }
00268 
00272     int size() const { return (int) _properties.size(); }
00273 
00277     void add( const YProperty & prop );
00278 
00285     void add( const YPropertySet & otherSet );
00286 
00287     typedef std::vector<YProperty>::const_iterator const_iterator;
00288 
00292     const_iterator propertiesBegin() const;
00293 
00297     const_iterator propertiesEnd() const;
00298 
00299 private:
00300 
00307     std::vector<YProperty> _properties;
00308 };
00309 
00310 
00311 #endif // YProperty_h
 All Classes Functions Variables Enumerations Friends