ALBA
albaDefines.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaDefines
5 Authors: Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaDefines_h
17#define __albaDefines_h
18
23//----------------------------------------------------------------------------
24// Pragmas: disable the "singned/unsigned mismatch" warning
25//----------------------------------------------------------------------------
26#pragma warning( disable : 4018 )
27#pragma warning( disable : 4251 )
28
29
30
31//----------------------------------------------------------------------------
32// Includes: albaConfigure should be first, albaIncludeWX second
33//----------------------------------------------------------------------------
34#include "albaConfigure.h"
35#include "albaIncludeWX.h" // must be after albaConfigure.h
36
37#include <string.h>
38#include <typeinfo>
39#include <iosfwd>
40#include <sstream>
41//----------------------------------------------------------------------------
42// forward declarations :
43//----------------------------------------------------------------------------
44#ifndef MIN
45 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
46#endif
47#ifndef MAX
48 #define MAX( x, y ) ( (x) > (y) ? (x) : (y) )
49#endif
50#ifndef round
51 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
52#endif
53
54//------------------------------------------------------------------------------
55// Typedefs
56//------------------------------------------------------------------------------
57typedef double albaTimeStamp;
58typedef long albaID;
59typedef std::type_info albaTypeID;
60
61//------------------------------------------------------------------------------
62// Constants
63//------------------------------------------------------------------------------
64enum ALBA_EXPORT ALBA_RETURN_VALUES_ID
65{
69 ALBA_USER_RETURN_VALUE
70};
71#define ID_NO_EVENT 0
72/*enum ALBA_NO_EVENT_ID
73{
74 ID_NO_EVENT = 0
75};
76*/
77#define ALBA_STRING_BUFFER_SIZE 2048
78/*enum ALBA_DEFAULT_BUFFER_SIZE
79{
80 ALBA_STRING_BUFFER_SIZE = 2048
81};
82*/
83//------------------------------------------------------------------------------
84// Global Variables
85//------------------------------------------------------------------------------
86
87//------------------------------------------------------------------------------
88// Global Functions
89//------------------------------------------------------------------------------
91ALBA_EXPORT void albaLogMessage(const char *format, ...);
93ALBA_EXPORT void albaWarningMessage(const char *format, ...);
95ALBA_EXPORT void albaErrorMessage(const char *format, ...);
97ALBA_EXPORT void albaMessage(const char *format, ...);
102ALBA_EXPORT bool albaEquals(double x, double y);
103ALBA_EXPORT bool albaFloatEquals(float x, float y);
104
106ALBA_EXPORT double albaRoundToPrecision(double val, unsigned prec);
107
109ALBA_EXPORT bool albaIsLittleEndian(void);
110
112ALBA_EXPORT void albaSleep(int msec);
113
114//------------------------------------------------------------------------------
115// Macros
116//------------------------------------------------------------------------------
117
119#define vtkDEL(a) do{if (a) { a->Delete(); a = NULL; }}while(0)
120
122#define vtkNEW(a) a=a->New()
123
125#define albaNEW(a) do{a=a->New();a->Register(this);}while(0)
126
128#define albaDEL(a) do{if (a) { a->Delete(); a = NULL;}}while(0)
129
131#define cppDEL(a) do{if (a) { delete a; a = NULL;}}while(0)
132
136#define albaAbstractTypeMacro(thisClass,superclass) \
137 public: \
138 \
139 typedef superclass Superclass; \
140 \
141 static const albaTypeID &GetStaticTypeId(); \
142 \
143 virtual const albaTypeID &GetTypeId() const; \
144 \
145 static const char *GetStaticTypeName(); \
146 \
147 virtual const char *GetTypeName() const; \
148 \
149 static bool IsStaticType(const char *type); \
150 \
151 static bool IsStaticType(const albaTypeID &type); \
152 \
153 virtual bool IsA(const char *type) const; \
154 \
155 virtual bool IsA(const albaTypeID &type) const; \
156 \
157 static thisClass* SafeDownCast(albaObject *o);
158
162#define albaTypeMacro(thisClass,superclass) \
163 albaAbstractTypeMacro(thisClass,superclass); \
164 \
165 static albaObject *NewObject(); \
166 \
167 virtual albaObject *NewObjectInstance() const; \
168 \
169 thisClass *NewInstance() const; \
170 \
173 static thisClass *New();
174
178#define albaCxxAbstractTypeMacro(thisClass) \
179 const albaTypeID &thisClass::GetStaticTypeId() {return typeid(thisClass);} \
180 const albaTypeID &thisClass::GetTypeId() const {return typeid(thisClass);} \
181 const char *thisClass::GetStaticTypeName() {return #thisClass;} \
182 const char *thisClass::GetTypeName() const {return #thisClass;} \
183 bool thisClass::IsStaticType(const char *type) \
184 { return ( strcmp(#thisClass,type)==0 ) ? true : Superclass::IsStaticType(type); } \
185 bool thisClass::IsStaticType(const albaTypeID &type) \
186 { return ( type==typeid(thisClass) ? true : Superclass::IsStaticType(type) ); } \
187 bool thisClass::IsA(const char *type) const {return IsStaticType(type);} \
188 bool thisClass::IsA(const albaTypeID &type) const {return IsStaticType(type);} \
189 thisClass* thisClass::SafeDownCast(albaObject *o) \
190 { try { return dynamic_cast<thisClass *>(o); } catch (std::bad_cast) { return NULL;} }
191
195#define albaCxxTypeMacro(thisClass) \
196 albaCxxAbstractTypeMacro(thisClass); \
197 albaObject *thisClass::NewObject() \
198 { \
199 thisClass *obj = new thisClass; \
200 if (obj) obj->m_HeapFlag=true; \
201 return obj; \
202 } \
203 albaObject *thisClass::NewObjectInstance() const \
204 { return NewObject(); } \
205 thisClass *thisClass::New() \
206 { return (thisClass *)NewObject(); } \
207 thisClass *thisClass::NewInstance() const \
208 { return (thisClass *)NewObjectInstance(); }
211#define IsALBAType(type_name) IsA(type_name::GetStaticTypeId())
214#define ALBA_ID_IMP(idname) const albaID idname = mmuIdFactory::GetNextId(#idname);
216#define ALBA_ID_DEC(idname) static const albaID idname;
218#define ALBA_ID_GLOBAL(idname) extern const albaID idname;
219
221// Not Used !!
222//#define ALBA_ID_GROUP(groupname,num) const albaID groupname = mmuIdFactory::AllocIdGroup(#groupname,num);
225#define ALBA_ID_CLASS_DEC(baseClass) static const albaID BaseID;
227#define ALBA_ID_CLASS_IMP(baseClass,num) const albaID baseClass::BaseID = mmuIdFactory::AllocIdGroup("#baseClass::BaseID",num);
228
229#define ALBA_ID_LOC(name,idname) static const albaID name=mmuIdFactory::GetId(#idname);
232#define albaGetEventClassId(event,baseClass) (event->GetID()-baseClass::BaseID)
233#define albaGetEventGroupId(event,baseID) (event->GetID()-baseID)
234#define albaEvalGroupId(baseClass,id) (baseClass::BaseID+id)
237#define albaEventMacro(e) if (m_Listener) {m_Listener->OnEvent(&e);}
240#define ALBA_TEST(a) if (!(a)) \
241{ \
242 std::cerr << "Test failed at line " \
243 << __LINE__ << " : " << #a << std::endl; \
244 return ALBA_ERROR; \
245}
246
250#define albaWarningMacro(x) \
251{ \
252 std::stringstream msg; \
253 msg << "Warning in: " __FILE__ ", line " << __LINE__ << "\n" x \
254 << "\n"; \
255 albaLogMessage(msg.str().c_str());\
256}
257
261#define albaErrorMacro(x) \
262{ \
263 std::stringstream msg; \
264 msg << "Error in: " __FILE__ ", line " << __LINE__ << "\n" x \
265 << "\n"; \
266 albaLogMessage(msg.str().c_str());\
267}
268
271#define albaWarningMessageMacro(x) \
272{ \
273 std::stringstream msg; \
274 msg << x << "\n"; \
275 albaWarningMessage(msg.str().c_str());\
276}
277
280#define albaErrorMessageMacro(x) \
281{ \
282 std::stringstream msg; \
283 msg << x << "\n"; \
284 albaErrorMessage(msg.str().c_str());\
285}
286
289#define albaMessageMacro(x) \
290{ \
291 std::stringstream msg; \
292 msg << x << "\n"; \
293 albaMessage(msg.str().c_str());\
294}
295
300#define ALBA_PRINT_MACRO(format,buffer,size) \
301 va_list argptr; \
302 va_start(argptr, format); \
303 vsnprintf(buffer,(const size_t)size, format, argptr); \
304 va_end(argptr);
305
306#endif
ALBA_OK
Definition: albaDefines.h:66
ALBA_EXPORT void albaErrorMessage(const char *format,...)
open an error dialog and write a message
enum ALBA_EXPORT ALBA_RETURN_VALUES_ID
Definition: albaDefines.h:65
ALBA_EXPORT bool albaFloatEquals(float x, float y)
ALBA_EXPORT void albaWarningMessage(const char *format,...)
open a warning dialog and write a message
ALBA_WAIT
Definition: albaDefines.h:68
ALBA_EXPORT void albaLogMessage(const char *format,...)
write a message in the log area
ALBA_EXPORT void albaMessage(const char *format,...)
open a message dialog and write a message
ALBA_EXPORT void albaSleep(int msec)
wait for given milliseconds
ALBA_EXPORT bool albaIsLittleEndian(void)
return true if it's little endian
ALBA_EXPORT bool albaEquals(double x, double y)
reliable comparison test for floating point numbers.
ALBA_EXPORT double albaRoundToPrecision(double val, unsigned prec)
retrieve the double value with the desired precision
long albaID
type for IDs inside ALBA
Definition: albaDefines.h:58
std::type_info albaTypeID
type for albaObject's class type IDs
Definition: albaDefines.h:59
ALBA_ERROR
Definition: albaDefines.h:67
double albaTimeStamp
type for time varying data timestamps (not for pipelines timestamps!)
Definition: albaDefines.h:57