libcrn  3.9.5
A document image processing library
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNConfigurationFile.h
Go to the documentation of this file.
1 /* Copyright 2010-2015 CoReNum, INSA-Lyon, Université Paris Descartes
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNConfigurationFile.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNConfigurationFile_HEADER
23 #define CRNConfigurationFile_HEADER
24 
25 #include <CRNData/CRNData.h>
26 #include <CRNData/CRNMap.h>
27 #include <CRNIO/CRNPath.h>
28 
29 namespace crn
30 {
31  class String;
32 
33  enum class ConfigurationType { USER, APP };
34 
44  {
45  public:
47  ConfigurationFile(const String &application_name, const StringUTF8 &file_name = "", ConfigurationType ctype = ConfigurationType::APP);
48  ConfigurationFile(const ConfigurationFile &) = delete;
53  Path Load();
55  Path Save();
56 
58  SObject& operator[](const String &key);
60  SObject GetData(const String &key);
62  SCObject GetData(const String &key) const;
64  Path GetPath(const String &key) const;
66  String GetString(const String &key) const;
68  StringUTF8 GetStringUTF8(const String &key) const;
70  Prop3 GetProp3(const String &key) const;
72  int GetInt(const String &key) const;
74  double GetDouble(const String &key) const;
75 
79  template<typename T> void SetData(const String &key, T value)
80  {
81  data.Set(key, Data::ToCRN(value));
82  }
83 
85  Path GetUserDirectory() const;
86  private:
87  Map data;
88  Path appname;
89  Path filename;
90  ConfigurationType type;
91 
93  };
94 
95  CRN_ALIAS_SMART_PTR(ConfigurationFile)
96 }
97 
98 #endif
99 
100 
Path GetUserDirectory() const
Returns the path to the user configuration directory.
ConfigurationFile & operator=(const ConfigurationFile &)=delete
void SetData(const String &key, T value)
Sets a key/value pair.
SObject & operator[](const String &key)
Gets a value.
Path Load()
Loads the file.
double GetDouble(const String &key) const
Gets a double.
void Set(const String &key, SObject value)
Sets a value for a key with constraints check.
Definition: CRNMap.cpp:92
SObject GetData(const String &key)
Gets a value.
A UTF32 character string class.
Definition: CRNString.h:61
UInt ToCRN(int i)
Converts an int to CRN data.
Definition: CRNData.cpp:33
A convenience class for file paths.
Definition: CRNPath.h:39
Path Save()
Saves the file to the user's personal space.
String GetString(const String &key) const
Gets a string.
ConfigurationFile(const String &application_name, const StringUTF8 &file_name="", ConfigurationType ctype=ConfigurationType::APP)
Constructor.
Prop3 GetProp3(const String &key) const
Gets a Prop3.
StringUTF8 GetStringUTF8(const String &key) const
Gets a UTF8 string.
int GetInt(const String &key) const
Gets an int.
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
Definition: CRNObject.h:173
Data map class.
Definition: CRNMap.h:42
CRN_ALIAS_SMART_PTR(ImageBW)
A character string class.
Definition: CRNStringUTF8.h:49
A ternary proposition.
Definition: CRNProp3.h:40
Configuration file management utility class.
Path GetPath(const String &key) const
Gets a path.