eVaf
inifile_p.h
Go to the documentation of this file.
1 
20 #ifndef __COMMON_INIFILE_P_H
21 #define __COMMON_INIFILE_P_H
22 
23 #include <QSharedData>
24 #include <QExplicitlySharedDataPointer>
25 #include <QHash>
26 #include <QString>
27 #include <QVariant>
28 #include <QDateTime>
29 #include <QFile>
30 
31 
32 namespace eVaf {
33 namespace Common {
34 namespace Internal {
35 
39 class IniFileValue : public QSharedData
40 {
41 public:
42 
43  IniFileValue(quint64 pos)
44  : QSharedData()
45  , filePos(pos)
46  , thisOsOnly(false)
47  {}
48 
55  quint64 filePos;
56 
60  QByteArray name;
61 
65  QByteArray paramValue;
66 
70  QVariant value;
71 
75  bool thisOsOnly;
76 };
77 
82 {
83 public:
84 
85  IniFileSection(quint64 pos)
86  : QSharedData()
87  , filePos(pos)
88  {}
89 
96  quint64 filePos;
97 
101  QByteArray name;
102 
108  QHash<QByteArray, QExplicitlySharedDataPointer<IniFileValue> > values;
109 
110 };
111 
116 {
117 public:
118 
119  IniFileImpl(QString const & fileName, QIODevice::OpenMode mode);
120 
121  ~IniFileImpl();
122 
123  QVariant getValue(QByteArray const & paramName, QVariant const & defaultValue);
124 
125  bool setValue(QByteArray const & paramName, QVariant const & value);
126 
127  inline bool isValid() const { return mValid; }
128 
129  inline QString const & fileName() const { return mFileName; }
130 
131  inline QString const & errorString() const { return mErrorString; }
132 
133 
134 private: // Members
135 
137  bool mValid;
138 
140  QString mFileName;
141 
143  QIODevice::OpenMode mMode;
144 
146  QString mErrorString;
147 
153  QHash<QByteArray, QExplicitlySharedDataPointer<IniFileSection> > mCache;
154 
156  QDateTime mLastModified;
157 
158 
159 private:
160 
170  void updateCache(quint64 pos, qint64 diff);
171 
186  QExplicitlySharedDataPointer<IniFileSection> getSection(QFile & file, QByteArray const & sectionName);
187 
203  QExplicitlySharedDataPointer<IniFileValue> getParameter(QFile & file, IniFileSection & section, QByteArray const & paramName);
204 
205 };
206 
207 
208 } // namespace eVaf::Common::Internal
209 } // namespace eVaf::Common
210 } // namespace eVaf
211 
212 #endif // inifile_p.h
QByteArray name
Name of the section.
Definition: inifile_p.h:101
Internal implementation of the IniFile class.
Definition: inifile_p.h:115
QVariant value
Value converted to the final type (defaults to QVariant::Invalid.
Definition: inifile_p.h:70
QByteArray paramValue
Value from the INI file.
Definition: inifile_p.h:65
INI file value in the internal cache.
Definition: inifile_p.h:39
quint64 filePos
File position.
Definition: inifile_p.h:55
INI file section in the internal cache.
Definition: inifile_p.h:81
QByteArray name
Key name of the parameter.
Definition: inifile_p.h:60
QHash< QByteArray, QExplicitlySharedDataPointer< IniFileValue > > values
List of all the known parameter values in this section.
Definition: inifile_p.h:108
Global eVaf namespace.
Definition: engine.h:37
bool thisOsOnly
Flag indicating that this value is valid on this OS only.
Definition: inifile_p.h:75
quint64 filePos
File position.
Definition: inifile_p.h:96
QString const & fileName() const
Definition: inifile_p.h:129
QString const & errorString() const
Definition: inifile_p.h:131