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, Gianluigi Crimi
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 <mutex>
35#include <string.h>
36#include <typeinfo>
37#include <iosfwd>
38#include <sstream>
39
40#include "albaConfigure.h"
41#include "albaIncludeWX.h" // must be after albaConfigure.h
42
43
44//----------------------------------------------------------------------------
45// forward declarations :
46//----------------------------------------------------------------------------
47#ifndef MIN
48 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
49#endif
50#ifndef MAX
51 #define MAX( x, y ) ( (x) > (y) ? (x) : (y) )
52#endif
53#ifndef round
54 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
55#endif
56
57//------------------------------------------------------------------------------
58// Typedefs
59//------------------------------------------------------------------------------
60typedef double albaTimeStamp;
61typedef long albaID;
62typedef std::type_info albaTypeID;
63
64//------------------------------------------------------------------------------
65// Constants
66//------------------------------------------------------------------------------
67enum ALBA_EXPORT ALBA_RETURN_VALUES_ID
68{
72 ALBA_USER_RETURN_VALUE
73};
74#define ID_NO_EVENT 0
75/*enum ALBA_NO_EVENT_ID
76{
77 ID_NO_EVENT = 0
78};
79*/
80#define ALBA_STRING_BUFFER_SIZE 2048
81/*enum ALBA_DEFAULT_BUFFER_SIZE
82{
83 ALBA_STRING_BUFFER_SIZE = 2048
84};
85*/
86//------------------------------------------------------------------------------
87// Global Variables
88//------------------------------------------------------------------------------
89
90//------------------------------------------------------------------------------
91// Global Functions
92//------------------------------------------------------------------------------
94ALBA_EXPORT void albaLogMessage(const char *format, ...);
96ALBA_EXPORT void albaWarningMessage(const char *format, ...);
98ALBA_EXPORT void albaErrorMessage(const char *format, ...);
100ALBA_EXPORT void albaMessage(const char *format, ...);
105ALBA_EXPORT bool albaEquals(double x, double y);
106ALBA_EXPORT bool albaFloatEquals(float x, float y);
107
109ALBA_EXPORT double albaRoundToPrecision(double val, unsigned prec);
110
112ALBA_EXPORT bool albaIsLittleEndian(void);
113
115ALBA_EXPORT void albaSleep(int msec);
116
117//------------------------------------------------------------------------------
118// Macros
119//------------------------------------------------------------------------------
120
122#define vtkDEL(a) do{if (a) { a->Delete(); a = NULL; }}while(0)
123
125#define vtkNEW(a) a=a->New()
126
128#define albaNEW(a) do{a=a->New();a->Register(this);}while(0)
129
131#define albaDEL(a) do{if (a) { a->Delete(); a = NULL;}}while(0)
132
134#define cppDEL(a) do{if (a) { delete a; a = NULL;}}while(0)
135
139#define albaAbstractTypeMacro(thisClass,superclass) \
140 public: \
141 \
142 typedef superclass Superclass; \
143 \
144 static const albaTypeID &GetStaticTypeId(); \
145 \
146 virtual const albaTypeID &GetTypeId() const; \
147 \
148 static const char *GetStaticTypeName(); \
149 \
150 virtual const char *GetTypeName() const; \
151 \
152 static bool IsStaticType(const char *type); \
153 \
154 static bool IsStaticType(const albaTypeID &type); \
155 \
156 virtual bool IsA(const char *type) const; \
157 \
158 virtual bool IsA(const albaTypeID &type) const; \
159 \
160 static thisClass* SafeDownCast(albaObject *o);
161
165#define albaTypeMacro(thisClass,superclass) \
166 albaAbstractTypeMacro(thisClass,superclass); \
167 \
168 static albaObject *NewObject(); \
169 \
170 virtual albaObject *NewObjectInstance() const; \
171 \
172 thisClass *NewInstance() const; \
173 \
176 static thisClass *New();
177
181#define albaCxxAbstractTypeMacro(thisClass) \
182 const albaTypeID &thisClass::GetStaticTypeId() {return typeid(thisClass);} \
183 const albaTypeID &thisClass::GetTypeId() const {return typeid(thisClass);} \
184 const char *thisClass::GetStaticTypeName() {return #thisClass;} \
185 const char *thisClass::GetTypeName() const {return #thisClass;} \
186 bool thisClass::IsStaticType(const char *type) \
187 { return ( strcmp(#thisClass,type)==0 ) ? true : Superclass::IsStaticType(type); } \
188 bool thisClass::IsStaticType(const albaTypeID &type) \
189 { return ( type==typeid(thisClass) ? true : Superclass::IsStaticType(type) ); } \
190 bool thisClass::IsA(const char *type) const {return IsStaticType(type);} \
191 bool thisClass::IsA(const albaTypeID &type) const {return IsStaticType(type);} \
192 thisClass* thisClass::SafeDownCast(albaObject *o) \
193 { try { return dynamic_cast<thisClass *>(o); } catch (std::bad_cast) { return NULL;} }
194
198#define albaCxxTypeMacro(thisClass) \
199 albaCxxAbstractTypeMacro(thisClass); \
200 albaObject *thisClass::NewObject() \
201 { \
202 thisClass *obj = new thisClass; \
203 if (obj) obj->m_HeapFlag=true; \
204 return obj; \
205 } \
206 albaObject *thisClass::NewObjectInstance() const \
207 { return NewObject(); } \
208 thisClass *thisClass::New() \
209 { return (thisClass *)NewObject(); } \
210 thisClass *thisClass::NewInstance() const \
211 { return (thisClass *)NewObjectInstance(); }
214#define IsALBAType(type_name) IsA(type_name::GetStaticTypeId())
217#define ALBA_ID_IMP(idname) const albaID idname = mmuIdFactory::GetNextId(#idname);
219#define ALBA_ID_DEC(idname) static const albaID idname;
221#define ALBA_ID_GLOBAL(idname) extern const albaID idname;
222
224// Not Used !!
225//#define ALBA_ID_GROUP(groupname,num) const albaID groupname = mmuIdFactory::AllocIdGroup(#groupname,num);
228#define ALBA_ID_CLASS_DEC(baseClass) static const albaID BaseID;
230#define ALBA_ID_CLASS_IMP(baseClass,num) const albaID baseClass::BaseID = mmuIdFactory::AllocIdGroup("#baseClass::BaseID",num);
231
232#define ALBA_ID_LOC(name,idname) static const albaID name=mmuIdFactory::GetId(#idname);
235#define albaGetEventClassId(event,baseClass) (event->GetID()-baseClass::BaseID)
236#define albaGetEventGroupId(event,baseID) (event->GetID()-baseID)
237#define albaEvalGroupId(baseClass,id) (baseClass::BaseID+id)
240#define albaEventMacro(e) if (m_Listener) {m_Listener->OnEvent(&e);}
243#define ALBA_TEST(a) if (!(a)) \
244{ \
245 std::cerr << "Test failed at line " \
246 << __LINE__ << " : " << #a << std::endl; \
247 return ALBA_ERROR; \
248}
249
253#define albaWarningMacro(x) \
254{ \
255 std::stringstream msg; \
256 msg << "Warning in: " __FILE__ ", line " << __LINE__ << "\n" x \
257 << "\n"; \
258 albaLogMessage(msg.str().c_str());\
259}
260
264#define albaErrorMacro(x) \
265{ \
266 std::stringstream msg; \
267 msg << "Error in: " __FILE__ ", line " << __LINE__ << "\n" x \
268 << "\n"; \
269 albaLogMessage(msg.str().c_str());\
270}
271
274#define albaWarningMessageMacro(x) \
275{ \
276 std::stringstream msg; \
277 msg << x << "\n"; \
278 albaWarningMessage(msg.str().c_str());\
279}
280
283#define albaErrorMessageMacro(x) \
284{ \
285 std::stringstream msg; \
286 msg << x << "\n"; \
287 albaErrorMessage(msg.str().c_str());\
288}
289
292#define albaMessageMacro(x) \
293{ \
294 std::stringstream msg; \
295 msg << x << "\n"; \
296 albaMessage(msg.str().c_str());\
297}
298
303#define ALBA_PRINT_MACRO(format,buffer,size) \
304 va_list argptr; \
305 va_start(argptr, format); \
306 vsnprintf(buffer,(const size_t)size, format, argptr); \
307 va_end(argptr);
308
309#endif
ALBA_OK
Definition: albaDefines.h:69
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:68
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:71
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:61
std::type_info albaTypeID
type for albaObject's class type IDs
Definition: albaDefines.h:62
ALBA_ERROR
Definition: albaDefines.h:70
double albaTimeStamp
type for time varying data timestamps (not for pipelines timestamps!)
Definition: albaDefines.h:60