moreupdates
[synfig.git] / synfig-core / trunk / 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_GENERAL_H
25 #define __SYNFIG_GENERAL_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include <ETL/stringf>
30 #include "string.h"
31 #include "version.h"
32
33 /* === M A C R O S ========================================================= */
34
35 // Quick hack to keep stuff working until gettext support is added
36 #ifndef _
37 #define _(x)            (x)
38 #define N_(x)           (x)
39 //#define gettext(x)    (x)
40 #endif
41
42 #define SYNFIG_COPYRIGHT "Copyright (c) 2001-2004 Voria Software, LLC"
43
44
45 #ifdef _DEBUG
46 #ifdef __FUNC__
47 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d DEBUGPOINT",__LINE__))
48 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":"__FUNC__":%d:DEBUGINFO:",__LINE__)+x)
49 #else
50 #define DEBUGPOINT()    synfig::warning(etl::strprintf(__FILE__":%d DEBUGPOINT",__LINE__))
51 #define DEBUGINFO(x)    synfig::warning(etl::strprintf(__FILE__":%d:DEBUGINFO:",__LINE__)+x)
52 #endif
53
54 #else
55 #define DEBUGPOINT()
56 #define DEBUGINFO(x)
57 #endif
58
59 /* === C L A S S E S & S T R U C T S ======================================= */
60
61 namespace synfig {
62
63 /*!     \class ProgressCallback
64 **      \todo writeme
65 */
66 class ProgressCallback
67 {
68 public:
69
70         virtual ~ProgressCallback() { }
71         virtual bool task(const String &task) { return true; }
72         virtual bool error(const String &task) { return true; }
73         virtual bool warning(const String &task) { return true; }
74         virtual bool amount_complete(int current, int total) { return true; }
75         
76         virtual bool valid() const { return true; }
77 };
78
79 typedef ProgressCallback ProgressManager;
80
81 /*!     \class SuperCallback
82 **      \todo writeme
83 */
84 class SuperCallback : public ProgressCallback
85 {
86         ProgressCallback *cb;
87         int start,end,tot;
88         int w;
89 public:
90
91         SuperCallback() { cb=NULL; }
92         SuperCallback(ProgressCallback *cb,int start, int end, int total):cb(cb),start(start),end(end),tot(total)
93         {
94                 //make sure we don't "inherit" if our subcallback is invalid
95                 if(!cb || !cb->valid())
96                         cb = NULL;
97                 w=end-start;
98         }
99         virtual bool task(const String &task) { if(cb)return cb->task(task); return true; }
100         virtual bool error(const String &task) { if(cb)return cb->error(task); return true; }
101         virtual bool warning(const String &task) { if(cb)return cb->warning(task); return true; }
102         virtual bool amount_complete(int cur, int total) { if(cb)return cb->amount_complete(start+cur*w/total,tot); return true; }
103         
104         virtual bool valid() const { return cb != 0; }
105 };
106
107 /*! \class SoftwareExpired
108 **      \brief This class is thrown when the software timeout has been reached.
109 */
110 class SoftwareExpired
111 {
112 }; // END of class SoftwareExpired
113
114
115 #ifdef DEATH_TIME
116 inline void CHECK_EXPIRE_TIME() { if(time(0)>DEATH_TIME) throw SoftwareExpired(); }
117 #else
118 #define CHECK_EXPIRE_TIME() while(0){ }
119 #endif
120
121 /*
122 extern bool add_to_module_search_path(const std:string &path);
123 extern bool add_to_config_search_path(const std:string &path);
124 */
125
126 //! Shutdown the synfig environment
127 extern void shutdown();
128
129 //! Reports an error
130 /*! Call this when an error occurs, describing what happened */
131 extern void error(const char *format,...);
132 extern void error(const String &str);
133
134 //! Reports a warning
135 /*! Call this when something questionable occurs, describing what happened */
136 extern void warning(const char *format,...);
137 extern void warning(const String &str);
138
139 //! Reports some information
140 /*! Call this to report various information. Please be sparse... */
141 extern void info(const char *format,...);
142 extern void info(const String &str);
143
144 }; // END of namespace synfig
145
146 /* === E N D =============================================================== */
147
148 #endif