Actin  Version 5.5.5
Software for Robotics Simulation and Control
ecMacros.h
Go to the documentation of this file.
1 #ifndef ecMacros_H_
2 #define ecMacros_H_
3 //------------------------------------------------------------------------------
4 // Copyright (c) 2001-2019 Energid Technologies. All rights reserved.
5 //
8 //
9 //------------------------------------------------------------------------------
10 #include "ecConstants.h"
11 
12 #include <ecboost/current_function.hpp>
13 
14 #ifdef _WIN32
15 #define NULLFILE "NUL"
16 #else
17 #define NULLFILE "/dev/null"
18 #endif
19 
20 #include "ecPrint.h"
21 
23 #define Ec_UNUSED(x) (void)x
24 
26 #define EcSTRINGIFY(A) #A
27 
29 #ifdef _DEBUG
30 # include <assert.h>
31 # define EcTRAP() assert(0)
32 #else
33 # define EcTRAP()
34 #endif
35 
37 #if defined(EC_ENABLE_LEGACY_CPP)
38 #define EC_OVERRIDE
39 #else
40 #define EC_OVERRIDE override
41 #endif
42 
44 #if defined(EC_ENABLE_LEGACY_CPP)
45 #define EC_FINAL
46 #else
47 #define EC_FINAL final
48 #endif
49 
53 template<class Type>
54 inline void EcDELETE
55  (
56  Type& x
57  )
58 {
59  // it is always safe to regular delete a NULL pointer, but at
60  // runtime most EcDELETE'ed pointers are NULL, so checking here is
61  // faster
62  if(x)
63  {
64  delete(x);
65  x=0;
66  }
67 }
68 
72 template<class Type>
73 inline void EcARRAYDELETE
74  (
75  Type& x
76  )
77 {
78  // it is not safe to array delete a NULL pointer
79  if(x)
80  {
81  delete[] x;
82  x=0;
83  }
84 }
85 
90 template<class Type>
91 inline void EcSWAP
92  (
93  Type& xx,
94  Type& yy
95  )
96 {
97  Type zz=xx;
98  xx=yy;
99  yy=zz;
100 }
101 
105  (
106  EcU32 ms
107  );
108 
111 #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
112 
114 namespace Ec
115 {
116  template <typename T> EcBoolean writeBinary
117  (
118  const T& value,
119  std::ostream& ofs
120  )
121  {
123  ofs.write(reinterpret_cast<const char*>(&value), sizeof(value));
124  return EcTrue;
125  }
126 }
127 
128 #define EcWRITEBIN(value, stream) Ec::writeBinary(value, stream)
129 
131 namespace Ec
132 {
133  template <typename T> EcBoolean readBinary
134  (
135  T& value,
136  std::istream& ifs
137  )
138  {
140  ifs.read(reinterpret_cast<char*>(&value), sizeof(value));
141  return EcTrue;
142  }
143 }
144 
145 #define EcREADBIN(value, stream) Ec::readBinary(value, stream)
146 
147 #ifdef RTOS32WIN
148 const EcStringVector& EcRTOS32WinReadCommandLine
152  (
153  const EcString &name
154  );
155 #endif
156 
161  (
162  const EcString& dirname
163  );
164 
170  (
171  const EcString& directoryPlusFilename,
172  EcString& filenameOnly
173  );
174 
177  (
178  const EcString& directoryPlusFilename
179  );
180 
181 
184  (
185  int integer,
186  EcU32 radix=10U
187  );
188 
189 
192  (
193  long int integer,
194  EcU32 radix=10U
195  );
196 
199  (
200  long long int integer,
201  EcU32 radix=10U
202  );
203 
206  (
207  unsigned integer,
208  EcU32 radix=10U
209  );
210 
211 
214  (
215  unsigned long integer,
216  EcU32 radix=10U
217  );
218 
221  (
222  unsigned long long integer,
223  EcU32 radix=10U
224  );
225 
228  (
229  const EcReal value
230  );
231 
234  (
235  const EcString& valueString
236  );
237 
240  (
241  const EcString& str
242  );
243 
244 // Support for C++11 features not available in older compilers.
245 #if defined(EC_ENABLE_LEGACY_CPP)
246 #define EC_STD_MAP_AT(map, key, null) (map.count(key))?map.find(key)->second:null
247 #else
248 #define EC_STD_MAP_AT(map, key, null) map.at(key)
249 #endif
250 
252 #define ECXMLOBJECT_CLONE(EcCls) \
253  virtual EcXmlObject* clone() const EC_OVERRIDE\
254  { \
255  return new EcCls(*this); \
256  }
257 
259 #define ECXMLOBJECT_EQUALITY(EcCls) \
260  virtual EcBoolean equality(const EcXmlObject* other) const EC_OVERRIDE\
261  { \
262  EcBoolean retVal=EcTrue; \
263  const EcCls* cast = dynamic_cast<const EcCls*>(other); \
264  if(!cast || !(*this==*cast)) \
265  { \
266  retVal=EcFalse; \
267  } \
268  return retVal; \
269  }
270 
272 #define ECXMLOBJECT_NEWOBJECT(EcCls) \
273  virtual EcXmlObject* newObject() const EC_OVERRIDE \
274  { \
275  return new EcCls(); \
276  }
277 
279 #define ECXML_XMLOBJECTCREATOR(EcCls) \
280  static EcXmlObject* xmlObjectCreator() \
281  { \
282  return new EcCls(); \
283  }
284 
288 #define ECXML_DECLARE_TOKENS \
289  virtual const EcToken& token() const EC_OVERRIDE \
290  { \
291  return classToken(); \
292  } \
293  static const EcToken& classToken()
294 
296 #define ECXML_DEFINE_TOKENS(EcCls,EcClsToken) \
297  const EcToken& EcCls::classToken() \
298  { \
299  return EcClsToken; \
300  }
301 
303 #define ECXML_REGISTER_COMPONENT_CREATOR(EcCls) \
304  registerComponentCreator(EcCls::classToken(),EcCls::xmlObjectCreator)
305 
312 #define ECDECLARE_BIGFOUR(EcCls) \
313  EcCls(); \
314  virtual ~EcCls(); \
315  EcCls(const EcCls&); \
316  EcCls& operator=(const EcCls&); \
317  EcBoolean operator==(const EcCls&) const
318 
324 #define ECXMLOBJECT_PUREVIRTUAL(cls) \
325  ECDECLARE_BIGFOUR(cls); \
326  ECXMLOBJECT_EQUALITY(cls) \
327 
328 
334 #define ECXMLOBJECT(cls) \
335  ECDECLARE_BIGFOUR(cls); \
336  ECXMLOBJECT_CLONE(cls) \
337  ECXMLOBJECT_EQUALITY(cls) \
338  ECXMLOBJECT_NEWOBJECT(cls) \
339  ECXML_DECLARE_TOKENS
340 
344 #define EC_XMLOBJECT_PLUGIN_DECLARE(cls) \
345  public: \
346  ECXMLOBJECT(cls); \
347  ECXML_XMLOBJECTCREATOR(cls)\
348  protected: \
349  virtual EcXmlObject* libraryAttribute() EC_OVERRIDE; \
350  EcXmlString m_LibraryAttribute; \
351 
352 #define EC_XMLOBJECT_PLUGIN_DEFINE(cls, token) \
356  ECXML_DEFINE_TOKENS(cls, token) \
357  EcXmlObject* cls::libraryAttribute() \
358  {\
359  m_LibraryAttribute = EC_CMAKE_DEF_PLUGIN_LIBRARY_NAME; \
360  return &m_LibraryAttribute;\
361  }\
362 
363 #define EC_XMLOBJECT_PLUGIN_ACCESSORS(cls) \
368  extern "C" EC_DECL_EXPORTS const EcToken* getClassToken(EcU16); \
369  extern "C" EC_DECL_EXPORTS EcXmlObjectCreator getCreator(EcU16); \
370  const EcToken* getClassToken \
371  ( \
372  EcU16 index \
373  ) \
374  { \
375  static const EcToken emptyString; \
376  return index == 0 ? &cls::classToken() : &emptyString; \
377  } \
378  EcXmlObjectCreator getCreator \
379  ( \
380  EcU16 index \
381  ) \
382  { \
383  return index == 0 ? cls::xmlObjectCreator : 0; \
384  } \
385 
386 #if defined(_VX_CPU) && (_VX_CPU == _VX_PPC32)
388 # define EcU32FORMATSPECIFIER "%lu"
389 #else
390 # define EcU32FORMATSPECIFIER "%u"
391 #endif
392 
394 #ifdef __VXWORKS__
395 # ifdef _WRS_KERNEL
396 # include <taskLib.h>
397 # include <iostream>
398 # include <stdexcept>
399 # ifdef _DEBUG
400 # define EC_VXWORKS_DKM_ENTRY_POINT(name) \
401  int name##DebugLauncher \
402  ( \
403  ... \
404  ) \
405  { \
406  int argc = 1; \
407  char* argv[] = { (char *) #name "Debug.out" }; \
408  return main(argc, argv); \
409  } \
410  extern "C" void name##Debug \
411  ( \
412  ) \
413  { \
414  taskSpawn((char *) #name "Debug", 100, VX_FP_TASK, 2097152, \
415  (FUNCPTR) name##DebugLauncher,0,0,0,0,0,0,0,0,0,0); \
416  }
417 # else
418 # define EC_VXWORKS_DKM_ENTRY_POINT(name) \
419  int name##Launcher \
420  ( \
421  ... \
422  ) \
423  { \
424  int argc = 1; \
425  char* argv[] = { (char *) #name ".out" }; \
426  return main(argc, argv); \
427  } \
428  extern "C" void name \
429  ( \
430  ) \
431  { \
432  taskSpawn((char *) #name , 100, VX_FP_TASK, 2097152, \
433  (FUNCPTR) name##Launcher,0,0,0,0,0,0,0,0,0,0); \
434  }
435 # endif
436 # else
437 # define EC_VXWORKS_DKM_ENTRY_POINT(name)
438 # endif
439 #else
440 # define EC_VXWORKS_DKM_ENTRY_POINT(name)
441 #endif
442 
443 #endif // ecMacros_H_
std::basic_string< wchar_t > EcWString
a wide character string
Definition: ecTypes.h:123
void EcDELETE(Type &x)
Definition: ecMacros.h:55
void EcARRAYDELETE(Type &x)
Definition: ecMacros.h:74
ecboost::uint32_t EcU32
32-bit unsigned integer
Definition: ecTypes.h:53
const EcBoolean EcTrue
gives a representation of true
Definition: ecConstants.h:19
void EcSWAP(Type &xx, Type &yy)
Definition: ecMacros.h:92
EcBoolean readBinary(T &value, std::istream &ifs)
Definition: ecMacros.h:134
EC_STABLE_FOUNDCORE_DECL EcReal EcSTRING2DOUBLE(const EcString &valueString)
Convert a string to a double.
std::vector< EcString > EcStringVector
string organization using vectors
Definition: ecTypes.h:138
EC_STABLE_FOUNDCORE_DECL EcBoolean EcExtractFilename(const EcString &directoryPlusFilename, EcString &filenameOnly)
EC_STABLE_FOUNDCORE_DECL EcBoolean EcFILEEXISTS(const EcString &directoryPlusFilename)
see if a file exists
#define EC_STABLE_FOUNDCORE_DECL
foundCore directory
Definition: ecConfig.h:149
EC_STABLE_FOUNDCORE_DECL EcWString EcSTRING2WSTRING(const EcString &str)
Convert a string to a wide string.
EC_STABLE_FOUNDCORE_DECL EcString EcDOUBLE2STRING(const EcReal value)
convert a double to a string
Energid common namespace.
bool EcBoolean
Boolean (0 or 1)
Definition: ecTypes.h:21
EC_STABLE_FOUNDCORE_DECL EcString EcINT2STRING(int integer, EcU32 radix=10U)
convert an integer to a string
EcF64 EcReal
Alias for 64-bit float.
Definition: ecTypes.h:30
std::basic_string< char > EcString
a character string
Definition: ecTypes.h:116
A collection of constant values, both physics and programming constants.
EC_STABLE_FOUNDCORE_DECL EcBoolean EcMKDIR(const EcString &dirname)
EcBoolean writeBinary(const T &value, std::ostream &ofs)
Definition: ecMacros.h:117
EC_STABLE_FOUNDCORE_DECL void EcSLEEPMS(EcU32 ms)