Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
csapplicationframework.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Odes B. Boatwright. 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSAPPLICATIONFRAMEWORK_H__ 00020 #define __CS_CSAPPLICATIONFRAMEWORK_H__ 00021 00030 #include "csextern.h" 00031 00032 #include "cstool/initapp.h" 00033 #include "ivaria/reporter.h" 00034 00105 class CS_CRYSTALSPACE_EXPORT csApplicationFramework : public csInitializer 00106 { 00107 private: 00119 static csApplicationFramework* m_Ptr; 00120 00127 static const char* m_FoundationStringName; 00128 00135 static char* m_ApplicationStringName; 00136 00141 bool restartFlag; 00142 protected: 00152 csApplicationFramework (); 00153 00167 static bool Initialize (int argc, char* argv[]); 00168 00178 static bool Start (); 00179 00188 static void End (); 00189 public: 00193 virtual ~csApplicationFramework (); 00194 00202 static void Quit (); 00203 00204 protected: 00208 static iObjectRegistry* object_reg; 00209 00224 virtual bool OnInitialize (int argc, char* argv[]) = 0; 00225 00237 virtual bool Application () = 0; 00238 00247 virtual void OnExit (); 00248 public: 00249 // Inline Helper Functions 00253 static iObjectRegistry* GetObjectRegistry () { return object_reg; }; 00254 00263 operator iObjectRegistry* () { return object_reg; } 00264 00268 bool Open () { return OpenApplication (object_reg); } 00269 00285 static void SetApplicationName (char *name) 00286 { 00287 m_ApplicationStringName = name; 00288 } 00289 00296 static const char* GetApplicationName () 00297 { 00298 return m_ApplicationStringName; 00299 } 00300 00306 static void Run () 00307 { 00308 csDefaultRunLoop (object_reg); 00309 } 00310 00316 void Restart(); 00317 private: 00325 static bool ReportLibError (const char* description, ...) 00326 { 00327 va_list args; 00328 va_start (args, description); 00329 csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR, 00330 m_FoundationStringName, 00331 description, args); 00332 va_end (args); 00333 return false; 00334 } 00335 00336 public: 00344 static bool ReportError (const char* description, ...) 00345 { 00346 va_list args; 00347 va_start (args, description); 00348 csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR, 00349 m_ApplicationStringName, 00350 description, args); 00351 va_end (args); 00352 return false; 00353 } 00354 00362 static void ReportWarning (const char* description, ...) 00363 { 00364 va_list args; 00365 va_start (args, description); 00366 csReportV (object_reg, CS_REPORTER_SEVERITY_WARNING, 00367 m_ApplicationStringName, 00368 description, args); 00369 va_end (args); 00370 } 00371 00379 static void ReportInfo (const char* description, ...) 00380 { 00381 va_list args; 00382 va_start (args, description); 00383 csReportV (object_reg, CS_REPORTER_SEVERITY_NOTIFY, 00384 m_ApplicationStringName, 00385 description, args); 00386 va_end (args); 00387 } 00388 00398 int Main (int argc, char* argv[]); 00399 00401 bool DoRestart(); 00402 }; 00403 00407 template <class T> 00408 class csApplicationRunner 00409 { 00410 public: 00412 static int Run (int argc, char* argv[]) 00413 { 00414 int result; 00415 bool again; 00416 do 00417 { 00418 T app; 00419 result = app.Main (argc, argv); 00420 again = app.DoRestart(); 00421 } 00422 while (again); 00423 return result; 00424 } 00425 }; 00426 00429 #endif //__CS_CSAPPLICATIONFRAMEWORK_H__
Generated for Crystal Space by doxygen 1.4.4