///////////////////////////////////////////////////////////////////// // Repository.CPP - application of Singleton Pattern // // // // Jim Fawcett, CSE776 - Design Patterns, Fall 2017 // ///////////////////////////////////////////////////////////////////// #include "Repository.h" #include "../Utilities/Utilities.h" #include "../Locks/Locks.h" #include #include #include using namespace Singleton; using namespace Utilities; using namespace SingletonRepository; using namespace Locks; using Repo = Repository; void showList(Repo* pRep, const std::string& msg = "") { if (pRep) { std::list list = pRep->getList(); std::cout << "\n " << msg; for (std::string item : list) { std::cout << " " << item; } } } int main() { Utilities::title<'='>("Testing Derived Singleton: Repository"); Singleton::log.set(&std::cout); Singleton::log.logging = true; Repo* pRep1 = Repo::Instance(); if (!pRep1) { std::cout << "\n couldn't create instance of repository"; putLine(2); return 1; } pRep1->add("123").add("456"); showList(pRep1, " pRep1:"); Repo* pRep2 = Repo::Instance(); pRep2->add("abc").add("def").add("ghi"); showList(pRep2, " pRep2:"); showList(pRep1, " pRep1:"); std::list newList{ "one", "two", "three" }; pRep1->setList(newList); showList(pRep1, " pRep1"); showList(pRep2, " pRep2"); pRep1->Release(); pRep2->Release(); putLine(2); return 0; }