1 #ifndef XML_SETTING_STORE_H_
2 #define XML_SETTING_STORE_H_
11 #include "SettingsStore.h"
12 #include "AbstractXMLParser.h"
17 // This class is not thread-safe.
18 class XmlSettingsStore
: public Dasher::CSettingsStore
, public AbstractXMLParser
{
20 XmlSettingsStore(const std::string
& filename
, CFileUtils
* fileUtils
, CMessageDisplay
* pDisplay
);
21 ~XmlSettingsStore() override
= default;
22 // Load the XML file and fills in the default values needed.
23 // Returns true on success.
25 // Saves the XML file, returns true on success.
29 bool LoadSetting(const std::string
& Key
, bool* Value
) override
;
30 bool LoadSetting(const std::string
& Key
, long* Value
) override
;
31 bool LoadSetting(const std::string
& Key
, std::string
* Value
) override
;
33 void SaveSetting(const std::string
& Key
, bool Value
) override
;
34 void SaveSetting(const std::string
& Key
, long Value
) override
;
35 void SaveSetting(const std::string
& Key
, const std::string
& Value
) override
;
37 void XmlStartHandler(const XML_Char
* name
, const XML_Char
** atts
) override
;
38 virtual void XmlEndHandler(const XML_Char
* name
) override
;
40 // Parses the tag attributes expecting exactly one 'value' and one 'name'
42 bool GetNameAndValue(const XML_Char
** attributes
, std::string
* name
,
45 // Save if the mode is 'SAVE_IMMEDIATELY', otherwise just set 'modified_' to
50 // Save each time 'SaveSetting' is called.
52 // Save only when 'Save' is called.
56 Mode mode_
= EXPLICIT_SAVE
;
57 std::string filename_
;
58 CFileUtils
* fileutils_
;
59 bool modified_
= false;
60 std::map
<std::string
, bool> boolean_settings_
;
61 std::map
<std::string
, long> long_settings_
;
62 std::map
<std::string
, std::string
> string_settings_
;
67 #endif // XML_SETTING_STORE_H_