This library provides a class that enables the storing, updating, and managing of key-value pairs. The DataManager class efficiently stores data using linked lists, has O[N] insertion and retrieval complexity, and a memory footprint of O[N]. Note that this implementation is not equivalent to C++ maps or Python dictionaries. While developed for Arduino and ESP8266 applications, it works with plain C++ as well. However, there are more efficient implementation (e.g. std::map) available.
The DataManager class is a templated class that can store arbitrary data types (such as int, float, or String) or user-defined structures.
Based on Ivan Seidel's LinkedList implementation (see https://github.com/ivanseidel/LinkedList).
- Download the latest release from GitHub.
- Unzip and modify the Folder name to "data_manager".
- Paste the modified folder on your Library folder (On your
Libraries
folder inside Sketchbooks or Arduino software). - Reopen the Arduino software.
Alternatively, just clone the repository from here
// Instantiate a DataManager that will hold 'integer' values.
DataManager<int> myDataManager = DataManager<int>();
DataManager<int> myDataManager;
// Instantiate a pointer to a DataManager.
DataManager<int> *myDataManager = new DataManager<int>();
// If you want a DataManager with any other type such as 'MyClass'.
DataManager<MyClass> *myDataManager = new DataManager<MyClass>();
// To add a new element or update an existing one.
myDataManager.update("variable_name", value);
// To check whether a named variable already exists.
bool exists = myDataManager.exists("variable_name");
// To check whether any new data is available.
bool is_new = myDataManager.has_new_data();
// To get the size of a linked list, make use of the size() method
int data_size = myDataManager.get_size();
// To add an new object named "variable_name".
myDataManager.update("variable_name", myObject);
// To get a pointer to the container holding the named variable by name.
DataContainer<T>* myObject = myDataManager.get_entry_by_name("variable_name");
// To get the value of a named variable.
int my_value = myDataManager.get_value("variable_name");
// To set the value of a named variable.
bool modified = myDataManager.set_value("variable_name", 10);
// To remove a named variable.
bool removed = myDataManager.remove_entry_by_name("variable_name");
1.0 (2019-07-08)
: Original release