summaryrefslogtreecommitdiff
path: root/node/Dictionary.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-01-06 17:16:54 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-01-06 17:16:54 -0800
commit60fb28a90a5e7b01e58b2a93351658195651e8eb (patch)
tree1ec74eb3ea942c3f0272363c50dffc3a07561bfe /node/Dictionary.hpp
parenta369c690910d014ca79b55d07603af45343b37f5 (diff)
downloadinfinitytier-60fb28a90a5e7b01e58b2a93351658195651e8eb.tar.gz
infinitytier-60fb28a90a5e7b01e58b2a93351658195651e8eb.zip
Cleanup, new C++ netconf code is almost ready to test!
Diffstat (limited to 'node/Dictionary.hpp')
-rw-r--r--node/Dictionary.hpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/node/Dictionary.hpp b/node/Dictionary.hpp
index c0bc13a2..a104ea1a 100644
--- a/node/Dictionary.hpp
+++ b/node/Dictionary.hpp
@@ -35,6 +35,7 @@
#include <stdexcept>
#include "Constants.hpp"
+#include "Utils.hpp"
// Three fields are added/updated by sign()
#define ZT_DICTIONARY_SIGNATURE "~!ed25519"
@@ -108,6 +109,128 @@ public:
}
/**
+ * @param key Key to get
+ * @param dfl Default boolean result if key not found or empty (default: false)
+ * @return Boolean value of key
+ */
+ inline bool getBoolean(const std::string &key,bool dfl = false) const
+ {
+ const_iterator e(find(key));
+ if (e == end())
+ return dfl;
+ if (e->second.length() < 1)
+ return dfl;
+ switch(e->second[0]) {
+ case '1':
+ case 't':
+ case 'T':
+ case 'y':
+ case 'Y':
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param key Key to get
+ * @param dfl Default value if not present (default: 0)
+ * @return Value converted to unsigned 64-bit int or 0 if not found
+ */
+ inline uint64_t getUInt(const std::string &key,uint64_t dfl = 0) const
+ {
+ const_iterator e(find(key));
+ if (e == end())
+ return dfl;
+ return Utils::strToU64(e->second.c_str());
+ }
+
+ /**
+ * @param key Key to get
+ * @param dfl Default value if not present (default: 0)
+ * @return Value converted to unsigned 64-bit int or 0 if not found
+ */
+ inline uint64_t getHexUInt(const std::string &key,uint64_t dfl = 0) const
+ {
+ const_iterator e(find(key));
+ if (e == end())
+ return dfl;
+ return Utils::hexStrToU64(e->second.c_str());
+ }
+
+ /**
+ * @param key Key to get
+ * @param dfl Default value if not present (default: 0)
+ * @return Value converted to signed 64-bit int or 0 if not found
+ */
+ inline int64_t getInt(const std::string &key,int64_t dfl = 0) const
+ {
+ const_iterator e(find(key));
+ if (e == end())
+ return dfl;
+ return Utils::strTo64(e->second.c_str());
+ }
+
+ /**
+ * @param key Key to set
+ * @param value String value
+ */
+ inline void set(const std::string &key,const char *value)
+ {
+ (*this)[key] = value;
+ }
+
+ /**
+ * @param key Key to set
+ * @param value String value
+ */
+ inline void set(const std::string &key,const std::string &value)
+ {
+ (*this)[key] = value;
+ }
+
+ /**
+ * @param key Key to set
+ * @param value Boolean value
+ */
+ inline void set(const std::string &key,bool value)
+ {
+ (*this)[key] = ((value) ? "1" : "0");
+ }
+
+ /**
+ * @param key Key to set
+ * @param value Integer value
+ */
+ inline void set(const std::string &key,uint64_t value)
+ {
+ char tmp[24];
+ Utils::snprintf(tmp,sizeof(tmp),"%llu",(unsigned long long)value);
+ (*this)[key] = tmp;
+ }
+
+ /**
+ * @param key Key to set
+ * @param value Integer value
+ */
+ inline void set(const std::string &key,int64_t value)
+ {
+ char tmp[24];
+ Utils::snprintf(tmp,sizeof(tmp),"%lld",(long long)value);
+ (*this)[key] = tmp;
+ }
+
+ /**
+ * @param key Key to set
+ * @param value Integer value
+ */
+ inline void setHex(const std::string &key,uint64_t value)
+ {
+ char tmp[24];
+ Utils::snprintf(tmp,sizeof(tmp),"%llx",(unsigned long long)value);
+ (*this)[key] = tmp;
+ }
+
+ /**
* @param key Key to check
* @return True if dictionary contains key
*/