ct_common  1.0.1
Common library for combinatorial testing
src/ct_common/common/utils.h
Go to the documentation of this file.
00001 //===----- ct_common/common/utils.h -----------------------------*- C++ -*-===//
00002 //
00003 //                      The ct_common Library
00004 //
00005 // This file is distributed under the MIT license. See LICENSE for details.
00006 //
00007 //===----------------------------------------------------------------------===//
00008 //
00009 // This header file contains some utility definitions and classes
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #ifndef CT_COMMON_UTILS_H_
00014 #define CT_COMMON_UTILS_H_
00015 
00016 #ifdef USE_ASSERT
00017 #include <cassert>
00018 #else  // USE_ASSERT
00019 #include <exception>
00020 #include <string>
00021 
00022 namespace ct {
00023 namespace common {
00027 class CT_Exception : public std::exception {
00028 public:
00029   CT_Exception(void) throw(): std::exception() {}
00030   CT_Exception(const CT_Exception &from) throw(): std::exception(from) {
00031     this->what_ = from.what_;
00032   }
00033   CT_Exception(std::string what) throw() { this->what_ = what; }
00034   virtual ~CT_Exception(void) throw() {} ;
00035   
00036   virtual const char *what() const throw() { return this->what_.c_str(); }
00037 
00038 private:
00039   std::string what_;
00040 };
00041 }  // namespace common
00042 }  // namespace ct
00043 #endif  // USE_ASSERT
00044 
00045 // for exporting shared library
00046 #ifndef DLL_EXPORT
00047 #ifdef _WIN32
00048 #pragma warning(disable:4251)
00049 #endif  // _WIN32
00050 #ifdef _DLL_EXPORT
00051   #define DLL_EXPORT __declspec(dllexport)
00052 #else  // _DLL_EXPORT
00053 #ifdef _DLL_IMPORT
00054   #define DLL_EXPORT __declspec(dllimport)
00055 #else  // _DLL_IMPORT
00056   #define DLL_EXPORT
00057 #endif  // _DLL_IMPORT
00058 #endif  // _DLL_EXPORT
00059 #endif
00060 
00061 #ifdef USE_ASSERT
00062 #define CT_EXCEPTION(x) do { assert(!x); } while (false)
00063 #else  // USE_ASSERT
00064 #define CT_EXCEPTION(x) do { throw (ct::common::CT_Exception(x)); } while (false)
00065 #endif  // USE_ASSERT
00066 
00067 #define TYPE_CHECK(x, T) ((dynamic_cast<T>(x) != 0) ? true:false)
00068 #define TYPE_ASSERT(x, T) do { if (!TYPE_CHECK(x,T)) { CT_EXCEPTION(std::string("the object is not of type ") + #T); } } while (false)
00069 
00070 #endif  // CT_COMMON_UTILS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines