1 #ifndef __CPPLUGINS_CONFIG__H__
2 #define __CPPLUGINS_CONFIG__H__
5 * =========================================================================
7 * =========================================================================
10 #define ITK_MANUAL_INSTANTIATION
11 #ifndef ITK_DELETE_FUNCTION
12 # define ITK_DELETE_FUNCTION
13 #endif // ITK_DELETE_FUNCTION
16 #endif // ITK_OVERRIDE
19 * =========================================================================
21 * =========================================================================
23 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
24 # define cpPlugins_SYS_WINDOWS
25 # define cpPlugins_LIB_PREFIX ""
26 # define cpPlugins_LIB_EXT "dll"
27 # ifndef WIN32_LEAN_AND_MEAN
28 # define WIN32_LEAN_AND_MEAN
33 #elif defined( linux ) || defined( __linux )
34 # define cpPlugins_SYS_LINUX
35 # define cpPlugins_LIB_PREFIX "lib"
36 # define cpPlugins_LIB_EXT "so"
37 #elif defined( __APPLE__ ) || defined( MACOSX ) || defined( macintosh ) || defined( Macintosh )
38 # define cpPlugins_SYS_MACOS
39 # define cpPlugins_LIB_PREFIX "lib"
40 # define cpPlugins_LIB_EXT "dylib"
41 #elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
42 # define cpPlugins_SYS_FREEBSD
43 # define cpPlugins_LIB_PREFIX "lib"
44 # define cpPlugins_LIB_EXT "so"
46 # error "This operating system is not supported by cpPlugins"
50 * =========================================================================
51 * Some helper functions
52 * =========================================================================
61 // -------------------------------------------------------------------------
62 #ifdef cpPlugins_SYS_WINDOWS
63 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
64 #else // cpPlugins_SYS_WINDOWS
65 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
66 #endif // cpPlugins_SYS_WINDOWS
68 // -------------------------------------------------------------------------
69 #define cpPlugins_CHRONO \
70 std::chrono::duration_cast< std::chrono::milliseconds >( \
71 std::chrono::system_clock::now( ).time_since_epoch( ) \
78 // ---------------------------------------------------------------------
79 inline bool operator()( char c ) const
81 #ifdef cpPlugins_SYS_WINDOWS
82 return( c == '\\' || c == '/' );
83 #else // cpPlugins_SYS_WINDOWS
85 #endif // cpPlugins_SYS_WINDOWS
89 // -----------------------------------------------------------------------
90 inline bool IsBlank( const char& value )
92 return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
95 // -----------------------------------------------------------------------
96 template< class _TTokens >
97 inline void TokenizeString(
98 _TTokens& tokens, const std::string& str, const std::string& delims
102 if( str.size( ) > 0 )
104 auto ssize = str.size( );
105 char* buffer = new char[ ssize + 1 ];
106 for( unsigned long i = 0; i < ssize; ++i )
107 buffer[ i ] = str[ i ];
108 buffer[ ssize ] = '\0';
110 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
113 tokens.push_back( std::string( it ) );
114 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
122 // -----------------------------------------------------------------------
123 inline std::string ReplaceString(
124 const std::string& str, const std::string& sub, const std::string& nsub
127 std::string res = str;
129 while( ( index = res.find( sub ) ) != std::string::npos )
130 res.replace( index, sub.size( ), nsub );
134 // -----------------------------------------------------------------------
135 inline bool ReadFileIntoString( std::string& buffer, const std::string& fname )
138 std::ifstream file_stream( fname.c_str( ) );
141 file_stream.seekg( 0, std::ios::end );
142 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
143 file_stream.seekg( 0, std::ios::beg );
145 ( std::istreambuf_iterator< char >( file_stream ) ),
146 std::istreambuf_iterator< char >( )
148 file_stream.close( );
152 // -----------------------------------------------------------------------
153 inline std::string CanonicalPath( const std::string& path )
155 std::string ret = "";
156 #ifdef cpPlugins_SYS_WINDOWS
157 TCHAR buffer[ 4096 ] = TEXT( "" );
158 TCHAR** lppPart = { NULL };
159 GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
160 ret = std::string( buffer );
161 #else // cpPlugins_SYS_WINDOWS
162 char* canonical_path = realpath( path.c_str( ), NULL );
163 if( canonical_path != NULL )
165 ret = canonical_path;
166 free( canonical_path );
169 #endif // cpPlugins_SYS_WINDOWS
175 #endif // __CPPLUGINS_CONFIG__H__