State Management - ktm/amv GitHub Wiki
State management
The plan is to have a single collection of name/value pairs, shared among all of the executing processes.
This is a simple idea and the execution was simple, too. The name/value pairs are stored in an unsorted vector. The vector is wrapped by a class and provided as a singleton. Access to the data is protected by a single mutex.
The choice of an unsorted vector is supported by this Scott Meyers' blog post.
The singleton is of the C++11 variety, as described at the bottom of this article.
I do not know how to handle the case where a read was requested for a value which does not exist. I was returning nullptr, but this broke something. Returning an empty string literal is a hack-around. Hopefully I can get some guidance from the Core C++ Guidelines.
string read(string name) {
std::lock_guard<std::mutex> data_lock(data_mutex);
NameValuePairPtr npp = find(name);
if (npp != nullptr) {
return npp->second;
}
return "";
}