class LIBCONFIGXX_API ConfigException : public std::exception { };
class Setting; // fwd decl
+class SettingIterator;
+class SettingConstIterator;
class LIBCONFIGXX_API SettingException : public ConfigException
{
FormatHex = 1
};
+ typedef SettingIterator iterator;
+ typedef SettingConstIterator const_iterator;
+
private:
config_setting_t *_setting;
unsigned int getSourceLine() const throw();
const char *getSourceFile() const throw();
+
+ iterator begin();
+ iterator end();
+
+ const_iterator begin() const;
+ const_iterator end() const;
};
+
+class LIBCONFIGXX_API SettingIterator
+{
+ private:
+
+ Setting *_setting;
+
+ int _count;
+ int _idx;
+
+ public:
+
+ SettingIterator(Setting &setting, bool endIterator = false);
+ SettingIterator(const SettingIterator &rhs);
+ SettingIterator& operator=(const SettingIterator &rhs);
+
+ // Equality comparison.
+ inline bool operator ==(SettingIterator const& rhs) const
+ { return _idx == rhs._idx; }
+
+ inline bool operator !=(SettingIterator const& rhs) const
+ { return ! (*this == rhs); }
+
+ bool operator <(SettingIterator const& rhs) const;
+
+ // Dereference operators.
+ inline Setting & operator *() { return (*_setting)[_idx]; }
+ inline Setting * operator ->() { return &(*_setting)[_idx]; }
+
+ inline const Setting & operator *() const { return (*_setting)[_idx]; }
+ inline const Setting * operator ->() const { return &(*_setting)[_idx]; }
+
+ // Increment and decrement operators.
+ SettingIterator& operator ++();
+ SettingIterator operator ++(int);
+
+ SettingIterator& operator --();
+ SettingIterator operator --(int);
+
+ // Arithmetic operators.
+ SettingIterator operator +(int offset) const;
+ SettingIterator& operator +=(int offset);
+
+ SettingIterator operator -(int offset) const;
+ SettingIterator& operator -=(int offset);
+
+ int operator -(const SettingIterator &rhs) const;
+};
+
+SettingIterator operator +(int offset, const SettingIterator &si);
+
+class LIBCONFIGXX_API SettingConstIterator
+{
+ private:
+
+ const Setting *_setting;
+
+ int _count;
+ int _idx;
+
+ public:
+
+ SettingConstIterator(const Setting &setting, bool endIterator = false);
+ SettingConstIterator(const SettingConstIterator &rhs);
+ SettingConstIterator& operator=(const SettingConstIterator &rhs);
+
+ // Equality comparison.
+ bool operator ==(SettingConstIterator const& rhs) const
+ { return _idx == rhs._idx; }
+
+ inline bool operator !=(SettingConstIterator const& rhs) const
+ { return ! (*this == rhs); }
+
+ // Dereference operators.
+ inline Setting const& operator *() { return (*_setting)[_idx]; }
+ inline Setting const* operator ->() { return &(*_setting)[_idx]; }
+
+ inline const Setting& operator *() const { return (*_setting)[_idx]; }
+ inline const Setting* operator ->() const { return &(*_setting)[_idx]; }
+
+ // Increment and decrement operators.
+ SettingConstIterator& operator ++();
+ SettingConstIterator operator ++(int);
+
+ SettingConstIterator& operator --();
+ SettingConstIterator operator --(int);
+
+ // Arithmetic operators.
+ SettingConstIterator operator +(int offset) const;
+ SettingConstIterator& operator +=(int offset);
+
+ SettingConstIterator operator -(int offset) const;
+ SettingConstIterator& operator -=(int offset);
+
+ int operator -(const SettingConstIterator &rhs) const;
+};
+
+SettingConstIterator operator +(int offset, const SettingConstIterator &si);
+
class LIBCONFIGXX_API Config
{
private:
// ---------------------------------------------------------------------------
+Setting::iterator Setting::begin()
+{ return iterator(*this); }
+
+// ---------------------------------------------------------------------------
+
+Setting::iterator Setting::end()
+{ return iterator(*this, true); }
+
+// ---------------------------------------------------------------------------
+
+Setting::const_iterator Setting::begin() const
+{ return const_iterator(*this); }
+
+// ---------------------------------------------------------------------------
+
+Setting::const_iterator Setting::end() const
+{ return const_iterator(*this, true); }
+
+// ---------------------------------------------------------------------------
+
+SettingIterator::SettingIterator(Setting& setting, bool endIterator)
+ : _setting(&setting), _count(setting.getLength())
+{
+ if (endIterator)
+ _idx = _count;
+ else
+ _idx = 0;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator::SettingIterator(const SettingIterator &rhs)
+ : _setting(rhs._setting), _count(rhs._count), _idx(rhs._idx)
+{
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator& SettingIterator::operator=(const SettingIterator &rhs)
+{
+ _setting = rhs._setting;
+ _count = rhs._count;
+ _idx = rhs._idx;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator& SettingIterator::operator ++()
+{
+ ++_idx;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator SettingIterator::operator ++(int)
+{
+ SettingIterator tmp(*this);
+ ++_idx;
+ return tmp;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator& SettingIterator::operator --()
+{
+ --_idx;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator SettingIterator::operator --(int)
+{
+ SettingIterator tmp(*this);
+ --_idx;
+ return tmp;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator SettingIterator::operator +(int offset) const
+{
+ SettingIterator cpy(*this);
+ cpy += offset;
+ return cpy;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator& SettingIterator::operator +=(int offset)
+{
+ _idx += offset;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator operator +(int offset, SettingIterator& si)
+{
+ SettingIterator cpy(si);
+ cpy += offset;
+ return cpy;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator SettingIterator::operator -(int offset) const
+{
+ SettingIterator cpy(*this);
+ cpy._idx -= offset;
+ return cpy;;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingIterator& SettingIterator::operator -=(int offset)
+{
+ _idx -= offset;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+int SettingIterator::operator -(SettingIterator const& rhs) const
+{
+ return _idx - rhs._idx;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator::SettingConstIterator(const Setting &setting, bool endIterator)
+ : _setting(&setting), _count(setting.getLength())
+{
+ if (endIterator)
+ _idx = _count;
+ else
+ _idx = 0;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator::SettingConstIterator(const SettingConstIterator &rhs)
+ : _setting(rhs._setting), _count(rhs._count), _idx(rhs._idx)
+{
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator& SettingConstIterator::operator=(const SettingConstIterator &rhs)
+{
+ _setting = rhs._setting;
+ _count = rhs._count;
+ _idx = rhs._idx;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator& SettingConstIterator::operator ++()
+{ ++_idx; return *this; }
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator SettingConstIterator::operator ++(int)
+{
+ SettingConstIterator tmp(*this);
+ ++_idx;
+ return tmp;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator& SettingConstIterator::operator --()
+{
+ --_idx;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator SettingConstIterator::operator --(int)
+{
+ SettingConstIterator tmp(*this);
+ --_idx;
+ return tmp;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator SettingConstIterator::operator +(int offset) const
+{
+ SettingConstIterator cpy(*this);
+ cpy += offset;
+ return cpy;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator& SettingConstIterator::operator +=(int offset)
+{
+ _idx += offset;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator operator +(int offset, SettingConstIterator& si)
+{
+ SettingConstIterator cpy(si);
+ cpy += offset;
+ return cpy;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator SettingConstIterator::operator -(int offset) const
+{
+ SettingConstIterator cpy(*this);
+ cpy -= offset;
+ return cpy;
+}
+
+// ---------------------------------------------------------------------------
+
+SettingConstIterator& SettingConstIterator::operator -=(int offset)
+{
+ _idx -= offset;
+ return *this;
+}
+
+// ---------------------------------------------------------------------------
+
+int SettingConstIterator::operator -(SettingConstIterator const& rhs) const
+{
+ return _idx - rhs._idx;
+}
+
+
} // namespace libconfig
// eof