CrystalSpace

Public API Reference

cstool/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 
00104 class CS_CRYSTALSPACE_EXPORT csApplicationFramework : public csInitializer
00105 {
00106 private:
00118   static csApplicationFramework* m_Ptr;
00119 
00126   static const char* m_FoundationStringName;
00127 
00134   static char* m_ApplicationStringName;
00135   
00140   bool restartFlag;
00141 protected:
00151   csApplicationFramework ();
00152 
00166   static bool Initialize (int argc, char* argv[]);
00167 
00177   static bool Start ();
00178 
00187   static void End ();
00188 public:
00192   virtual ~csApplicationFramework ();
00193 
00201   static void Quit ();
00202 
00203 protected:
00207   static iObjectRegistry* object_reg;
00208   
00223   virtual bool OnInitialize (int argc, char* argv[]) = 0;
00224 
00236   virtual bool Application () = 0;
00237 
00246   virtual void OnExit ();
00247 
00255   virtual void OnCommandLineHelp ();
00256 
00263   static bool SetupConfigManager (iObjectRegistry* object_reg, 
00264     const char* configName)
00265   { 
00266     return csInitializer::SetupConfigManager (object_reg, configName, 
00267       GetApplicationName());
00268   }
00269 public:
00270   // Inline Helper Functions
00274   static iObjectRegistry* GetObjectRegistry () { return object_reg; };
00275 
00284   operator iObjectRegistry* () { return object_reg; }
00285 
00289   bool Open () { return OpenApplication (object_reg); }
00290 
00306   static void SetApplicationName (char *name)
00307   {
00308     m_ApplicationStringName = name;
00309   }
00310 
00317   static const char* GetApplicationName ()
00318   {
00319     return m_ApplicationStringName ? m_ApplicationStringName : 
00320       GetDefaultAppID();
00321   }
00322 
00328   static void Run ()
00329   {
00330     csDefaultRunLoop (object_reg);
00331   }
00332 
00338   void Restart();
00339 private:
00347   static bool ReportLibError (const char* description, ...)
00348   {
00349     va_list args;
00350     va_start (args, description);
00351     csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR,
00352       m_FoundationStringName,
00353       description, args);
00354     va_end (args);
00355     return false;
00356   }
00357 
00358 public:
00366   static bool ReportError (const char* description, ...)
00367   {
00368     va_list args;
00369     va_start (args, description);
00370     csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR,
00371       GetApplicationName(),
00372       description, args);
00373     va_end (args);
00374     return false;
00375   }
00376 
00384   static void ReportWarning (const char* description, ...)
00385   {
00386     va_list args;
00387     va_start (args, description);
00388     csReportV (object_reg, CS_REPORTER_SEVERITY_WARNING,
00389       GetApplicationName(),
00390       description, args);
00391     va_end (args);
00392   }
00393   
00401   static void ReportInfo (const char* description, ...)
00402   {
00403     va_list args;
00404     va_start (args, description);
00405     csReportV (object_reg, CS_REPORTER_SEVERITY_NOTIFY,
00406       GetApplicationName(),
00407       description, args);
00408     va_end (args);
00409   }
00410   
00420   int Main (int argc, char* argv[]);
00421 
00423   bool DoRestart();
00424 };
00425 
00429 template <class T>
00430 class csApplicationRunner
00431 {
00432 public:
00434   static int Run (int argc, char* argv[])
00435   {
00436     int result;
00437     bool again;
00438     do
00439     {
00440       T app;
00441       result = app.Main (argc, argv);
00442       again = app.DoRestart();
00443     }
00444     while (again);
00445     return result;
00446   }
00447 };
00448 
00451 #endif //__CS_CSAPPLICATIONFRAMEWORK_H__

Generated for Crystal Space by doxygen 1.4.7