Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_03 / synfig-core / src / synfig / general.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file general.h
3 **      \brief General macros, classes, and prodecure declarations
4 **
5 **      $Id: general.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_GENERAL_H
26 #define __SYNFIG_GENERAL_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <ETL/stringf>
31 #include "string.h"
32 #include "version.h"
33
34 /* === M A C R O S ========================================================= */
35
36 // Quick hack to keep stuff working until gettext support is added
37 #ifndef _
38 #define _(x)            (x)
39 #define N_(x)           (x)
40 //#define gettext(x)    (x)
41 #endif
42
43 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2004 Voria Software, LLC"
44
45
46 #ifdef _DEBUG
47 #ifdef __FUNC__
48 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
49 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
50 #else
51 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
52 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
53 #endif
54
55 #else
56 #define DEBUGPOINT()
57 #define DEBUGINFO(x)
58 #endif
59
60 /* === C L A S S E S & S T R U C T S ======================================= */
61
62 namespace synfig {
63
64 /*!     \class ProgressCallback
65 **      \todo writeme
66 */
67 class ProgressCallback
68 {
69 public:
70
71         virtual ~ProgressCallback() { }
72         virtual bool task(const String &task) { return true; }
73         virtual bool error(const String &task) { return true; }
74         virtual bool warning(const String &task) { return true; }
75         virtual bool amount_complete(int current, int total) { return true; }
76         
77         virtual bool valid() const { return true; }
78 };
79
80 typedef ProgressCallback ProgressManager;
81
82 /*!     \class SuperCallback
83 **      \todo writeme
84 */
85 class SuperCallback : public ProgressCallback
86 {
87         ProgressCallback *cb;
88         int start,end,tot;
89         int w;
90 public:
91
92         SuperCallback() { cb=NULL; }
93         SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
94         {
95                 //make sure we don't "inherit" if our subcallback is invalid
96                 if(!cb || !cb->valid())
97                         cb = NULL;
98                 w=end-start;
99         }
100         virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
101         virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
102         virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
103         virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
104         
105         virtual bool valid() const { return cb != 0; }
106 };
107
108 /*! \class SoftwareExpired
109 **      \brief This class is thrown when the software timeout has been reached.
110 */
111 class SoftwareExpired
112 {
113 }; // END of class SoftwareExpired
114
115
116 #ifdef DEATH_TIME
117 inline void CHECK_EXPIRE_TIME() { if(time(0)>DEATH_TIME) throw SoftwareExpired(); }
118 #else
119 #define CHECK_EXPIRE_TIME() while(0){ }
120 #endif
121
122 /*
123 extern bool add_to_module_search_path(const std:string &path);
124 extern bool add_to_config_search_path(const std:string &path);
125 */
126
127 //! Shutdown the synfig environment
128 extern void shutdown();
129
130 //! Reports an error
131 /*! Call this when an error occurs, describing what happened */
132 extern void error(const char *format,...);
133 extern void error(const String &str);
134
135 //! Reports a warning
136 /*! Call this when something questionable occurs, describing what happened */
137 extern void warning(const char *format,...);
138 extern void warning(const String &str);
139
140 //! Reports some information
141 /*! Call this to report various information. Please be sparse... */
142 extern void info(const char *format,...);
143 extern void info(const String &str);
144
145 }; // END of namespace synfig
146
147 /* === E N D =============================================================== */
148
149 #endif