inivariable.h
1 //------------------------------------------------------------------------------
2 // inivariable.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __INIVARIABLE_H__
24 #define __INIVARIABLE_H__
25 
26 #include "dptr.h"
27 #include "global.h"
28 
29 #include <QHash>
30 #include <QString>
31 #include <QVariant>
32 
33 class IniSection;
34 
41 class MAIN_EXPORT IniVariable
42 {
43  public:
50  IniVariable();
51 
56  IniVariable(const IniSection &section, const QString& key);
57 
58  virtual ~IniVariable();
59 
63  const QString& key();
64 
69  bool isNull() const;
70 
76  QString valueString() const { return this->value().toString(); }
77 
78  const IniVariable &operator=(const QString &str);
79  const IniVariable &operator=(const char* str) { return *this = QString(str); }
80  const IniVariable &operator=(int i);
81  const IniVariable &operator=(unsigned int i);
82  const IniVariable &operator=(short i);
83  const IniVariable &operator=(unsigned short i);
84 
91  const IniVariable &operator=(bool b);
92  const IniVariable &operator=(float f);
93 
97  QString operator*() const { return value().toString(); }
98 
102  operator QString () const { return value().toString(); }
103 
107  operator float() const;
111  operator int() const;
112  operator unsigned int() const;
113 
114  operator short() const;
115  operator unsigned short() const;
116 
121  operator bool() const;
122 
126  void setValue(const QVariant& value);
127 
131  QVariant value() const;
132 
133  private:
134  friend class TestReadINIVariable;
135  friend class TestReadINIList;
136 
138 };
139 
140 #endif
QString valueString() const
Returns the underlying value as a QString.
Definition: inivariable.h:76
INI variable representation.
Definition: inivariable.h:41
QString operator*() const
Attempts to convert the value to QString.
Definition: inivariable.h:97
INI section representation.
Definition: inisection.h:40