|
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.
|
|
Common tools used for most CISST applications. The main features of cisstCommon are:
- A log system. There is a set of classes and macros which allows the user to log some text information to any c++ stream, including a file or stdout. For further details, see cmnLogger, cmnClassRegister and cmnClassServices.
- A random sequence generator. For more information, see cmnRandomSequence.
- A type trait class used to define common values for different types (e.g. default tolerance for float, double, int). See cmnTypeTraits.
- A path search class, see cmnPath.
- XML Path wrappers using either LibXML2 (preferred) or Qt XML. See cmnXMLPath.
- 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:
#define CMN_ASSERT |
( |
|
expr | ) |
|
Value:if (!(expr)) { \
std::stringstream messageBuffer; \
messageBuffer << __FILE__ << ": Assertion '" << #expr \
<< ", line #" << __LINE__; \
std::cerr << 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
int cmn_snprintf |
( |
char * |
destination, |
|
|
size_t |
size, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
|
inline |
template<class _exceptionType >
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.