51 struct ICLUtils_API XMLDocumentDelOp{
static void delete_func(pugi::xml_document *h); };
174 friend class ConfigFileGUI;
179 ICLException(
"Entry " + entryName+
" could not be found!"){}
186 ICLException(
"Invalid type " + typeName +
" (entry " + entryName +
")"){};
193 ICLException(
"type with RTTI ID " + rttiID +
" is not registered"){}
209 static Maps *getMapsInstance();
214 static std::map<std::string,std::string> s_typeMap;
215 static std::map<std::string,std::string> s_typeMapReverse;
221 static const std::string &rttiID = get_rtti_type_id<T>();
223 static const std::string &name = getMapsInstanceRef().typeMap[rttiID];
230 static std::string NAME =
typeid(T).name();
237 return check_type_internal(
id,get_rtti_type_id<T>());
241 bool check_type_internal(
const std::string &
id,
const std::string &rttiTypeID)
const 246 Maps &maps = getMapsInstanceRef();
254 #define REGISTER_CONFIG_FILE_TYPE(T) ::icl::utils::ConfigFile::register_type<T>(#T) 286 Maps &maps = getMapsInstanceRef();
287 std::string rtti = get_rtti_type_id<T>();
291 s_typeMap[get_rtti_type_id<T>()] = id;
292 s_typeMapReverse[id] = get_rtti_type_id<T>();
324 void load(
const std::string &filename);
327 void save(
const std::string &filename)
const;
330 void setPrefix(
const std::string &defaultPrefix)
const;
333 const std::string &getPrefix()
const;
353 return cf->
get<T>(id);
360 return cf->
get<T>(id);
390 Data operator [](
const std::string &
id);
394 const Data operator[](
const std::string &
id)
const ;
398 std::vector<Data> find(
const std::string ®ex);
403 const std::vector<Data>
find(
const std::string ®ex)
const{
404 return const_cast<ConfigFile*>(
this)->find(regex);
435 void set(
const std::string &
id,
const T &val) {
436 set_internal(
id,
str(val),get_rtti_type_id<T>());
451 inline T
get(
const std::string &idIn)
const {
454 return parse<T>(m_entries.find(m_sDefaultPrefix+idIn)->second.value);
461 inline T
get(
const std::string &idIn,
const T &def)
const {
462 if(!contains(idIn))
return def;
464 return parse<T>(m_entries.find(m_sDefaultPrefix+idIn)->second.value);
468 static void loadConfig(
const std::string &filename);
471 static void loadConfig(
const ConfigFile &configFile);
478 static inline T
sget(
const std::string &
id) {
479 return getConfig().get<T>(id);
484 static inline T
sget(
const std::string &
id,
const T &def) {
485 return getConfig().get<T>(id,def);
489 void listContents()
const;
492 bool contains(
const std::string &
id)
const;
498 hasRange(false),hasValues(false){}
500 hasRange(true),hasValues(false){
505 values(values),hasRange(false),hasValues(true){}
518 void setRestriction(
const std::string &
id,
const KeyRestriction &r) ;
522 const KeyRestriction *getRestriction(
const std::string &
id)
const ;
532 const std::string &
getTypeName()
const {
return getMapsInstanceRef().typeMap[rttiType]; }
536 const std::string &pfx = parent->getPrefix();
537 if(!pfx.length())
return id;
538 else return id.substr(pfx.length());
553 const std::vector<const Entry*>
getEntryList(
bool relToPrefix=
false)
const{
554 std::vector<const Entry*> v;
556 v.push_back(&it->second);
568 const pugi::xml_document *
getHandle()
const {
return m_doc.get(); }
573 void load_internal();
576 Entry &get_entry_internal(
const std::string &
id) ;
579 const Entry &get_entry_internal(
const std::string &
id)
const ;
582 void set_internal(
const std::string &
id,
const std::string &val,
const std::string &type) ;
585 static void add_to_doc(pugi::xml_document &h,
const std::string &
id,
const std::string &type,
586 const std::string &value,
const KeyRestriction *restr=0);
double min
Definition: ConfigFile.h:508
SmartPtrBase< pugi::xml_document, XMLDocumentDelOp > m_doc
shallow copyable smart pointer of the document handle
Definition: ConfigFile.h:589
std::string value
entries value as string
Definition: ConfigFile.h:527
T get(const std::string &idIn) const
returns a given value from the internal string based representation (un const)
Definition: ConfigFile.h:451
Utility Type for restriction of type values.
Definition: ConfigFile.h:496
ICLQt_API void save(const core::ImgBase &image, const std::string &filename)
write an image to HD
undocument this line if you encounter any issues!
Definition: Any.h:37
internal utility structure for contained data
Definition: ConfigFile.h:525
internally used type map class
Definition: ConfigFile.h:200
ConfigFile * cf
parent config file
Definition: ConfigFile.h:339
bool check_type(const std::string &id) const
internally used utitlity function (id must be given without prefix)
Definition: ConfigFile.h:236
Utility class for creating and reading XML-based hierarchical configuration files.
Definition: ConfigFile.h:171
UnregisteredTypeException(const std::string &rttiID)
Definition: ConfigFile.h:192
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
Data & operator=(const T &t)
mutlti class assignment operator
Definition: ConfigFile.h:378
~UnregisteredTypeException()
Definition: ConfigFile.h:194
std::string m_sDefaultPrefix
current string prefix contents
Definition: ConfigFile.h:596
ICLQt_API core::Img< T > load(const std::string &filename)
load an image file read file (affinity for floats)
std::string getRelID() const
returns this entries id relatively to the parent ConfigFiles prefix
Definition: ConfigFile.h:535
static T sget(const std::string &id)
applies get on the static config instances
Definition: ConfigFile.h:478
static ConfigFile s_oConfig
global ConfigFile instance
Definition: ConfigFile.h:592
Internal exception type, thrown if an entry type missmatch occurs.
Definition: ConfigFile.h:184
Data- type used for the []-operator of ConfigFile instances.
Definition: ConfigFile.h:337
Data & operator=(const Data &d)
special assignment for data instances
Definition: ConfigFile.h:365
void set(const std::string &id, const T &val)
sets or updates a new data element to the ConfigFile
Definition: ConfigFile.h:435
bool hasRange
Definition: ConfigFile.h:511
const_iterator end() const
all-entry iterator end
Definition: ConfigFile.h:550
KeyRestriction(double min, double max)
Definition: ConfigFile.h:499
static const ConfigFile & getConfig()
returns the global ConfigFile
Definition: ConfigFile.h:474
Internal exception type, thrown if an entry was not found.
Definition: ConfigFile.h:177
std::string rttiType
entries rtti type ID
Definition: ConfigFile.h:528
const std::vector< Data > find(const std::string ®ex) const
returns all data entries, that match the given regex (const);
Definition: ConfigFile.h:403
std::string values
Definition: ConfigFile.h:509
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
InvalidTypeException(const std::string &entryName, const std::string &typeName)
Definition: ConfigFile.h:185
T get(const std::string &idIn, const T &def) const
returns a given value from the internal string based representation
Definition: ConfigFile.h:461
ConfigFile * parent
Definition: ConfigFile.h:540
std::string str(const T &t)
convert a data type into a string using an std::ostringstream instance
Definition: StringUtils.h:136
std::map< std::string, std::string > typeMapReverse
reverse ordered map here, key is written type, and value is rtti-type
Definition: ConfigFile.h:205
std::string id
entries key (config.foo.bar....)
Definition: ConfigFile.h:526
static Maps & getMapsInstanceRef()
returns a singelton instance of type Maps as reference
Definition: ConfigFile.h:212
KeyRestriction(const std::string &values)
Definition: ConfigFile.h:504
static void register_type(const std::string &id)
registers a new type in the data store parsing engine
Definition: ConfigFile.h:285
static T sget(const std::string &id, const T &def)
applies get on the static config instances (with default)
Definition: ConfigFile.h:484
T as() const
explicit cast into given type
Definition: ConfigFile.h:359
virtual ~InvalidTypeException()
Definition: ConfigFile.h:187
const std::vector< const Entry * > getEntryList(bool relToPrefix=false) const
returns all entries as vector<const Entry*>
Definition: ConfigFile.h:553
std::map< std::string, Entry >::const_iterator const_iterator
iterator type to run through all entries (const only)
Definition: ConfigFile.h:544
static const std::string & get_rtti_type_id()
internally used utitlity function
Definition: ConfigFile.h:229
bool hasValues
Definition: ConfigFile.h:512
Base class for Exception handling in the ICL.
Definition: Exception.h:42
Interface for objects, that can be locked using an internal mutex.
Definition: Lockable.h:41
KeyRestriction()
Definition: ConfigFile.h:497
static const std::string & get_type_name()
internally used utitlity function
Definition: ConfigFile.h:220
SmartPtr< KeyRestriction > restr
Definition: ConfigFile.h:529
std::string id
internal id (config.foo.bar)
Definition: ConfigFile.h:338
static bool type_registered_by_rtti(const std::string &rttiID)
internally used utitlity function
Definition: ConfigFile.h:245
const std::string & getTypeName() const
optional restriction pointer
Definition: ConfigFile.h:532
std::map< std::string, Entry > m_entries
DataStore contents.
Definition: ConfigFile.h:600
thrown if unregistered types are used
Definition: ConfigFile.h:191
std::map< std::string, std::string > typeMap
key: rttiType (e.g. i), value: written type (e.g. int)
Definition: ConfigFile.h:202
const pugi::xml_document * getHandle() const
returns internal document handle (forward declared here) (const only)
Definition: ConfigFile.h:568
const_iterator begin() const
all-entry iterator begin
Definition: ConfigFile.h:547
EntryNotFoundException(const std::string &entryName)
Definition: ConfigFile.h:178
virtual ~EntryNotFoundException()
Definition: ConfigFile.h:180
Specialization of the SmartPtrBase class for Pointers.
Definition: SmartPtr.h:75