cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Files | Classes | Macros | Functions
cisstCommon

Files

file  cmnConstants.h
 Declaration of various constants.
 
file  cmnLogger.h
 Declaration of cmnLogger amd macros for human readable logging.
 
file  cmnLogLoD.h
 Declaration of Levels of Detail for cmnLogger (human readable logging)
 
file  cmnPath.h
 Declaration of cmnPath.
 
file  cmnPortability.h
 Portability across compilers and operating systems tools.
 
file  cmnPrintf.h
 Declaration of cmnPrintf and cmnPrintfParser.
 
file  cmnRequiresDeepCopy.h
 Declaration of cmnRequiresDeepCopy.
 
file  cmnUnits.h
 Declaration of units and unit conversion methodsThis file include the definition and implementation of constants and global functions used to defines measuring units in the cisst libraries. The internal units of the cisst libraries are meters, kilograms, seconds and radians if CISST_USE_SI_UNITS is set to true. Otherwise, units are millimeters and grams. Older versions of cisst didn't define CISST_USE_SI_UNITS and the default units were millimeters and grams.
 

Classes

class  cmnClassRegister
 Main register for classes. More...
 
class  cmnCommandLineOptions
 Set command line options and parse command line arguments. More...
 
class  cmnDeSerializer
 De-serialization utility class.This class allows to deserialize objects previously serialized using cmnSerializer. More...
 
class  cmnGenericObject
 Base class for high level objects. More...
 
class  cmnLogger
 Class to glue the class register, the output multiplexer and the message level of detail to form the logging entity of cisst. More...
 
class  cmnNamedMap< _elementType >
 
class  cmnObjectRegister
 Object Register. More...
 
class  cmnPath
 Search path to find a file. This class contains a list of directories used to locate a file. More...
 
class  cmnPrintf
 printf-like formatted output for streams More...
 
class  cmnPrintfParser
 Parser for cmnPrintf. More...
 
class  cmnRandomSequence
 Provide an interface to a reproducible random sequence. More...
 
class  cmnSerializer
 Serialization utility class.This class allows to serialize objects of different types (all derived from cmnGenericObject) as well as the information required to deserialize them (see cmnDeSerializer) to and from an STL output stream. More...
 
class  cmnTypeTraits< _elementType >
 A collection of useful information about the C++ basic types, represented in a generic programming way. More...
 

Macros

#define CMN_ASSERT(expr)
 

Functions

int cmn_snprintf (char *destination, size_t size, const char *format,...)
 
template<class _exceptionType >
void cmnThrow (const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR) throw (_exceptionType)
 

Detailed Description

Common tools used for most CISST applications. The main features of cisstCommon are:

Note
All the classes and global functions of cisstCommon start with the prefix cmn. To use cisstCommon, you can either include a specific file with:
#include <cisstCommon/cmnXyz.h>
or include all the files with:
#include <cisstCommon.h>

Macro Definition Documentation

#define CMN_ASSERT (   expr)
Value:
if (!(expr)) { \
std::stringstream messageBuffer; \
messageBuffer << __FILE__ << ": Assertion '" << #expr \
<< "' failed in: " << CMN_PRETTY_FUNCTION \
<< ", line #" << __LINE__; \
std::cerr << messageBuffer.str() << std::endl; \
CMN_LOG_INIT_ERROR << messageBuffer.str() << std::endl; \
abort(); \
}
#define CMN_LOG_INIT_ERROR
Definition: cmnLogger.h:162
#define CMN_PRETTY_FUNCTION
Somewhat portable compilation warning message. This works with very recent versions of gcc (4...
Definition: cmnPortability.h:563

Assert a condition. This macro should be used whenever one needs to assert a condition.

This macro has two main advantages over the system assert:

  • The error message is log using CMN_LOG (level of detail 1).
  • CMN_ASSERT behavior can be modified using the defined variables CISST_CMN_ASSERT_DISABLED and CISST_CMN_ASSERT_THROWS_EXCEPTION. The first variable allows to not compile the assertion. It is similar to the NDEBUG for the standard assert .
    The second variable allows to throw an exception (of type std::logic_error) instead of using the system abort. This can be convenient if the libraries are wrapped for an interpreted language such as Python. In this case, an abort() has the annoying effect of aborting the interpreter itself.
    Both these variables can be modified using the CMake advanced mode.
Note
When compiling on linux make sure ulimit -c is unlimited! Otherwise, no core file will be generated with abort() . By default, Redhat and Debian are set to prevent any core dump.
On windows abort() uses stderr in console apps, message box API with OK button for release builds and message box API with "Abort, Ignore, Retry" for debug builds.
See Also
cmnThrow

Function Documentation

int cmn_snprintf ( char *  destination,
size_t  size,
const char *  format,
  ... 
)
inline
template<class _exceptionType >
void cmnThrow ( const _exceptionType &  except,
cmnLogLevel  lod = CMN_LOG_LEVEL_INIT_ERROR 
)
throw (_exceptionType
)
inline

Throw an exception. This templated function should be used to throw any exception.

One of the advantages of this function over the default throw is that if the exception is of type std::exception, the message is logged (using the what method).
This function attempts to dynamically cast the exception. If the cast succeeds, the cmnThrow will log the message using CMN_LOG (level of detail). If the cast fails, cmnThrow will log a less informative message anyway.
Once the message has been logged, cmnThrow simply uses throw to throw the exception.

Using this function systematically within the cisst packages also allows some system wide configuration:

  • In some special cases such as real-time programming, exceptions can be somewhat impractical. If the variable CISST_CMN_THROW_DOES_ABORT is defined at compilation time, cmnThrow doesn't throw an exception but uses the abort function. This is a very special case and the vast majority of users should not use this option.
    Using the CMake advanced mode, it is possible to define CISST_CMN_THROW_DOES_ABORT for the whole cisst package. It is important to note that this option will break many of the cisst package tests programs (tests based on try and catch).
  • This function might be used later on to provide a nice debug breakpoint. Indeed, cmnThrow is called before the exception is actually throw and the stack unwinding.
See Also
CMN_ASSERT
Note
The type of exception thrown would ideally derived from std::exception but this is not a requirement.