4 // key names for properties we use
6 extern const char* key;
7 extern const char* ref;
8 extern const char* type;
9 extern const char* password;
13 * Class to store data on the unencrypted folder of a device.
14 * Note that the folder must exist before this class is constructed.
15 * All names must be valid single level (no '/') file or directory names
16 * Data is organized hierarchically so we can get a child folder
18 class UnencryptedProperties
21 // Opens properties folder on named device.
22 // If folder does not exist, construction will succeed, but all
23 // getters will return default properties and setters will fail.
24 UnencryptedProperties(const char* device);
26 // Get named object. Return default if object does not exist or error.
27 template<typename t> t Get(const char* name, t default_value = t());
29 // Set named object. Return true if success, false otherwise
30 template<typename t> bool Set(const char* name, t const& value);
32 // Get child properties
33 UnencryptedProperties GetChild(const char* name);
35 // Remove named object
36 bool Remove(const char* name);
39 std::string const& GetPath() const {return folder_;}
41 UnencryptedProperties();
47 template<typename t> t UnencryptedProperties::Get(const char* name,
50 if (!OK()) return default_value;
51 t value = default_value;
52 std::ifstream(folder_ + "/" + name) >> value;
56 template<typename t> bool UnencryptedProperties::Set(const char* name,
59 if (!OK()) return false;
60 std::ofstream o(folder_ + "/" + name);
65 // Specialized getters/setters for strings
66 template<> std::string UnencryptedProperties::Get(const char* name,
67 std::string default_value);
69 template<> bool UnencryptedProperties::Set(const char* name,
70 std::string const& value);