Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_04 / 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 #include <locale.h>
34
35 /* === M A C R O S ========================================================= */
36
37 // Quick hack to keep stuff working until gettext support is added
38 #ifndef _
39 #define _(x)            (x)
40 #define N_(x)           (x)
41 //#define gettext(x)    (x)
42 #endif
43
44 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2005 Robert B. Quattlebaum Jr., Adrian Bentley"
45
46
47 #ifdef _DEBUG
48 #ifdef __FUNC__
49 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
50 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
51 #else
52 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
53 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
54 #endif
55
56 #else
57 #define DEBUGPOINT()
58 #define DEBUGINFO(x)
59 #endif
60
61 /* === C L A S S E S & S T R U C T S ======================================= */
62
63 namespace synfig {
64
65 class ChangeLocale {
66     const char *previous;
67     int category;
68 public:
69     ChangeLocale(int category, const char *locale):
70         previous(setlocale(category,NULL)),category(category)
71     {
72             setlocale(category,locale);
73     }
74     ~ChangeLocale() {
75         setlocale(category,previous);
76     }
77 };
78
79 /*!     \class ProgressCallback
80 **      \todo writeme
81 */
82 class ProgressCallback
83 {
84 public:
85
86         virtual ~ProgressCallback() { }
87         virtual bool task(const String &task) { return true; }
88         virtual bool error(const String &task) { return true; }
89         virtual bool warning(const String &task) { return true; }
90         virtual bool amount_complete(int current, int total) { return true; }
91         
92         virtual bool valid() const { return true; }
93 };
94
95 typedef ProgressCallback ProgressManager;
96
97 /*!     \class SuperCallback
98 **      \todo writeme
99 */
100 class SuperCallback : public ProgressCallback
101 {
102         ProgressCallback *cb;
103         int start,end,tot;
104         int w;
105 public:
106
107         SuperCallback() { cb=NULL; }
108         SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
109         {
110                 //make sure we don't "inherit" if our subcallback is invalid
111                 if(!cb || !cb->valid())
112                         cb = NULL;
113                 w=end-start;
114         }
115         virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
116         virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
117         virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
118         virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
119         
120         virtual bool valid() const { return cb != 0; }
121 };
122
123 /*! \class SoftwareExpired
124 **      \brief This class is thrown when the software timeout has been reached.
125 */
126 class SoftwareExpired
127 {
128 }; // END of class SoftwareExpired
129
130
131 #ifdef DEATH_TIME
132 inline void CHECK_EXPIRE_TIME() { if(time(0)>DEATH_TIME) throw SoftwareExpired(); }
133 #else
134 #define CHECK_EXPIRE_TIME() while(0){ }
135 #endif
136
137 /*
138 extern bool add_to_module_search_path(const std:string &path);
139 extern bool add_to_config_search_path(const std:string &path);
140 */
141
142 //! Shutdown the synfig environment
143 extern void shutdown();
144
145 //! Reports an error
146 /*! Call this when an error occurs, describing what happened */
147 extern void error(const char *format,...);
148 extern void error(const String &str);
149
150 //! Reports a warning
151 /*! Call this when something questionable occurs, describing what happened */
152 extern void warning(const char *format,...);
153 extern void warning(const String &str);
154
155 //! Reports some information
156 /*! Call this to report various information. Please be sparse... */
157 extern void info(const char *format,...);
158 extern void info(const String &str);
159
160 }; // END of namespace synfig
161
162 /* === E N D =============================================================== */
163
164 #endif