Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: util/dict.h
- Revision:
- 101:dbcd3bc51758
- Parent:
- 99:e369fc75c000
- Child:
- 103:ede6611e064e
--- a/util/dict.h Thu May 07 13:56:19 2015 +0000 +++ b/util/dict.h Fri May 08 12:19:57 2015 +0000 @@ -1,6 +1,7 @@ #ifndef DICH_H #define DICH_H #include <string.h> +#include <stdio.h> #define MAX_KEY_LEN 50 #define MAX_VALUE_LEN 50 #define MAX_ITEM_SIZE 3 @@ -14,6 +15,19 @@ }; Dict(): count(0) {} + + Dict(const Dict& d): count(0) { + *this = d; + } + + Dict& operator= (const Dict& d) { + clear(); + for (size_t i = 0; i < d.size(); ++i) { + const Item* p = d.at(i); + set(p->key, p->value); + } + return *this; + } const Item* at(const size_t i) const { if (i < count) return &items[i]; @@ -42,19 +56,20 @@ return NULL; } + size_t dump(char* buf) const { + size_t l = 0; + for (size_t i = 0; i < count; ++i) { + l += sprintf(buf+l, "%s=%s;", items[i].key, items[i].value); + } + buf[l] = 0; + return l; + } + size_t maxSize() const { return MAX_ITEM_SIZE; } size_t size() const { return count; } bool empty() const { return count==0; } bool full() const { return count == MAX_ITEM_SIZE; } void clear() { count = 0; } - size_t dump(char* buf) { - size_t l = 0; - for (size_t i = 0; i < count; ++i) { - l + sprintf(buf+l, "%s=%s;", items[i].key, items[i].value); - } - buf[l] = 0; - return l; - } virtual ~Dict() {} protected: size_t find(const char* k) const { @@ -69,4 +84,4 @@ size_t count; }; -#endif /* DICH_H */ +#endif /* DICH_H */ \ No newline at end of file