#pragma once ///////////////////////////////////////////////////////////////////// // SkeletonPlus.h - Gang of Four Singleton with reference counting // // Ver 1.1 // // Jim Fawcett, CSE776 - Design Patterns, Fall 2017 // ///////////////////////////////////////////////////////////////////// /* * Ver 1.1 : 13 Sep 2017 * - fixes bug discovered by Lakshmi Chilukuri by setting * pInstance to nullptr after deleting instance in Release() * Ver 1.0 : 11 Sep 2017 * - first release. */ ///////////////////////////////////////////////////////////////////// // Singleton class /* * - Guarantees, at most, one instance of Singleton will exist * in a single-threaded environment. * - Does not guarantee only one instance of singletonData! */ #include class Singleton { public: static Singleton* Instance(); void SingletonOperation(const std::string& data); std::string GetSingletonData(); void ReleaseInstance(); private: Singleton(); ~Singleton(); static Singleton* pUniqueInstance; std::string singletonData; static size_t refCount; }; Singleton* Singleton::pUniqueInstance = nullptr; size_t Singleton::refCount = 0;