general.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_GENERAL_H
00026 #define __SYNFIG_GENERAL_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include <ETL/stringf>
00031 #include "string.h"
00032 #include "version.h"
00033 #include <locale.h>
00034 
00035 /* === M A C R O S ========================================================= */
00036 
00037 // Quick hack to keep stuff working until gettext support is added
00038 #ifndef _
00039 #define _(x)        (x)
00040 #define N_(x)       (x)
00041 //#define gettext(x)    (x)
00042 #endif
00043 
00044 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2005 Robert B. Quattlebaum Jr., Adrian Bentley"
00045 
00046 
00047 #ifdef _DEBUG
00048 #ifdef __FUNC__
00049 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
00050 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
00051 #else
00052 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
00053 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
00054 #endif
00055 
00056 #else
00057 #define DEBUGPOINT()
00058 #define DEBUGINFO(x)
00059 #endif
00060 
00061 /* === C L A S S E S & S T R U C T S ======================================= */
00062 
00063 namespace synfig {
00064 
00065 class ChangeLocale {
00066     const String previous;
00067     const int category;
00068 public:
00069     ChangeLocale(int category, const char *locale):
00070         previous(setlocale(category,locale)),category(category)
00071     {
00072     }
00073     ~ChangeLocale() {
00074         setlocale(category,previous.c_str());
00075     }
00076 };
00077 
00081 class ProgressCallback
00082 {
00083 public:
00084 
00085     virtual ~ProgressCallback() { }
00086     virtual bool task(const String &/*task*/) { return true; }
00087     virtual bool error(const String &/*task*/) { return true; }
00088     virtual bool warning(const String &/*task*/) { return true; }
00089     virtual bool amount_complete(int /*current*/, int /*total*/) { return true; }
00090 
00091     virtual bool valid() const { return true; }
00092 };
00093 
00094 typedef ProgressCallback ProgressManager;
00095 
00099 class SuperCallback : public ProgressCallback
00100 {
00101     ProgressCallback *cb;
00102     int start,end,tot;
00103     int w;
00104 public:
00105 
00106     SuperCallback() { cb=NULL; }
00107     SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
00108     {
00109         //make sure we don't "inherit" if our subcallback is invalid
00110         if(!cb || !cb->valid())
00111             cb = NULL;
00112         w=end-start;
00113     }
00114     virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
00115     virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
00116     virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
00117     virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
00118 
00119     virtual bool valid() const { return cb != 0; }
00120 };
00121 
00125 class SoftwareExpired
00126 {
00127 }; // END of class SoftwareExpired
00128 
00129 
00130 #ifdef DEATH_TIME
00131 inline void CHECK_EXPIRE_TIME() { if(time(0)>DEATH_TIME) throw SoftwareExpired(); }
00132 #else
00133 #define CHECK_EXPIRE_TIME() while(0){ }
00134 #endif
00135 
00136 /*
00137 extern bool add_to_module_search_path(const std:string &path);
00138 extern bool add_to_config_search_path(const std:string &path);
00139 */
00140 
00142 extern void shutdown();
00143 
00145 
00146 extern void error(const char *format,...);
00147 extern void error(const String &str);
00148 
00150 
00151 extern void warning(const char *format,...);
00152 extern void warning(const String &str);
00153 
00155 
00156 extern void info(const char *format,...);
00157 extern void info(const String &str);
00158 
00159 }; // END of namespace synfig
00160 
00161 /* === E N D =============================================================== */
00162 
00163 #endif

Generated on Wed Dec 12 03:11:41 2007 for synfig by  doxygen 1.5.4