16#ifndef __albaDefines_h
17#define __albaDefines_h
26#pragma warning( disable : 4018 )
27#pragma warning( disable : 4251 )
34#include "albaConfigure.h"
45 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
48 #define MAX( x, y ) ( (x) > (y) ? (x) : (y) )
51 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
69 ALBA_USER_RETURN_VALUE
77#define ALBA_STRING_BUFFER_SIZE 2048
119#define vtkDEL(a) do{if (a) { a->Delete(); a = NULL; }}while(0)
122#define vtkNEW(a) a=a->New()
125#define albaNEW(a) do{a=a->New();a->Register(this);}while(0)
128#define albaDEL(a) do{if (a) { a->Delete(); a = NULL;}}while(0)
131#define cppDEL(a) do{if (a) { delete a; a = NULL;}}while(0)
136#define albaAbstractTypeMacro(thisClass,superclass) \
139 typedef superclass Superclass; \
141 static const albaTypeID &GetStaticTypeId(); \
143 virtual const albaTypeID &GetTypeId() const; \
145 static const char *GetStaticTypeName(); \
147 virtual const char *GetTypeName() const; \
149 static bool IsStaticType(const char *type); \
151 static bool IsStaticType(const albaTypeID &type); \
153 virtual bool IsA(const char *type) const; \
155 virtual bool IsA(const albaTypeID &type) const; \
157 static thisClass* SafeDownCast(albaObject *o);
162#define albaTypeMacro(thisClass,superclass) \
163 albaAbstractTypeMacro(thisClass,superclass); \
165 static albaObject *NewObject(); \
167 virtual albaObject *NewObjectInstance() const; \
169 thisClass *NewInstance() const; \
173 static thisClass *New();
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;} }
195#define albaCxxTypeMacro(thisClass) \
196 albaCxxAbstractTypeMacro(thisClass); \
197 albaObject *thisClass::NewObject() \
199 thisClass *obj = new thisClass; \
200 if (obj) obj->m_HeapFlag=true; \
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;
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);
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)) \
242 std::cerr << "Test failed at line " \
243 << __LINE__ << " : " << #a << std::endl; \
250#define albaWarningMacro(x) \
252 std::stringstream msg; \
253 msg << "Warning in: " __FILE__ ", line " << __LINE__ << "\n" x \
255 albaLogMessage(msg.str().c_str());\
261#define albaErrorMacro(x) \
263 std::stringstream msg; \
264 msg << "Error in: " __FILE__ ", line " << __LINE__ << "\n" x \
266 albaLogMessage(msg.str().c_str());\
271#define albaWarningMessageMacro(x) \
273 std::stringstream msg; \
275 albaWarningMessage(msg.str().c_str());\
280#define albaErrorMessageMacro(x) \
282 std::stringstream msg; \
284 albaErrorMessage(msg.str().c_str());\
289#define albaMessageMacro(x) \
291 std::stringstream msg; \
293 albaMessage(msg.str().c_str());\
300#define ALBA_PRINT_MACRO(format,buffer,size) \
302 va_start(argptr, format); \
303 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!)