OpenMPCD
Configuration.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the Configuration class
4  */
5 
6 #ifndef OPENMPCD_CONFIGURATION_HPP
7 #define OPENMPCD_CONFIGURATION_HPP
8 
14 
15 #include <boost/algorithm/string.hpp>
16 #include <libconfig.h++>
17 
18 #include <set>
19 #include <sstream>
20 #include <utility>
21 #include <vector>
22 
23 namespace OpenMPCD
24 {
25  /**
26  * Represents the configuration of the simulation.
27  */
29  {
30  public:
31  class List;
32 
33  /**
34  * Represents a setting in the configuration.
35  */
36  class Setting
37  {
38  public:
39  /**
40  * The constructor.
41  * The instance is only valid as long as the Configuration
42  * instance it originated from is valid.
43  *
44  * @param[in] s The setting.
45  */
46  Setting(const libconfig::Setting& s) : setting(&s)
47  {
48  }
49 
50  /**
51  * Returns whether the setting has a name.
52  */
53  bool hasName() const
54  {
55  return setting->getName() != NULL;
56  }
57 
58  /**
59  * Returns the name of the setting.
60  *
61  * @throw OpenMPCD::InvalidCallException
62  * If `OPENMPCD_DEBUG` is defined, throws if `!hasName()`.
63  */
64  const std::string getName() const
65  {
66  #ifdef OPENMPCD_DEBUG
67  if(!hasName())
69  #endif
70 
71  return setting->getName();
72  }
73 
74  /**
75  * Returns whether a setting with the given name exists.
76  *
77  * @throw OpenMPCD::InvalidArgumentException
78  * Throws if the setting name is illegal.
79  *
80  * @param[in] settingName The setting name.
81  */
82  bool has(const std::string& settingName) const
83  {
84  const std::string::size_type dot = settingName.find(".");
85 
86  if(dot != std::string::npos)
87  {
88  if(dot == 0 || dot + 1 >= settingName.size())
89  {
92  settingName + " is not a legal setting name.");
93  }
94 
95  const std::string first = settingName.substr(0, dot);
96 
97  if(!setting->exists(first))
98  return false;
99 
100  const Setting subsetting(setting->lookup(first));
101 
102  const std::string second = settingName.substr(dot + 1);
103  return subsetting.has(second);
104  }
105 
106  return setting->exists(settingName);
107  }
108 
109  /**
110  * Reads the specified setting and stores it at the given
111  * location.
112  *
113  * @throw OpenMPCD::InvalidArgumentException
114  * Throws if the setting name is illegal.
115  * @throw OpenMPCD::InvalidConfigurationException
116  * Throws if the setting does not exist.
117  * @throw OpenMPCD::InvalidConfigurationException
118  * Throws if the setting could not be read into the
119  * specified type.
120  * @throw OpenMPCD::NULLPointerException
121  * If `OPENMPCD_DEBUG` is defined, throws if the given
122  * pointer is `NULL`.
123  *
124  * @tparam ValueType The type of the settings value.
125  *
126  * @param[in] name The setting name, relative to this setting.
127  * @param[out] value The location to read the setting value
128  * into.
129  */
130  template<typename ValueType>
131  void read(const std::string& name, ValueType* const value)
132  const
133  {
134  #ifdef OPENMPCD_DEBUG
135  if(value==NULL)
137  #endif
138 
139  const std::string::size_type dot = name.find(".");
140 
141  if(dot != std::string::npos)
142  {
143  if(dot == 0 || dot + 1 >= name.size())
144  {
147  name + " is not a legal setting name.");
148  }
149 
150  const std::string first = name.substr(0, dot);
151 
152  if(!setting->exists(first))
153  {
156  name + " does not exist.");
157  }
158 
159  const Setting subsetting(setting->lookup(first));
160 
161  const std::string second = name.substr(dot + 1);
162  return subsetting.read(second, value);
163  }
164 
165  if(!setting->lookupValue(name, *value))
166  {
167  if(!setting->exists(name))
170  name+" does not exist.");
171 
172  const libconfig::Setting::Type type =
173  setting->lookup(name).getType();
174  const std::string typeString =
177 
180  name + " has an unexpected type: " + typeString);
181  }
182  }
183 
184  /**
185  * Reads the specified setting and stores it at the given
186  * location.
187  *
188  * @throw OpenMPCD::InvalidArgumentException
189  * Throws if the setting name is illegal.
190  * @throw OpenMPCD::InvalidConfigurationException
191  * Throws if the setting does not exist.
192  * @throw OpenMPCD::InvalidConfigurationException
193  * Throws if the setting could not be read into the
194  * specified type.
195  * @throw OpenMPCD::NULLPointerException
196  * If `OPENMPCD_DEBUG` is defined, throws if the given
197  * pointer is `NULL`.
198  *
199  * @param[in] name The setting name, relative to this setting.
200  * @param[out] value The location to read the setting value
201  * into.
202  */
203  void read(const std::string& name, std::size_t* const value)
204  const
205  {
206  unsigned int tmp;
207  read(name, &tmp);
208  *value = tmp;
209  }
210 
211  /**
212  * Returns the specified setting.
213  *
214  * @throw OpenMPCD::InvalidConfigurationException
215  * Throws if the settings could not be read into the
216  * specified type.
217  *
218  * @tparam ValueType The type of the settings value.
219  *
220  * @param[in] name The setting name, relative to this setting.
221  */
222  template<typename ValueType>
223  ValueType read(const std::string& name) const
224  {
225  ValueType value;
226  read(name, &value);
227  return value;
228  }
229 
230  /**
231  * Returns the number of direct child settings in this setting.
232  *
233  * This function does not count children of children.
234  */
235  std::size_t getChildCount() const
236  {
237  return static_cast<std::size_t>(setting->getLength());
238  }
239 
240  /**
241  * Returns the child setting with the given index.
242  *
243  * @param[in] childIndex
244  * The index of the child setting, which must be less
245  * than `getChildCount()`.
246  *
247  * @throw OpenMPCD::InvalidArgumentException
248  * Throws if the index is illegal.
249  */
250  const Setting getChild(const std::size_t childIndex) const
251  {
252  typedef libconfig::Setting::const_iterator It;
253 
254  std::size_t current = 0;
255  for(It it = setting->begin(); it != setting->end(); ++it)
256  {
257  if(current == childIndex)
258  return Setting(*it);
259  ++current;
260  }
261 
262  OPENMPCD_THROW(InvalidArgumentException, "`childIndex`");
263  }
264 
265  /**
266  * Returns the setting object with the given name.
267  *
268  * @throw OpenMPCD::InvalidArgumentException
269  * Throws if the setting name is illegal.
270  * @throw OpenMPCD::InvalidConfigurationException
271  * Throws if the given name does not exist.
272  *
273  * @param[in] name The setting name.
274  */
275  const Setting getSetting(const std::string& name) const
276  {
277  if(!has(name))
278  {
281  name + " does not exist.");
282  }
283 
284  return Setting(setting->lookup(name));
285  }
286 
287  /**
288  * Returns the list object with the given name.
289  *
290  * @throw OpenMPCD::InvalidArgumentException
291  * Throws if the setting name is illegal.
292  * @throw OpenMPCD::InvalidConfigurationException
293  * Throws if the given name does not exist.
294  *
295  * @param[in] name The setting name.
296  */
297  const List getList(const std::string& name) const;
298 
299  /**
300  * Returns whether all children in this setting have names that
301  * are in the given set.
302  *
303  * @param[in] names
304  * The names against to compare the children's names
305  * to.
306  * @param[out] offender
307  * If not `NULL` and if `true` is returned, the
308  * pointee is set to the name of the first child
309  * encountered whose name is not in the given set
310  * `names`.
311  */
313  const std::set<std::string>& names,
314  std::string* const offender = NULL) const;
315 
316  private:
317  const libconfig::Setting* setting; ///< The setting.
318  }; //class Setting
319 
320  /**
321  * Represents a list, or an array, of values.
322  */
323  class List
324  {
325  public:
326  /**
327  * The constructor.
328  * The instance is only valid as long as the Configuration instance it originated
329  * from is valid.
330  * @param[in] s The setting.
331  * @throw Exception If OPENMPCD_DEBUG is defined, throws if this setting is
332  * neither a list nor an array in the libconfig sense.
333  */
334  List(const libconfig::Setting& s) : setting(&s)
335  {
336  #ifdef OPENMPCD_DEBUG
337  if(!setting->isArray() && !setting->isList())
338  OPENMPCD_THROW(Exception, "Unexpected setting type.");
339  #endif
340  }
341 
342  public:
343  /**
344  * Returns the number of elements in the list.
345  */
346  unsigned int getSize() const
347  {
348  return setting->getLength();
349  }
350 
351  /**
352  * Returns the setting object with the given index.
353  *
354  * @throw OpenMPCD::InvalidConfigurationException
355  * Throws if the given index does not exist.
356  *
357  * @param[in] index The setting index, starting at 0.
358  */
359  const Setting getSetting(const unsigned int index) const
360  {
361  if(index >= getSize())
362  {
365  }
366 
367  return Setting((*setting)[index]);
368  }
369 
370  /**
371  * Returns the list with the given index.
372  * @param[in] index The index to return.
373  * @throw InvalidConfigurationException Throws if the given index does not exist
374  * or is not a list.
375  */
376  const List getList(const unsigned int index) const
377  {
378  if(index >= getSize())
380 
381  const libconfig::Setting& child = (*setting)[index];
382 
383  if(!child.isArray() && !child.isList())
384  OPENMPCD_THROW(Exception, "Tried to getList, but found something else.");
385 
386  return List(child);
387  }
388 
389  /**
390  * Reads the specified setting and stores them in the given location.
391  * @throw InvalidConfigurationException Throws if the setting could not be read into the
392  * specified type.
393  * @throw NULLPointerException If OPENMPCD_DEBUG is defined, throws if the given
394  * pointer is NULL.
395  * @tparam ValueType The type of the settings value.
396  * @param[in] index The setting index.
397  * @param[out] value The location to read the setting value into.
398  */
399  template<typename ValueType>
400  void read(const unsigned int index, ValueType* const value) const
401  {
402  #ifdef OPENMPCD_DEBUG
403  if(value==NULL)
405  #endif
406 
407  try
408  {
409  *value=static_cast<ValueType>((*setting)[index]);
410  }
411  catch(...)
412  {
415  "Setting has an unexpected type or does not exist.");
416  }
417  }
418 
419  /**
420  * Reads the specified setting and stores it in the given
421  * location.
422  *
423  * @throw OpenMPCD::InvalidConfigurationException
424  * Throws if the setting ist not a string.
425  * @throw OpenMPCD::NULLPointerException
426  * If `OPENMPCD_DEBUG` is defined, throws if
427  * `value == nullptr`.
428  *
429  * @param[in] index
430  * The setting index.
431  * @param[out] value
432  * The location to read the setting value into.
433  */
434  void read(
435  const unsigned int index, std::string* const value)
436  const
437  {
438  #ifdef OPENMPCD_DEBUG
439  if(value==NULL)
441  #endif
442 
443  try
444  {
445  *value = (*setting)[index].operator std::string();
446  }
447  catch(...)
448  {
451  "Setting has an unexpected type or does not "
452  "exist.");
453  }
454  }
455 
456  /**
457  * Returns the specified setting from the given configuration file.
458  * @throw InvalidConfigurationException Throws if the settings could not be read into
459  * the specified type.
460  * @tparam ValueType The type of the settings value.
461  * @param[in] index The setting index
462  */
463  template<typename ValueType>
464  ValueType read(const unsigned int index) const
465  {
466  ValueType value;
467  read(index, &value);
468  return value;
469  }
470 
471  private:
472  const libconfig::Setting* setting; ///< The underlying setting.
473  };
474 
475  public:
476  /**
477  * The constructor.
478  */
480  {
481  }
482 
483  /**
484  * The constructor.
485  *
486  * @throw OpenMPCD::IOException
487  * Throws if the configuration file could not be read.
488  * @throw OpenMPCD::MalformedFileException
489  * Throws if the configuration file is malformed.
490  *
491  * @param[in] filename The filename for the configuration file.
492  */
493  Configuration(const std::string& filename);
494 
495  /**
496  * The copy constructor.
497  * @param[in] rhs The instance to copy.
498  */
500  {
501  ImplementationDetails::Configuration::copy(rhs.config, &config);
502  }
503 
504  public:
505  /**
506  * Returns whether a setting with the given name exists.
507  * @param[in] setting The setting name.
508  */
509  bool has(const std::string& setting) const
510  {
511  return config.exists(setting);
512  }
513 
514  /**
515  * Reads the specified settings from the given configuration file and stores them in the given location.
516  * @throw std::runtime_error Throws if any of the settings could not be read into the specified type.
517  * @throw std::runtime_error If OPENMPCD_DEBUG is defined, throws if any of given pointers is NULL.
518  * @tparam ValueType The types of the settings values.
519  * @tparam settingsCount The number of settings to read.
520  * @param[in,out] settingsAndValues The names of the settings to read, and the locations to store their values into.
521  */
522  template<typename ValueType, unsigned int settingsCount>
523  void read(const std::pair<const char*, ValueType*> (&settingsAndValues)[settingsCount]) const
524  {
525  for(unsigned int i=0; i<settingsCount; ++i)
526  read(settingsAndValues[i].first, settingsAndValues[i].second);
527  }
528 
529  /**
530  * Reads the specified setting from the given configuration file and stores them in the given location.
531  * @throw std::runtime_error Throws if the settings could not be read into the specified type.
532  * @throw std::runtime_error If OPENMPCD_DEBUG is defined, throws if the given pointer is NULL.
533  * @tparam ValueType The type of the settings value.
534  * @param[in] setting The name of the setting to read.
535  * @param[out] value The location to read the setting value into.
536  */
537  template<typename ValueType>
538  void read(const std::string& setting, ValueType* const value) const
539  {
540  #ifdef OPENMPCD_DEBUG
541  if(value==NULL)
543  #endif
544 
545  if(!config.lookupValue(setting, *value))
546  {
547  if(!config.exists(setting))
548  OPENMPCD_THROW(InvalidConfigurationException, setting+" does not exist.");
549 
550  const libconfig::Setting::Type type = config.lookup(setting).getType();
551  const std::string typeString = ImplementationDetails::Configuration::getSettingTypeString(type);
552 
553  OPENMPCD_THROW(InvalidConfigurationException, setting+" has an unexpected type: " + typeString);
554  }
555  }
556 
557  /**
558  * Returns the specified setting from the given configuration file.
559  * @throw std::runtime_error Throws if the settings could not be read into the specified type.
560  * @tparam ValueType The type of the settings value.
561  * @param[in] setting The name of the setting to read.
562  */
563  template<typename ValueType>
564  ValueType read(const std::string& setting) const
565  {
566  ValueType value;
567  read(setting, &value);
568  return value;
569  }
570 
571  /**
572  * Returns the setting object with the given name.
573  *
574  * @throw OpenMPCD::InvalidConfigurationException
575  * Throws if the given name does not exist.
576  *
577  * @param[in] name The setting name.
578  */
579  const Setting getSetting(const std::string& name) const
580  {
581  if(!has(name))
582  {
584  InvalidConfigurationException, name+" does not exist.");
585  }
586 
587  return Setting(config.lookup(name));
588  }
589 
590  /**
591  * Returns the list with the given name.
592  * @param[in] name The list name.
593  * @throw InvalidConfigurationException Throws if the given name does not exist
594  * or is not a list.
595  */
596  const List getList(const std::string& name) const
597  {
598  if(!has(name))
599  OPENMPCD_THROW(InvalidConfigurationException, name+" does not exist.");
600 
601  const libconfig::Setting& child = config.lookup(name);
602 
603  if(!child.isArray() && !child.isList())
604  OPENMPCD_THROW(Exception, "Tried to getList, but found something else.");
605 
606  return List(child);
607  }
608 
609  /**
610  * Asserts that the given setting exists, and has the specified type and value.
611  * @throw std::runtime_error Throws if the assertion fails.
612  * @tparam ValueType The type of the settings value.
613  * @param[in] setting The name of the setting to read.
614  * @param[in] value The value that the setting should have.
615  */
616  template <typename ValueType>
617  void assertValue(const std::string& setting, const ValueType& value) const
618  {
619  ValueType configValue;
620  if(!config.lookupValue(setting, configValue))
622 
623  if(configValue!=value)
624  {
625  std::stringstream message;
626  message<<setting<<": value is \""<<configValue<<"\", expected \""<<value<<"\"";
628  }
629  }
630 
631  /**
632  * Asserts that the given setting exists, and has the specified type and value.
633  * @throw std::runtime_error Throws if the assertion fails.
634  * @tparam ValueType The type of the settings value.
635  * @param[in] setting The name of the setting to read.
636  * @param[in] value The value that the setting should have.
637  */
638  template <int N>
639  void assertValue(const std::string& setting, const char (&value)[N]) const
640  {
641  std::string configValue;
642  if(!config.lookupValue(setting, configValue))
644 
645  if(configValue!=value)
646  {
647  std::stringstream message;
648  message<<setting<<": value is \""<<configValue<<"\", expected \""<<value<<"\"";
650  }
651  }
652 
653  /**
654  * Sets a setting's value.
655  * @throw InvalidArgumentException Throws if the setting already exists, but is of the wrong type.
656  * @tparam ValueType The type of the setting's value.
657  * @param[in] setting The name of the setting to set.
658  * @param[in] value The value to set the setting to.
659  */
660  template<typename ValueType>
661  void set(const std::string& setting, const ValueType value)
662  {
663  std::vector<std::string> pathComponents;
664  boost::algorithm::split(pathComponents, setting, boost::algorithm::is_any_of("."));
665 
666  libconfig::Setting* currentSetting = &config.getRoot();
667  for(unsigned int level=0; level < pathComponents.size(); ++level)
668  {
669  const bool isLastLevel = level + 1 == pathComponents.size();
670  const std::string currentName = pathComponents[level];
671 
672  if(isLastLevel)
673  {
674  if(currentSetting->exists(currentName))
675  {
676  try
677  {
678  (*currentSetting)[currentName.c_str()] = value;
679  }
680  catch(const libconfig::SettingTypeException&)
681  {
682  OPENMPCD_THROW(InvalidArgumentException, "Tried to set existing setting with wrong type.");
683  }
684  }
685  else
686  {
687  ImplementationDetails::Configuration::Setting::createSetting(currentSetting, currentName, value);
688  }
689  }
690  else
691  {
692  if(currentSetting->exists(currentName))
693  {
694  std::string lookupPath = currentSetting->getPath();
695  if(!lookupPath.empty())
696  lookupPath += ".";
697  lookupPath += currentName;
698 
699  currentSetting = &config.lookup(lookupPath);
700  #ifdef OPENMPCD_DEBUG
701  if(!currentSetting->isAggregate())
702  OPENMPCD_THROW(Exception, lookupPath + " is not aggregate.");
703  #endif
704  }
705  else
706  {
707  currentSetting = &currentSetting->add(currentName, libconfig::Setting::TypeGroup);
708  }
709  }
710  }
711  }
712 
713  /**
714  * Creates a settings group.
715  * Parent groups are created as necessary.
716  * @param[in] name The name of the group.
717  * @throw Exception Throws if the name is already in use.
718  */
719  void createGroup(const std::string& name)
720  {
721  createAggregateSetting(name, libconfig::Setting::TypeGroup);
722  }
723 
724  /**
725  * Creates a settings list.
726  * Parent groups are created as necessary.
727  * @param[in] name The name of the list.
728  * @throw Exception Throws if the name is already in use.
729  */
730  void createList(const std::string& name)
731  {
732  createAggregateSetting(name, libconfig::Setting::TypeList);
733  }
734 
735  /**
736  * Writes the configuration to the given path.
737  * @param[in] path The path to write to.
738  */
739  void writeToFile(const std::string& path) const
740  {
741  config.writeFile(path.c_str());
742  }
743 
744  public:
745  /**
746  * The assignment operator.
747  *
748  * @param[in] rhs The instance to copy.
749  *
750  * @return Returns a reference to this instance.
751  */
753  {
754  ImplementationDetails::Configuration::copy(rhs.config, &config);
755  return *this;
756  }
757 
758  private:
759  /**
760  * Creates an aggregate setting.
761  * Parent groups are created as necessary.
762  * @param[in] name The name of the group.
763  * @param[in] type The type of the setting.
764  * @throw Exception Throws if the name is already in use.
765  * @throw InvalidArgumentException Throws if the type is not an aggregate setting type.
766  */
767  void createAggregateSetting(const std::string& name, const libconfig::Setting::Type type)
768  {
769  if(has(name))
770  OPENMPCD_THROW(Exception, "Name already in use.");
771 
772  if(
773  type != libconfig::Setting::TypeGroup &&
774  type != libconfig::Setting::TypeArray &&
775  type != libconfig::Setting::TypeList)
776  {
777  OPENMPCD_THROW(InvalidArgumentException, "Invalid type given.");
778  }
779 
780  std::vector<std::string> pathComponents;
781  boost::algorithm::split(pathComponents, name, boost::algorithm::is_any_of("."));
782 
783  libconfig::Setting* currentSetting = &config.getRoot();
784  for(unsigned int level=0; level < pathComponents.size(); ++level)
785  {
786  const std::string currentName = pathComponents[level];
787 
788  if(currentSetting->exists(currentName))
789  {
790  std::string lookupPath = currentSetting->getPath();
791  if(!lookupPath.empty())
792  lookupPath += ".";
793  lookupPath += currentName;
794 
795  currentSetting = &config.lookup(lookupPath);
796  }
797  else
798  {
799  const bool isLastLevel = level + 1 == pathComponents.size();
800  const libconfig::Setting::Type typeToCreate = isLastLevel ? type : libconfig::Setting::TypeGroup;
801  currentSetting = &currentSetting->add(currentName, typeToCreate);
802  }
803  }
804  }
805 
806  private:
807  mutable libconfig::Config config; ///< The simulation configuration.
808  };
809 
810  inline
811  const Configuration::List
812  Configuration::Setting::getList(const std::string& name) const
813  {
814  if(!has(name))
815  {
818  name + " does not exist.");
819  }
820 
821  return List(setting->lookup(name));
822  }
823 
824  #ifdef OPENMPCD_COMPILER_GCC
825  #pragma GCC diagnostic push
826  #pragma GCC diagnostic ignored "-Wsign-compare"
827  #endif
828  /**
829  * Sets a setting's value.
830  *
831  * @throw OpenMPCD::InvalidArgumentException
832  * Throws if the setting already exists, but is of the wrong type.
833  *
834  * @param[in] setting
835  * The name of the setting to set.
836  * @param[in] value
837  * The value to set the setting to.
838  */
839  template<> inline void Configuration::set(const std::string& setting, const unsigned int value)
840  {
841  if(static_cast<int>(value) == value)
842  {
843  set(setting, static_cast<int>(value));
844  }
845  else
846  {
847  #ifdef OPENMPCD_DEBUG
848  if(static_cast<long long int>(value) != value)
849  OPENMPCD_THROW(Exception, "Cannot represent config value.");
850  #endif
851 
852  set(setting, static_cast<long long int>(value));
853  }
854  }
855  #ifdef OPENMPCD_COMPILER_GCC
856  #pragma GCC diagnostic pop
857  #endif
858 }
859 
861 
862 #endif
copy.hpp
OpenMPCD::ImplementationDetails::Configuration::Setting::createSetting
static void createSetting(libconfig::Setting *const parent, const std::string &name, const bool value)
Creates a new setting with the given value.
Definition: Setting.hpp:42
OpenMPCD::Configuration::getSetting
const Setting getSetting(const std::string &name) const
Returns the setting object with the given name.
Definition: Configuration.hpp:579
OpenMPCD::Configuration::has
bool has(const std::string &setting) const
Returns whether a setting with the given name exists.
Definition: Configuration.hpp:509
OpenMPCD::Configuration::Setting::getChildCount
std::size_t getChildCount() const
Returns the number of direct child settings in this setting.
Definition: Configuration.hpp:235
OpenMPCD::InvalidCallException
Exception for a forbidden function call.
Definition: Exceptions.hpp:144
OpenMPCD::Configuration::Setting::getChild
const Setting getChild(const std::size_t childIndex) const
Returns the child setting with the given index.
Definition: Configuration.hpp:250
OpenMPCD::Configuration::List::List
List(const libconfig::Setting &s)
The constructor.
Definition: Configuration.hpp:334
OpenMPCD::Configuration::getList
const List getList(const std::string &name) const
Returns the list with the given name.
Definition: Configuration.hpp:596
OpenMPCD::Configuration
Represents the configuration of the simulation.
Definition: Configuration.hpp:28
CompilerDetection.hpp
Exceptions.hpp
getSettingTypeString.hpp
OpenMPCD::Configuration::List::getSize
unsigned int getSize() const
Returns the number of elements in the list.
Definition: Configuration.hpp:346
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::Configuration::assertValue
void assertValue(const std::string &setting, const char(&value)[N]) const
Asserts that the given setting exists, and has the specified type and value.
Definition: Configuration.hpp:639
Configuration.hpp
OpenMPCD::Configuration::createList
void createList(const std::string &name)
Creates a settings list.
Definition: Configuration.hpp:730
OpenMPCD::ImplementationDetails::Configuration::getSettingTypeString
const std::string getSettingTypeString(const libconfig::Setting::Type type)
Returns a string corresponding to the name of the given type.
Definition: getSettingTypeString.hpp:28
OpenMPCD::Configuration::List::read
void read(const unsigned int index, ValueType *const value) const
Reads the specified setting and stores them in the given location.
Definition: Configuration.hpp:400
OpenMPCD::Configuration::read
void read(const std::pair< const char *, ValueType * >(&settingsAndValues)[settingsCount]) const
Reads the specified settings from the given configuration file and stores them in the given location.
Definition: Configuration.hpp:523
OpenMPCD::Configuration::Setting::has
bool has(const std::string &settingName) const
Returns whether a setting with the given name exists.
Definition: Configuration.hpp:82
OpenMPCD::Configuration::List::read
ValueType read(const unsigned int index) const
Returns the specified setting from the given configuration file.
Definition: Configuration.hpp:464
OpenMPCD::Configuration::Setting::getSetting
const Setting getSetting(const std::string &name) const
Returns the setting object with the given name.
Definition: Configuration.hpp:275
OpenMPCD::Configuration::List
Represents a list, or an array, of values.
Definition: Configuration.hpp:323
OpenMPCD::Configuration::Setting::read
ValueType read(const std::string &name) const
Returns the specified setting.
Definition: Configuration.hpp:223
OpenMPCD::Configuration::set
void set(const std::string &setting, const ValueType value)
Sets a setting's value.
Definition: Configuration.hpp:661
OpenMPCD::Configuration::Setting::getName
const std::string getName() const
Returns the name of the setting.
Definition: Configuration.hpp:64
OpenMPCD::Configuration::read
void read(const std::string &setting, ValueType *const value) const
Reads the specified setting from the given configuration file and stores them in the given location.
Definition: Configuration.hpp:538
OpenMPCD::Configuration::assertValue
void assertValue(const std::string &setting, const ValueType &value) const
Asserts that the given setting exists, and has the specified type and value.
Definition: Configuration.hpp:617
OpenMPCD::Configuration::Setting::Setting
Setting(const libconfig::Setting &s)
The constructor.
Definition: Configuration.hpp:46
OpenMPCD::Configuration::read
ValueType read(const std::string &setting) const
Returns the specified setting from the given configuration file.
Definition: Configuration.hpp:564
OpenMPCD::Configuration::Setting::childrenHaveNamesInCollection
bool childrenHaveNamesInCollection(const std::set< std::string > &names, std::string *const offender=NULL) const
Returns whether all children in this setting have names that are in the given set.
Definition: Configuration.cpp:12
OpenMPCD::Configuration::createGroup
void createGroup(const std::string &name)
Creates a settings group.
Definition: Configuration.hpp:719
OpenMPCD::ImplementationDetails::Configuration::copy
void copy(const libconfig::Config &from, libconfig::Config *const to)
Copies a libconfig::Config instance.
Definition: copy.hpp:28
OpenMPCD::Configuration::List::getSetting
const Setting getSetting(const unsigned int index) const
Returns the setting object with the given index.
Definition: Configuration.hpp:359
OpenMPCD::Configuration::Setting::read
void read(const std::string &name, std::size_t *const value) const
Reads the specified setting and stores it at the given location.
Definition: Configuration.hpp:203
OpenMPCD::Configuration::List::read
void read(const unsigned int index, std::string *const value) const
Reads the specified setting and stores it in the given location.
Definition: Configuration.hpp:434
OpenMPCD::Configuration::operator=
const Configuration & operator=(const Configuration &rhs)
The assignment operator.
Definition: Configuration.hpp:752
OpenMPCD::Configuration::Setting
Represents a setting in the configuration.
Definition: Configuration.hpp:36
OpenMPCD::Configuration::writeToFile
void writeToFile(const std::string &path) const
Writes the configuration to the given path.
Definition: Configuration.hpp:739
OpenMPCD::InvalidConfigurationException
Represents an invalid configuration.
Definition: Exceptions.hpp:80
OpenMPCD::Configuration::Setting::hasName
bool hasName() const
Returns whether the setting has a name.
Definition: Configuration.hpp:53
OpenMPCD::Exception
The base exception class for OpenMPCD.
Definition: Exceptions.hpp:37
OpenMPCD::Configuration::Configuration
Configuration(const Configuration &rhs)
The copy constructor.
Definition: Configuration.hpp:499
Setting.hpp
OpenMPCD::Configuration::Configuration
Configuration()
The constructor.
Definition: Configuration.hpp:479
OpenMPCD::Configuration::List::getList
const List getList(const unsigned int index) const
Returns the list with the given index.
Definition: Configuration.hpp:376
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96
OpenMPCD::InvalidArgumentException
Invalid argument exception.
Definition: Exceptions.hpp:128
OpenMPCD::Configuration::Setting::read
void read(const std::string &name, ValueType *const value) const
Reads the specified setting and stores it at the given location.
Definition: Configuration.hpp:131
OpenMPCD::Configuration::Setting::getList
const List getList(const std::string &name) const
Returns the list object with the given name.
Definition: Configuration.hpp:812