1 /* ----------------------------------------------------------------------------
2 libconfig - A library for processing structured configuration files
3 Copyright (C) 2005-2010 Mark A Lindner
5 This file is part of libconfig.
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public License
9 as published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this library; if not, see
19 <http://www.gnu.org/licenses/>.
20 ----------------------------------------------------------------------------
23 #include "libconfig.h++"
26 #pragma warning (disable: 4996)
29 #include "wincompat.h"
30 #include "libconfig.h"
38 // ---------------------------------------------------------------------------
40 ParseException::ParseException(const char *file, int line, const char *error)
41 : _file(file ? ::strdup(file) : NULL), _line(line), _error(error)
45 // ---------------------------------------------------------------------------
47 ParseException::ParseException(const ParseException &other)
48 : ConfigException(other),
49 _file(other._file ? ::strdup(other._file) : NULL),
55 // ---------------------------------------------------------------------------
57 ParseException::~ParseException() throw()
59 ::free((void *)_file);
62 // ---------------------------------------------------------------------------
64 const char *ParseException::what() const throw()
66 return("ParseException");
69 // ---------------------------------------------------------------------------
71 static int __toTypeCode(Setting::Type type)
77 case Setting::TypeGroup:
78 typecode = CONFIG_TYPE_GROUP;
81 case Setting::TypeInt:
82 typecode = CONFIG_TYPE_INT;
85 case Setting::TypeInt64:
86 typecode = CONFIG_TYPE_INT64;
89 case Setting::TypeFloat:
90 typecode = CONFIG_TYPE_FLOAT;
93 case Setting::TypeString:
94 typecode = CONFIG_TYPE_STRING;
97 case Setting::TypeBoolean:
98 typecode = CONFIG_TYPE_BOOL;
101 case Setting::TypeArray:
102 typecode = CONFIG_TYPE_ARRAY;
105 case Setting::TypeList:
106 typecode = CONFIG_TYPE_LIST;
110 typecode = CONFIG_TYPE_NONE;
116 // ---------------------------------------------------------------------------
118 static void __constructPath(const Setting &setting,
119 std::stringstream &path)
121 // head recursion to print path from root to target
123 if(! setting.isRoot())
125 __constructPath(setting.getParent(), path);
129 const char *name = setting.getName();
133 path << '[' << setting.getIndex() << ']';
137 // ---------------------------------------------------------------------------
139 SettingException::SettingException(const Setting &setting)
141 std::stringstream sstr;
142 __constructPath(setting, sstr);
144 _path = ::strdup(sstr.str().c_str());
147 // ---------------------------------------------------------------------------
149 SettingException::SettingException(const Setting &setting, int idx)
151 std::stringstream sstr;
152 __constructPath(setting, sstr);
153 sstr << ".[" << idx << "]";
155 _path = ::strdup(sstr.str().c_str());
158 // ---------------------------------------------------------------------------
160 SettingException::SettingException(const Setting &setting, const char *name)
162 std::stringstream sstr;
163 __constructPath(setting, sstr);
166 _path = ::strdup(sstr.str().c_str());
169 // ---------------------------------------------------------------------------
171 SettingException::SettingException(const char *path)
173 _path = ::strdup(path);
176 // ---------------------------------------------------------------------------
178 const char *SettingException::getPath() const
183 // ---------------------------------------------------------------------------
185 SettingException::SettingException(const SettingException &other)
186 : ConfigException(other)
188 _path = ::strdup(other._path);
191 // ---------------------------------------------------------------------------
193 SettingException &SettingException::operator=(const SettingException &other)
196 _path = ::strdup(other._path);
201 // ---------------------------------------------------------------------------
203 const char *SettingException::what() const throw()
205 return("SettingException");
208 // ---------------------------------------------------------------------------
210 SettingException::~SettingException() throw()
215 // ---------------------------------------------------------------------------
217 SettingTypeException::SettingTypeException(const Setting &setting)
218 : SettingException(setting)
222 // ---------------------------------------------------------------------------
224 SettingTypeException::SettingTypeException(const Setting &setting, int idx)
225 : SettingException(setting, idx)
229 // ---------------------------------------------------------------------------
231 SettingTypeException::SettingTypeException(const Setting &setting,
233 : SettingException(setting, name)
237 // ---------------------------------------------------------------------------
239 const char *SettingTypeException::what() const throw()
241 return("SettingTypeException");
244 // ---------------------------------------------------------------------------
246 SettingNotFoundException::SettingNotFoundException(const Setting &setting,
248 : SettingException(setting, idx)
252 // ---------------------------------------------------------------------------
254 SettingNotFoundException::SettingNotFoundException(const Setting &setting,
256 : SettingException(setting, name)
260 // ---------------------------------------------------------------------------
262 SettingNotFoundException::SettingNotFoundException(const char *path)
263 : SettingException(path)
267 // ---------------------------------------------------------------------------
269 const char *SettingNotFoundException::what() const throw()
271 return("SettingNotFoundException");
274 // ---------------------------------------------------------------------------
276 SettingNameException::SettingNameException(const Setting &setting,
278 : SettingException(setting, name)
282 // ---------------------------------------------------------------------------
284 const char *SettingNameException::what() const throw()
286 return("SettingNameException");
289 // ---------------------------------------------------------------------------
291 const char *FileIOException::what() const throw()
293 return("FileIOException");
296 // ---------------------------------------------------------------------------
298 void Config::ConfigDestructor(void *arg)
300 delete reinterpret_cast<Setting *>(arg);
303 // ---------------------------------------------------------------------------
306 : _defaultFormat(Setting::FormatDefault)
308 _config = new config_t;
309 config_init(_config);
310 config_set_destructor(_config, ConfigDestructor);
313 // ---------------------------------------------------------------------------
315 Config::Config(std::string const& cfgFile)
316 : _defaultFormat(Setting::FormatDefault)
318 _config = new config_t;
319 config_init(_config);
320 config_set_destructor(_config, ConfigDestructor);
321 readFile(cfgFile.c_str());
324 // ---------------------------------------------------------------------------
328 config_destroy(_config);
332 // ---------------------------------------------------------------------------
334 void Config::setAutoConvert(bool flag)
336 config_set_auto_convert(_config, (flag ? CONFIG_TRUE : CONFIG_FALSE));
339 // ---------------------------------------------------------------------------
341 bool Config::getAutoConvert() const
343 return(config_get_auto_convert(_config) != CONFIG_FALSE);
346 // ---------------------------------------------------------------------------
348 void Config::setDefaultFormat(Setting::Format format)
350 if(format == Setting::FormatHex)
351 _defaultFormat = Setting::FormatHex;
353 _defaultFormat = Setting::FormatDefault;
355 config_set_default_format(_config, static_cast<short>(_defaultFormat));
358 // ---------------------------------------------------------------------------
360 void Config::setTabWidth(unsigned short width) throw()
362 config_set_tab_width(_config, width);
365 // ---------------------------------------------------------------------------
367 unsigned short Config::getTabWidth() const throw()
369 return(config_get_tab_width(_config));
372 // ---------------------------------------------------------------------------
374 void Config::setIncludeDir(const char *includeDir) throw()
376 config_set_include_dir(_config, includeDir);
379 // ---------------------------------------------------------------------------
381 const char *Config::getIncludeDir() const throw()
383 return(config_get_include_dir(_config));
386 // ---------------------------------------------------------------------------
388 void Config::handleError() const
390 switch(config_error_type(_config))
392 case CONFIG_ERR_NONE:
395 case CONFIG_ERR_PARSE:
396 throw ParseException(config_error_file(_config),
397 config_error_line(_config),
398 config_error_text(_config));
401 case CONFIG_ERR_FILE_IO:
403 throw FileIOException();
407 // ---------------------------------------------------------------------------
409 void Config::read(FILE *stream) throw(ParseException)
411 if(! config_read(_config, stream))
415 // ---------------------------------------------------------------------------
417 void Config::readString(const char *str) throw(ParseException)
419 if(! config_read_string(_config, str))
423 // ---------------------------------------------------------------------------
425 void Config::write(FILE *stream) const
427 config_write(_config, stream);
430 // ---------------------------------------------------------------------------
432 void Config::readFile(const char *filename) throw(FileIOException,
435 if(! config_read_file(_config, filename))
439 // ---------------------------------------------------------------------------
441 void Config::writeFile(const char *filename) throw(FileIOException)
443 if(! config_write_file(_config, filename))
447 // ---------------------------------------------------------------------------
449 Setting & Config::lookup(const std::string &path) const
451 config_setting_t *s = config_lookup(_config, path.c_str());
453 throw SettingNotFoundException(path.c_str());
455 return(Setting::wrapSetting(s));
458 // ---------------------------------------------------------------------------
460 bool Config::exists(const char *path) const throw()
462 config_setting_t *s = config_lookup(_config, path);
467 // ---------------------------------------------------------------------------
469 #define CONFIG_LOOKUP_NO_EXCEPTIONS(P, T, V) \
472 Setting &s = lookup(P); \
476 catch(const ConfigException &) \
481 // ---------------------------------------------------------------------------
483 bool Config::lookupValue(const char *path, bool &value) const throw()
485 CONFIG_LOOKUP_NO_EXCEPTIONS(path, bool, value);
488 // ---------------------------------------------------------------------------
490 bool Config::lookupValue(const char *path, int &value) const throw()
492 CONFIG_LOOKUP_NO_EXCEPTIONS(path, int, value);
495 // ---------------------------------------------------------------------------
497 bool Config::lookupValue(const char *path, unsigned int &value) const throw()
499 CONFIG_LOOKUP_NO_EXCEPTIONS(path, unsigned int, value);
502 // ---------------------------------------------------------------------------
504 bool Config::lookupValue(const char *path, long long &value) const throw()
506 CONFIG_LOOKUP_NO_EXCEPTIONS(path, long long, value);
509 // ---------------------------------------------------------------------------
511 bool Config::lookupValue(const char *path, unsigned long long &value)
514 CONFIG_LOOKUP_NO_EXCEPTIONS(path, unsigned long long, value);
517 // ---------------------------------------------------------------------------
519 bool Config::lookupValue(const char *path, double &value) const throw()
521 CONFIG_LOOKUP_NO_EXCEPTIONS(path, double, value);
524 // ---------------------------------------------------------------------------
526 bool Config::lookupValue(const char *path, float &value) const throw()
528 CONFIG_LOOKUP_NO_EXCEPTIONS(path, float, value);
531 // ---------------------------------------------------------------------------
533 bool Config::lookupValue(const char *path, std::string &value) const throw()
535 CONFIG_LOOKUP_NO_EXCEPTIONS(path, std::string, value);
538 // ---------------------------------------------------------------------------
540 Setting & Config::getRoot() const
542 return(Setting::wrapSetting(config_root_setting(_config)));
545 // ---------------------------------------------------------------------------
547 Setting::Setting(config_setting_t *setting)
550 switch(config_setting_type(setting))
552 case CONFIG_TYPE_GROUP:
556 case CONFIG_TYPE_INT:
560 case CONFIG_TYPE_INT64:
564 case CONFIG_TYPE_FLOAT:
568 case CONFIG_TYPE_STRING:
572 case CONFIG_TYPE_BOOL:
576 case CONFIG_TYPE_ARRAY:
580 case CONFIG_TYPE_LIST:
584 case CONFIG_TYPE_NONE:
590 switch(config_setting_get_format(setting))
592 case CONFIG_FORMAT_HEX:
596 case CONFIG_FORMAT_DEFAULT:
598 _format = FormatDefault;
603 // ---------------------------------------------------------------------------
605 Setting::~Setting() throw()
610 // ---------------------------------------------------------------------------
612 void Setting::setFormat(Format format) throw()
614 if((_type == TypeInt) || (_type == TypeInt64))
616 if(format == FormatHex)
619 _format = FormatDefault;
622 _format = FormatDefault;
624 config_setting_set_format(_setting, static_cast<short>(_format));
627 // ---------------------------------------------------------------------------
629 Setting::operator bool() const throw(SettingTypeException)
631 assertType(TypeBoolean);
633 return(config_setting_get_bool(_setting) ? true : false);
636 // ---------------------------------------------------------------------------
638 Setting::operator int() const throw(SettingTypeException)
642 return(config_setting_get_int(_setting));
645 // ---------------------------------------------------------------------------
647 Setting::operator unsigned int() const throw(SettingTypeException)
651 int v = config_setting_get_int(_setting);
656 return(static_cast<unsigned int>(v));
659 // ---------------------------------------------------------------------------
661 Setting::operator long() const throw(SettingTypeException)
663 if(sizeof(long) == sizeof(long long))
664 return operator long long();
666 return operator int();
669 // ---------------------------------------------------------------------------
671 Setting::operator unsigned long() const throw(SettingTypeException)
673 if(sizeof(long) == sizeof(long long))
674 return operator unsigned long long();
676 return operator unsigned int();
679 // ---------------------------------------------------------------------------
681 Setting::operator long long() const throw(SettingTypeException)
683 assertType(TypeInt64);
685 return(config_setting_get_int64(_setting));
688 // ---------------------------------------------------------------------------
690 Setting::operator unsigned long long() const throw(SettingTypeException)
692 assertType(TypeInt64);
694 long long v = config_setting_get_int64(_setting);
696 if(v < INT64_CONST(0))
699 return(static_cast<unsigned long long>(v));
702 // ---------------------------------------------------------------------------
704 Setting::operator double() const throw(SettingTypeException)
706 assertType(TypeFloat);
708 return(config_setting_get_float(_setting));
711 // ---------------------------------------------------------------------------
713 Setting::operator float() const throw(SettingTypeException)
715 assertType(TypeFloat);
717 // may cause loss of precision:
718 return(static_cast<float>(config_setting_get_float(_setting)));
721 // ---------------------------------------------------------------------------
723 Setting::operator std::string() const throw(SettingTypeException)
725 const char *s = c_str();
734 // ---------------------------------------------------------------------------
736 const char* Setting::c_str() const throw(SettingTypeException)
738 assertType(TypeString);
740 return(config_setting_get_string(_setting));
743 // ---------------------------------------------------------------------------
745 Setting & Setting::operator=(bool value) throw(SettingTypeException)
747 assertType(TypeBoolean);
749 config_setting_set_bool(_setting, value);
754 // ---------------------------------------------------------------------------
756 Setting & Setting::operator=(int value) throw(SettingTypeException)
760 config_setting_set_int(_setting, value);
765 // ---------------------------------------------------------------------------
767 Setting & Setting::operator=(long value) throw(SettingTypeException)
769 if(sizeof(long) == sizeof(long long))
770 return(operator=(static_cast<long long>(value)));
772 return(operator=(static_cast<int>(value)));
775 // ---------------------------------------------------------------------------
777 Setting & Setting::operator=(const long long &value)
778 throw(SettingTypeException)
780 assertType(TypeInt64);
782 config_setting_set_int64(_setting, value);
787 // ---------------------------------------------------------------------------
789 Setting & Setting::operator=(const double &value) throw(SettingTypeException)
791 assertType(TypeFloat);
793 config_setting_set_float(_setting, value);
798 // ---------------------------------------------------------------------------
800 Setting & Setting::operator=(float value) throw(SettingTypeException)
802 assertType(TypeFloat);
804 double cvalue = static_cast<double>(value);
806 config_setting_set_float(_setting, cvalue);
811 // ---------------------------------------------------------------------------
813 Setting & Setting::operator=(const char *value) throw(SettingTypeException)
815 assertType(TypeString);
817 config_setting_set_string(_setting, value);
822 // ---------------------------------------------------------------------------
824 Setting & Setting::operator=(const std::string &value)
825 throw(SettingTypeException)
827 assertType(TypeString);
829 config_setting_set_string(_setting, value.c_str());
834 // ---------------------------------------------------------------------------
836 Setting & Setting::lookup(const std::string &key) const
838 assertType(TypeGroup);
840 config_setting_t *setting = config_setting_get_member(_setting, key.c_str());
843 throw SettingNotFoundException(*this, key.c_str());
845 return(wrapSetting(setting));
848 // ---------------------------------------------------------------------------
850 Setting & Setting::operator[](int i) const
852 if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList))
853 throw SettingTypeException(*this, i);
855 config_setting_t *setting = config_setting_get_elem(_setting, i);
858 throw SettingNotFoundException(*this, i);
860 return(wrapSetting(setting));
863 // ---------------------------------------------------------------------------
865 #define SETTING_LOOKUP_NO_EXCEPTIONS(K, T, V) \
868 Setting &s = operator[](K); \
872 catch(const ConfigException &) \
877 // ---------------------------------------------------------------------------
879 bool Setting::lookupValue(const char *name, bool &value) const throw()
881 SETTING_LOOKUP_NO_EXCEPTIONS(name, bool, value);
884 // ---------------------------------------------------------------------------
886 bool Setting::lookupValue(const char *name, int &value) const throw()
888 SETTING_LOOKUP_NO_EXCEPTIONS(name, int, value);
891 // ---------------------------------------------------------------------------
893 bool Setting::lookupValue(const char *name, unsigned int &value)
896 SETTING_LOOKUP_NO_EXCEPTIONS(name, unsigned int, value);
899 // ---------------------------------------------------------------------------
901 bool Setting::lookupValue(const char *name, long long &value) const throw()
903 SETTING_LOOKUP_NO_EXCEPTIONS(name, long long, value);
906 // ---------------------------------------------------------------------------
908 bool Setting::lookupValue(const char *name, unsigned long long &value)
911 SETTING_LOOKUP_NO_EXCEPTIONS(name, unsigned long long, value);
914 // ---------------------------------------------------------------------------
916 bool Setting::lookupValue(const char *name, double &value) const throw()
918 SETTING_LOOKUP_NO_EXCEPTIONS(name, double, value);
921 // ---------------------------------------------------------------------------
923 bool Setting::lookupValue(const char *name, float &value) const throw()
925 SETTING_LOOKUP_NO_EXCEPTIONS(name, float, value);
928 // ---------------------------------------------------------------------------
930 bool Setting::lookupValue(const char *name, std::string &value) const throw()
932 SETTING_LOOKUP_NO_EXCEPTIONS(name, std::string, value);
935 // ---------------------------------------------------------------------------
937 bool Setting::exists(const char *name) const throw()
939 if(_type != TypeGroup)
942 config_setting_t *setting = config_setting_get_member(_setting, name);
944 return(setting != NULL);
947 // ---------------------------------------------------------------------------
949 int Setting::getLength() const throw()
951 return(config_setting_length(_setting));
954 // ---------------------------------------------------------------------------
956 const char * Setting::getName() const throw()
958 return(config_setting_name(_setting));
961 // ---------------------------------------------------------------------------
963 std::string Setting::getPath() const
965 std::stringstream path;
967 __constructPath(*this, path);
972 // ---------------------------------------------------------------------------
974 const Setting & Setting::getParent() const throw(SettingNotFoundException)
976 config_setting_t *setting = config_setting_parent(_setting);
979 throw SettingNotFoundException(NULL);
981 return(wrapSetting(setting));
984 // ---------------------------------------------------------------------------
986 Setting & Setting::getParent() throw(SettingNotFoundException)
988 config_setting_t *setting = config_setting_parent(_setting);
991 throw SettingNotFoundException(NULL);
993 return(wrapSetting(setting));
996 // ---------------------------------------------------------------------------
998 unsigned int Setting::getSourceLine() const throw()
1000 return(config_setting_source_line(_setting));
1003 // ---------------------------------------------------------------------------
1005 const char *Setting::getSourceFile() const throw()
1007 return(config_setting_source_file(_setting));
1010 // ---------------------------------------------------------------------------
1012 bool Setting::isRoot() const throw()
1014 return(config_setting_is_root(_setting));
1017 // ---------------------------------------------------------------------------
1019 int Setting::getIndex() const throw()
1021 return(config_setting_index(_setting));
1024 // ---------------------------------------------------------------------------
1026 void Setting::remove(const char *name)
1027 throw(SettingTypeException, SettingNotFoundException)
1029 assertType(TypeGroup);
1031 if(! config_setting_remove(_setting, name))
1032 throw SettingNotFoundException(*this, name);
1035 // ---------------------------------------------------------------------------
1037 void Setting::remove(unsigned int idx)
1038 throw(SettingTypeException, SettingNotFoundException)
1040 if((_type != TypeArray) && (_type != TypeGroup) && (_type != TypeList))
1041 throw SettingTypeException(*this, idx);
1043 if(! config_setting_remove_elem(_setting, idx))
1044 throw SettingNotFoundException(*this, idx);
1047 // ---------------------------------------------------------------------------
1049 Setting & Setting::add(const char *name, Setting::Type type)
1050 throw(SettingNameException, SettingTypeException)
1052 assertType(TypeGroup);
1054 int typecode = __toTypeCode(type);
1056 if(typecode == CONFIG_TYPE_NONE)
1057 throw SettingTypeException(*this, name);
1059 config_setting_t *setting = config_setting_add(_setting, name, typecode);
1062 throw SettingNameException(*this, name);
1064 return(wrapSetting(setting));
1067 // ---------------------------------------------------------------------------
1069 Setting & Setting::add(Setting::Type type) throw(SettingTypeException)
1071 if((_type != TypeArray) && (_type != TypeList))
1072 throw SettingTypeException(*this);
1074 if(_type == TypeArray)
1076 int idx = getLength();
1080 Setting::Type atype = operator[](0).getType();
1082 throw SettingTypeException(*this, idx);
1086 if((type != TypeInt) && (type != TypeInt64) && (type != TypeFloat)
1087 && (type != TypeString) && (type != TypeBoolean))
1088 throw SettingTypeException(*this, idx);
1092 int typecode = __toTypeCode(type);
1093 config_setting_t *s = config_setting_add(_setting, NULL, typecode);
1095 Setting &ns = wrapSetting(s);
1104 ns = INT64_CONST(0);
1127 // ---------------------------------------------------------------------------
1129 void Setting::assertType(Setting::Type type) const throw(SettingTypeException)
1133 if(!(isNumber() && config_get_auto_convert(_setting->config)
1134 && ((type == TypeInt) || (type == TypeInt64) || (type == TypeFloat))))
1135 throw SettingTypeException(*this);
1139 // ---------------------------------------------------------------------------
1141 Setting & Setting::wrapSetting(config_setting_t *s)
1143 Setting *setting = NULL;
1145 void *hook = config_setting_get_hook(s);
1148 setting = new Setting(s);
1149 config_setting_set_hook(s, reinterpret_cast<void *>(setting));
1152 setting = reinterpret_cast<Setting *>(hook);
1157 // ---------------------------------------------------------------------------
1159 Setting::iterator Setting::begin()
1160 { return iterator(*this); }
1162 // ---------------------------------------------------------------------------
1164 Setting::iterator Setting::end()
1165 { return iterator(*this, true); }
1167 // ---------------------------------------------------------------------------
1169 Setting::const_iterator Setting::begin() const
1170 { return const_iterator(*this); }
1172 // ---------------------------------------------------------------------------
1174 Setting::const_iterator Setting::end() const
1175 { return const_iterator(*this, true); }
1177 // ---------------------------------------------------------------------------
1179 SettingIterator::SettingIterator(Setting& setting, bool endIterator)
1180 : _setting(&setting), _count(setting.getLength())
1188 // ---------------------------------------------------------------------------
1190 SettingIterator::SettingIterator(const SettingIterator &rhs)
1191 : _setting(rhs._setting), _count(rhs._count), _idx(rhs._idx)
1195 // ---------------------------------------------------------------------------
1197 SettingIterator& SettingIterator::operator=(const SettingIterator &rhs)
1199 _setting = rhs._setting;
1200 _count = rhs._count;
1205 // ---------------------------------------------------------------------------
1207 SettingIterator& SettingIterator::operator ++()
1213 // ---------------------------------------------------------------------------
1215 SettingIterator SettingIterator::operator ++(int)
1217 SettingIterator tmp(*this);
1222 // ---------------------------------------------------------------------------
1224 SettingIterator& SettingIterator::operator --()
1230 // ---------------------------------------------------------------------------
1232 SettingIterator SettingIterator::operator --(int)
1234 SettingIterator tmp(*this);
1239 // ---------------------------------------------------------------------------
1241 SettingIterator SettingIterator::operator +(int offset) const
1243 SettingIterator cpy(*this);
1248 // ---------------------------------------------------------------------------
1250 SettingIterator& SettingIterator::operator +=(int offset)
1256 // ---------------------------------------------------------------------------
1258 SettingIterator operator +(int offset, SettingIterator& si)
1260 SettingIterator cpy(si);
1265 // ---------------------------------------------------------------------------
1267 SettingIterator SettingIterator::operator -(int offset) const
1269 SettingIterator cpy(*this);
1274 // ---------------------------------------------------------------------------
1276 SettingIterator& SettingIterator::operator -=(int offset)
1282 // ---------------------------------------------------------------------------
1284 int SettingIterator::operator -(SettingIterator const& rhs) const
1286 return _idx - rhs._idx;
1289 // ---------------------------------------------------------------------------
1291 SettingConstIterator::SettingConstIterator(const Setting &setting, bool endIterator)
1292 : _setting(&setting), _count(setting.getLength())
1300 // ---------------------------------------------------------------------------
1302 SettingConstIterator::SettingConstIterator(const SettingConstIterator &rhs)
1303 : _setting(rhs._setting), _count(rhs._count), _idx(rhs._idx)
1307 // ---------------------------------------------------------------------------
1309 SettingConstIterator& SettingConstIterator::operator=(const SettingConstIterator &rhs)
1311 _setting = rhs._setting;
1312 _count = rhs._count;
1317 // ---------------------------------------------------------------------------
1319 SettingConstIterator& SettingConstIterator::operator ++()
1320 { ++_idx; return *this; }
1322 // ---------------------------------------------------------------------------
1324 SettingConstIterator SettingConstIterator::operator ++(int)
1326 SettingConstIterator tmp(*this);
1331 // ---------------------------------------------------------------------------
1333 SettingConstIterator& SettingConstIterator::operator --()
1339 // ---------------------------------------------------------------------------
1341 SettingConstIterator SettingConstIterator::operator --(int)
1343 SettingConstIterator tmp(*this);
1348 // ---------------------------------------------------------------------------
1350 SettingConstIterator SettingConstIterator::operator +(int offset) const
1352 SettingConstIterator cpy(*this);
1357 // ---------------------------------------------------------------------------
1359 SettingConstIterator& SettingConstIterator::operator +=(int offset)
1365 // ---------------------------------------------------------------------------
1367 SettingConstIterator operator +(int offset, SettingConstIterator& si)
1369 SettingConstIterator cpy(si);
1374 // ---------------------------------------------------------------------------
1376 SettingConstIterator SettingConstIterator::operator -(int offset) const
1378 SettingConstIterator cpy(*this);
1383 // ---------------------------------------------------------------------------
1385 SettingConstIterator& SettingConstIterator::operator -=(int offset)
1391 // ---------------------------------------------------------------------------
1393 int SettingConstIterator::operator -(SettingConstIterator const& rhs) const
1395 return _idx - rhs._idx;
1399 } // namespace libconfig