config.h
Go to the documentation of this file.00001 #ifndef CPPTL_CONFIG_H_INCLUDED
00002 # define CPPTL_CONFIG_H_INCLUDED
00003
00004
00005 #include <utility>
00006
00007
00009
00010
00011 # if defined(_MSC_VER)
00012 # if _MSC_VER <= 1200 // VC++ 6 or before
00013 # pragma warning( disable : 4786 ) // ident trunc to '255' chars in debug info
00014 # pragma warning( disable : 4800 ) // forcing value to bool performance warning
00015 # pragma warning( disable : 4018 ) // '<' signed/unsigned mismatch
00016 # define CPPTL_NO_VECTOR_STD_ITERATOR
00017 # define CPPTL_NO_FUNCTION_TEMPLATE_ORDERING
00018 # define CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00019 # define CPPTL_HAS_INT64 1
00020 # define CPPTL_NO_INT64_TO_DOUBLE // no conversion from int64 to double
00021 # endif
00022
00023 # if _MSC_VER >= 1200 // VC++ 6 and above
00024 # undef CPPTL_NO_ENUM_STATIC_CONSTANT
00025 # endif
00026
00027 # if _MSC_VER <= 1300 // VC++ 7.0 or before
00028
00029
00030 # define CPPTL_NO_DEDUCED_TYPENAME
00031 # define CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00032 # endif
00033
00034 # if _MSC_VER >= 1310 // VC++ 7.1
00035 # define CPPTL_HAS_INT64 1
00036
00037 # pragma warning( disable : 4800 ) // forcing value to bool performance warning
00038 # pragma warning( disable : 4018 ) // '<' signed/unsigned mismatch
00039 # pragma warning( disable : 4180 ) // qualifier applied to function type has no meaning
00040 # endif
00041
00042 # ifndef _CPPRTTI // RTTI is not enabled
00043 # define CPPTL_NO_RTTI
00044 # endif
00045
00046 # define CPPTL_HAS__SNPRINTF 1
00047
00048 # endif
00049
00050
00051
00053 # if defined(__GLIBCPP__) || defined(__GLIBCXX__) // GNU libstdc++ 3
00054 # if !defined(_GLIBCPP_USE_WCHAR_T) && !defined(_GLIBCXX_USE_WCHAR_T)
00055 # define CPPTL_NO_STD_WSTRING 1
00056 # endif
00057 # endif
00058
00059 # if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__STL_USE_NEW_IOSTREAMS)
00060 # define CPPTL_NO_SSTREAM 1 // No #include <sstream>
00061 # define CPPTL_NO_STL_SEQUENCE_AT 1 // No std::vector<>::at std::deque<>::at
00062 # define CPPTL_NO_STD_WSTRING 1
00063 # endif
00064
00065
00067
00068 # if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
00069 # define CPPTL_USE_WIN32_ATOMIC 1
00070 # define CPPTL_USE_WIN32_THREAD 1
00071 # elif defined(linux) || defined(__linux) || defined(__linux__)
00072 # define CPPTL_USE_PTHREAD_THREAD 1
00073 # elif defined(sun) || defined(__sun)
00074 # define CPPTL_USE_PTHREAD_THREAD 1
00075 # elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
00076 # define CPPTL_USE_PTHREAD_THREAD 1
00077 # elif defined(__IBMCPP__)
00078 # define CPPTL_USE_PTHREAD_THREAD 1
00079 # endif
00080
00081
00083
00086 # if defined(CPPTL_NO_DEDUCED_TYPENAME)
00087 # define CPPTL_TYPENAME
00088 #else
00089 # define CPPTL_TYPENAME typename
00090 # endif
00091
00094 # if defined(CPPTL_NO_ENUM_STATIC_CONSTANT)
00095 # define CPPTL_STATIC_CONSTANT( type, assignment ) \
00096 static const int assignment
00097 # else
00098 # define CPPTL_STATIC_CONSTANT( type, assignment ) \
00099 enum { assignment }
00100 # endif
00101
00105 # if defined(CPPTL_NO_VECTOR_STD_ITERATOR) && defined(CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
00106 # define CPPTL_NO_VECTOR_ITERATOR_VALUE_TYPE_DEDUCTION 1 // might works with STLPort
00107 # endif
00108
00118 # if defined(CPPTL_NO_TYPE_DEFAULT_ARG)
00119 # define CPPTL_TYPE_DEFAULT_ARG(aType)
00120 # else
00121 # define CPPTL_TYPE_DEFAULT_ARG(aType) = ::CppTL::Type<aType>()
00122 # endif
00123
00124
00125
00126 # if defined(CPPTL_NO_STL_SEQUENCE_AT)
00127 # define CPPTL_AT( container, index ) container[index]
00128 # else
00129 # define CPPTL_AT( container, index ) (container).at(index)
00130 # endif
00131
00132 # if !defined(CPPTL_HAS_THREAD)
00133 # if CPPTL_USE_WIN32_THREAD || CPPTL_USE_PTHREAD_THREAD
00134 # define CPPTL_HAS_THREAD 1
00135 # endif
00136 # endif
00137
00138 # if !CPPTL_HAS_THREAD_SAFE_ATOMIC_COUNTER
00139 # if CPPTL_USE_PTHREAD_THREAD && !CPPTL_USE_WIN32_ATOMIC
00140 # define CPPTL_USE_PTHREAD_ATOMIC 1
00141 # endif
00142 # if CPPTL_USE_PTHREAD_ATOMIC || CPPTL_USE_WIN32_ATOMIC
00143 # define CPPTL_HAS_THREAD_SAFE_ATOMIC_COUNTER 1
00144 # endif
00145 # endif
00146
00147
00148
00150
00151 # define CPPTL_API
00152
00153
00154
00155
00156
00158
00159
00178 #define CPPTL_JOIN( symbol1, symbol2 ) _CPPTL_DO_JOIN( symbol1, symbol2 )
00179
00181 #define _CPPTL_DO_JOIN( symbol1, symbol2 ) _CPPTL_DO_JOIN2( symbol1, symbol2 )
00182
00184 #define _CPPTL_DO_JOIN2( symbol1, symbol2 ) symbol1##symbol2
00185
00190 #define CPPTL_MAKE_UNIQUE_NAME( prefix ) CPPTL_JOIN( prefix, __LINE__ )
00191
00192 #define CPPTL_MIN( a, b ) ((a) < (b) ? a : b)
00193 #define CPPTL_MAX( a, b ) ((a) > (b) ? a : b)
00194
00199 #define CPPTL_CHECK_TYPE_COMPLETE( Type ) \
00200 { \
00201 typedef char typeMustBeComplete[ sizeof(Type) ? 1 : -1 ]; \
00202 (void)sizeof(typeMustBeComplete); \
00203 }
00204
00206 #define CPPTL_ARRAY_SIZE( array ) (sizeof(array)/sizeof((array)[0]))
00207
00209
00210 #ifdef NDEBUG
00211 # define CPPTL_ASSERT_MESSAGE( cond, message ) \
00212 (void)(0)
00213
00214 # define CPPTL_DEBUG_ASSERT_UNREACHABLE \
00215 (void)(0)
00216 #else
00217 # include <assert.h>
00218 # define CPPTL_ASSERT_MESSAGE( cond, message ) \
00219 assert( (cond) && message )
00220
00221 # define CPPTL_DEBUG_ASSERT_UNREACHABLE \
00222 assert( false && "unreachable code" )
00223 #endif
00224
00225 namespace CppTL {
00226
00227
00228 # ifndef CPPTL_NO_INT64
00229 # if CPPTL_HAS_LONGLONG
00230 typedef long long int64_t;
00231 typedef unsigned long long uint64_t;
00232 # elif CPPTL_HAS_INT64
00233 typedef __int64 int64_t;
00234 typedef unsigned __int64 uint64_t;
00235 # else
00236 # define CPPTL_NO_INT64 1
00237 # endif
00238 # endif
00239
00240
00241 #ifndef CPPTL_NO_INT64
00242 typedef CppTL::int64_t LargestInt;
00243 typedef CppTL::uint64_t LargestUnsignedInt;
00244 #else
00245 typedef int LargestInt;
00246 typedef unsigned int LargestUnsignedInt;
00247 #endif
00248
00249
00250 typedef unsigned int size_type;
00251
00252 template<class T>
00253 struct Type
00254 {
00255 typedef T type;
00256 };
00257
00259 class CPPTL_API NonCopyable
00260 {
00261 public:
00262 NonCopyable()
00263 {
00264 }
00265
00266 ~NonCopyable()
00267 {
00268 }
00269
00270 private:
00271 NonCopyable( const NonCopyable &other );
00272 void operator =( const NonCopyable &other );
00273 };
00274
00275 template<class T>
00276 inline void
00277 swap( T &left, T &right )
00278 {
00279 T temp( left );
00280 left = right;
00281 right = temp;
00282 }
00283
00284 template<class T>
00285 void checkedDelete( T *p )
00286 {
00287 CPPTL_CHECK_TYPE_COMPLETE( T )
00288 delete p;
00289 }
00290
00291 template<class T>
00292 void checkedArrayDelete( T *p )
00293 {
00294 CPPTL_CHECK_TYPE_COMPLETE( T )
00295 delete[] p;
00296 }
00297
00298 template<class TargetType, class SourceType>
00299 TargetType checkedCast( SourceType *pointer, Type<TargetType> )
00300 {
00301 TargetType casted = dynamic_cast<TargetType>( pointer );
00302 CPPTL_ASSERT_MESSAGE( casted != 0, "CPPTL_CHECKED_CAST: wrong TargetType." );
00303 return casted;
00304 }
00305
00306 #if defined(NDEBUG) || defined(CPPTL_NO_RTTI)
00307 # define CPPTL_CHECKED_CAST( TargetType, pointer ) \
00308 static_cast<TargetType>( pointer )
00309 #else
00310 # define CPPTL_CHECKED_CAST( TargetType, pointer ) \
00311 ::CppTL::checkedCast( pointer, ::CppTL::Type<TargetType>() )
00312 #endif
00313
00314
00315
00316 }
00317
00318
00319 #endif // CPPTL_CONFIG_H_INCLUDED