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
77  {
78  return this->value().toString();
79  }
80 
81  const IniVariable &operator=(const QString &str);
82  const IniVariable &operator=(const char *str)
83  {
84  return *this = QString(str);
85  }
86  const IniVariable &operator=(int i);
87  const IniVariable &operator=(unsigned int i);
88  const IniVariable &operator=(short i);
89  const IniVariable &operator=(unsigned short i);
90 
97  const IniVariable &operator=(bool b);
98  const IniVariable &operator=(float f);
99 
103  QString operator*() const
104  {
105  return value().toString();
106  }
107 
111  operator QString () const { return value().toString(); }
112 
116  operator float() const;
120  operator int() const;
121  operator unsigned int() const;
122 
123  operator short() const;
124  operator unsigned short() const;
125 
129  operator bool() const;
130 
134  void setValue(const QVariant &value);
135 
139  QVariant value() const;
140 
141 private:
142  friend class TestReadINIVariable;
143  friend class TestReadINIList;
144 
146 };
147 
148 #endif