#pragma once ///////////////////////////////////////////////////////////////////// // NoSqlDb.h - key/value pair in-memory database // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2017 // ///////////////////////////////////////////////////////////////////// /* * If you elect to use this code, you will need to add * - manual information * - maintenance information * - query mechanism * - persistance mechanism * - TestExecutive that demonstrates the requirements you meet */ /* * - fixed bug in NoSqlDb::count() by replacing * unordered_map::count() with * unordered_map::size(); */ #include #include #include #include #include #include #include "../CppProperties/CppProperties.h" ///////////////////////////////////////////////////////////////////// // Element class represents a data record in our NoSql database // - in our NoSql database that is just the value in a key/value pair // - it needs to store child data, something for you to implement // template class Element { public: using Name = std::string; using Category = std::string; using TimeDate = std::string; Property name; // metadata Property category; // metadata Property timeDate; // metadata Property data; // data std::string show(); }; template std::string Element::show() { // show children when you've implemented them std::ostringstream out; out.setf(std::ios::adjustfield, std::ios::left); out << "\n " << std::setw(8) << "name" << " : " << name; out << "\n " << std::setw(8) << "category" << " : " << category; out << "\n " << std::setw(8) << "timeDate" << " : " << timeDate; out << "\n " << std::setw(8) << "data" << " : " << data; out << "\n"; return out.str(); } ///////////////////////////////////////////////////////////////////// // NoSqlDb class is a key/value pair in-memory database // - stores and retrieves elements // - you will need to add query capability // That should probably be another class that uses NoSqlDb // template class NoSqlDb { public: using Key = std::string; using Keys = std::vector; Keys keys(); bool save(Key key, Element elem); Element value(Key key); size_t count(); private: using Item = std::pair>; std::unordered_map> store; }; template typename NoSqlDb::Keys NoSqlDb::keys() { Keys keys; for (Item item : store) { keys.push_back(item.first); } return keys; } template bool NoSqlDb::save(Key key, Element elem) { if(store.find(key) != store.end()) return false; store[key] = elem; return true; } template Element NoSqlDb::value(Key key) { if (store.find(key) != store.end()) return store[key]; return Element(); } template size_t NoSqlDb::count() { return store.size(); } ///////////////////////////////////////////////////////////////////// // Persistance class // - you will need to implement that using the XmlDocument class // from Handouts/Repository