File indexing completed on 2024-11-10 03:45:20
0001 // 0002 // C++ Interface: cValue, cValueList 0003 // 0004 /* 0005 Copyright 2005-2011 Tomas Mecir <kmuddy@kmuddy.com> 0006 0007 This program is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU General Public License as 0009 published by the Free Software Foundation; either version 2 of 0010 the License, or (at your option) any later version. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 #ifndef CVALUE_H 0021 #define CVALUE_H 0022 0023 class cValueData; 0024 class KConfigGroup; 0025 class QXmlStreamWriter; 0026 0027 #include <qstring.h> 0028 0029 /** 0030 Class cValue holds one value, used in variables and in function evaluator. 0031 0032 @author Tomas Mecir 0033 */ 0034 class cValue { 0035 public: 0036 /** constructor */ 0037 cValue (); 0038 cValue (const cValue &val); 0039 cValue (const QString &val); 0040 cValue (int val); 0041 cValue (double val); 0042 cValue (bool val); 0043 0044 /** destructor */ 0045 ~cValue (); 0046 0047 static cValue *load (KConfigGroup *g); 0048 void save (QXmlStreamWriter *writer, const QString &name); 0049 0050 /** assignment operator */ 0051 cValue &operator= (const cValue &a); 0052 0053 /** set value to nothing */ 0054 void setValue (); 0055 /** set value to a string */ 0056 void setValue (const QString &val); 0057 /** set value to an integer */ 0058 void setValue (int val); 0059 /** set value to a number */ 0060 void setValue (double val); 0061 /** set value to a copy of a given value */ 0062 void setValue (const cValue &val); 0063 void setAsMarker (); 0064 /** set one particular item in an array */ 0065 void setItem (int index, const QString &value); 0066 /** remove an item from an array */ 0067 void removeItem (int index); 0068 /** add an item to the list */ 0069 void addToList (const QString &item); 0070 /** remove an item from the list */ 0071 void removeFromList (const QString &item); 0072 /** does the list contain a given string ? */ 0073 bool listContains (const QString &item); 0074 0075 QString asString () const; 0076 int asInteger () const; 0077 double asDouble () const; 0078 /** Return array item with the given index, if any. Arrays only. */ 0079 QString item (int index) const; 0080 /** Does the list contain a given value ? Lists only.*/ 0081 bool contains (const QString &item) const; 0082 /** Number of entries in a list/array. */ 0083 int size () const; 0084 0085 /** join a list into a string, using the given separator */ 0086 QString listJoin (const QString &sep) const; 0087 /** convert a string to a list, using the given separator */ 0088 cValue toList (const QString &sep) const; 0089 0090 bool isEmpty() const; 0091 bool isString() const; 0092 bool isInteger() const; 0093 bool isDouble() const; 0094 bool isArray() const; 0095 bool isList() const; 0096 bool isMarker() const; 0097 0098 /// some operators ... 0099 cValue operator[] (int index) const; 0100 0101 static cValue empty () { return _empty; }; 0102 protected: 0103 0104 /** detach from current value, deleting it if no one else uses it */ 0105 void detachValue (); 0106 /** ensure that no one else uses our value */ 0107 void unique (); 0108 0109 cValueData *d; 0110 0111 static cValue _empty; 0112 }; 0113 0114 /// some external operators ... 0115 cValue operator+ (const cValue &a, const cValue &b); 0116 cValue operator- (const cValue &a, const cValue &b); 0117 cValue operator* (const cValue &a, const cValue &b); 0118 cValue operator/ (const cValue &a, const cValue &b); 0119 0120 0121 #endif