#pragma once #ifndef DConsoleContext_h__ #define DConsoleContext_h__ #include #include #include "Providers/DDataProvider.h" #include "DConsole.h" #include "DConsoleUtilBase.h" using namespace std; namespace ccdb { class DConsoleContext { public: /** @brief Singleton instance of console context * * @returns DConsoleContext* instance */ static DConsoleContext* Instance(); /** @brief Every console util should call this function to register its command * * How to do alias on command? * Just do second RegisterConsoleUtil call with different command * * How to find util by name than? * By using @see FindUtil * * @param string command * @param DConsoleUtilBase * util * @returns void */ void RegisterConsoleUtil(string command, DConsoleUtilBase *util); /** @brief Do the process of parameters * * @param int argc * @param char * argv[] * @returns like in main() */ int Process(int argc, char* argv[], int startArgc = 2); /** @brief Do the process of command string * * @param string command * @returns like in main */ int Process(string command); /** @brief Starts interactive session to work with user commands * * @returns int like in main() */ int ProcessInteractive(int argc, char* argv[], int startArgc = 2); /** @brief Gets current working directory * * @returns working directory */ string GetWorkDir() const { return mWorkDir; } /** @brief Sets current working directory * * it doesnt check the directory existence or something like this * it just set string that holds current directory structure data * * @param string val */ void SetWorkDir(string val) { mWorkDir = val; } /** @brief Gets current provider. * * In current realization it is DMySQLProvider * @return DDataProvider * */ DDataProvider * GetProvider() const { return mProvider; } /** @brief Finds util by its command * * @return DDataProvider * if found or NULL if not found */ DConsoleUtilBase * FindUtil(string command); /** @brief Get all utils * * @return DDataProvider * if found or NULL if not found */ const map& GetUtils(); /** @brief returns console to write read operation * * @return DConsole * */ DConsole * GetConsole() const; virtual ~DConsoleContext(void); ///Destructor protected: private: DConsoleContext(); // Private so that it can not be called DConsoleContext(DConsoleContext const&){}; // copy constructor is private DConsoleContext& operator=(DConsoleContext const&); // assignment operator is private map mUtils; // Map of utils by command string mWorkDir; // Current working dir DDataProvider *mProvider; //MySQL (probably) data provider DConsole *mConsole; //Console that used for output static DConsoleContext* mInstance; //Main and only singleton instance } ; } #endif // DConsoleContext_h__