00001 //---------------------------------------------------------------------------- 00002 /** @file HexProgram.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef HEXPROGRAM_HPP 00007 #define HEXPROGRAM_HPP 00008 00009 #include <map> 00010 #include <string> 00011 00012 #include <boost/utility.hpp> 00013 #include <boost/program_options/options_description.hpp> 00014 00015 #include "Logger.hpp" 00016 00017 _BEGIN_BENZENE_NAMESPACE_ 00018 00019 //---------------------------------------------------------------------------- 00020 00021 /** Program for playing Hex. 00022 Parses command-line arguments and initializes the Hex system. 00023 */ 00024 class HexProgram : private boost::noncopyable 00025 { 00026 public: 00027 00028 /** Creates new HexProgram if non exists, or returns existing 00029 instance. */ 00030 static HexProgram& Get(); 00031 00032 //----------------------------------------------------------------------- 00033 00034 /** Parses cmd-line arguments, starts up Hex system, etc. Does 00035 nothing if called a second time. */ 00036 virtual void Initialize(int argc, char** argv); 00037 00038 /** Shuts down the program and the Hex system. */ 00039 virtual void Shutdown(); 00040 00041 //----------------------------------------------------------------------- 00042 00043 /** Sets the name, version, etc, for this program. */ 00044 void SetInfo(std::string name, std::string version, std::string date); 00045 00046 /** Prints program information and some license details. */ 00047 void PrintStartupMessage(); 00048 00049 /** Returns the name of the program. */ 00050 std::string getName() const; 00051 00052 /** Returns the version string of the program. */ 00053 std::string getVersion() const; 00054 00055 /** Returns the build number of the program. */ 00056 std::string getBuild() const; 00057 00058 /** Returns the build date of the program. */ 00059 std::string getDate() const; 00060 00061 //----------------------------------------------------------------------- 00062 00063 /** Boardsize as parsed from the cmd-line options. */ 00064 int BoardSize() const; 00065 00066 /** Returns the configuration file that should be parsed. This 00067 will be non-empty if the cmd-line option '--config' was parsed 00068 during the call to Initialize(). */ 00069 std::string ConfigFileToExecute() const; 00070 00071 protected: 00072 00073 /** Registers all command-line arguments. */ 00074 virtual void RegisterCmdLineArguments(); 00075 00076 /** Prints all registered cmd-line arguments and their usage. */ 00077 void Usage() const; 00078 00079 //---------------------------------------------------------------------- 00080 00081 std::string m_name; 00082 std::string m_version; 00083 std::string m_date; 00084 00085 std::string m_executable_name; 00086 std::string m_executable_path; 00087 00088 /** Cmd-line options. */ 00089 bool m_initialized; 00090 boost::program_options::options_description m_options_desc; 00091 00092 int m_boardsize; 00093 int m_random_seed; 00094 bool m_use_logfile; 00095 std::string m_logfile_name; 00096 std::string m_logfile_level; 00097 std::string m_config_file; 00098 LogLevel m_stderr_level; 00099 00100 private: 00101 00102 /** Constructor. */ 00103 HexProgram(); 00104 00105 /** Destructor. */ 00106 virtual ~HexProgram(); 00107 00108 void InitLog(); 00109 00110 void InitRandom(); 00111 00112 /** Start the Hex system. */ 00113 void InitializeHexSystem(); 00114 00115 void ProcessCmdLineArguments(int argc, char** argv); 00116 00117 void ShutdownLog(); 00118 00119 //---------------------------------------------------------------------- 00120 }; 00121 00122 inline std::string HexProgram::getName() const 00123 { 00124 return m_name; 00125 } 00126 00127 inline std::string HexProgram::getVersion() const 00128 { 00129 return m_version; 00130 } 00131 00132 inline std::string HexProgram::getDate() const 00133 { 00134 return m_date; 00135 } 00136 00137 inline int HexProgram::BoardSize() const 00138 { 00139 return m_boardsize; 00140 } 00141 00142 inline std::string HexProgram::ConfigFileToExecute() const 00143 { 00144 return m_config_file; 00145 } 00146 00147 //---------------------------------------------------------------------------- 00148 00149 _END_BENZENE_NAMESPACE_ 00150 00151 #endif // HEXPROGRAM_HPP