16#ifndef __albaDefines_h
17#define __albaDefines_h
26#pragma warning( disable : 4018 )
27#pragma warning( disable : 4251 )
40#include "albaConfigure.h"
48 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
51 #define MAX( x, y ) ( (x) > (y) ? (x) : (y) )
54 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
72 ALBA_USER_RETURN_VALUE
80#define ALBA_STRING_BUFFER_SIZE 2048
122#define vtkDEL(a) do{if (a) { a->Delete(); a = NULL; }}while(0)
125#define vtkNEW(a) a=a->New()
128#define albaNEW(a) do{a=a->New();a->Register(this);}while(0)
131#define albaDEL(a) do{if (a) { a->Delete(); a = NULL;}}while(0)
134#define cppDEL(a) do{if (a) { delete a; a = NULL;}}while(0)
139#define albaAbstractTypeMacro(thisClass,superclass) \
142 typedef superclass Superclass; \
144 static const albaTypeID &GetStaticTypeId(); \
146 virtual const albaTypeID &GetTypeId() const; \
148 static const char *GetStaticTypeName(); \
150 virtual const char *GetTypeName() const; \
152 static bool IsStaticType(const char *type); \
154 static bool IsStaticType(const albaTypeID &type); \
156 virtual bool IsA(const char *type) const; \
158 virtual bool IsA(const albaTypeID &type) const; \
160 static thisClass* SafeDownCast(albaObject *o);
165#define albaTypeMacro(thisClass,superclass) \
166 albaAbstractTypeMacro(thisClass,superclass); \
168 static albaObject *NewObject(); \
170 virtual albaObject *NewObjectInstance() const; \
172 thisClass *NewInstance() const; \
176 static thisClass *New();
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;} }
198#define albaCxxTypeMacro(thisClass) \
199 albaCxxAbstractTypeMacro(thisClass); \
200 albaObject *thisClass::NewObject() \
202 thisClass *obj = new thisClass; \
203 if (obj) obj->m_HeapFlag=true; \
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;
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);
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)) \
245 std::cerr << "Test failed at line " \
246 << __LINE__ << " : " << #a << std::endl; \
253#define albaWarningMacro(x) \
255 std::stringstream msg; \
256 msg << "Warning in: " __FILE__ ", line " << __LINE__ << "\n" x \
258 albaLogMessage(msg.str().c_str());\
264#define albaErrorMacro(x) \
266 std::stringstream msg; \
267 msg << "Error in: " __FILE__ ", line " << __LINE__ << "\n" x \
269 albaLogMessage(msg.str().c_str());\
274#define albaWarningMessageMacro(x) \
276 std::stringstream msg; \
278 albaWarningMessage(msg.str().c_str());\
283#define albaErrorMessageMacro(x) \
285 std::stringstream msg; \
287 albaErrorMessage(msg.str().c_str());\
292#define albaMessageMacro(x) \
294 std::stringstream msg; \
296 albaMessage(msg.str().c_str());\
303#define ALBA_PRINT_MACRO(format,buffer,size) \
305 va_start(argptr, format); \
306 vsnprintf(buffer,(const size_t)size, format, argptr); \
ALBA_EXPORT void albaErrorMessage(const char *format,...)
open an error dialog and write a message
enum ALBA_EXPORT ALBA_RETURN_VALUES_ID
ALBA_EXPORT bool albaFloatEquals(float x, float y)
ALBA_EXPORT void albaWarningMessage(const char *format,...)
open a warning dialog and write a message
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
std::type_info albaTypeID
type for albaObject's class type IDs
double albaTimeStamp
type for time varying data timestamps (not for pipelines timestamps!)