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 #include <vtkConfigure.h>
26 #endif // VTK_OVERRIDE
29 * =========================================================================
31 * =========================================================================
33 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
34 # define cpPlugins_SYS_WINDOWS
35 # define cpPlugins_LIB_PREFIX ""
36 # define cpPlugins_LIB_EXT "dll"
37 # define cpPlugins_SEPARATOR ";"
38 # ifndef WIN32_LEAN_AND_MEAN
39 # define WIN32_LEAN_AND_MEAN
44 #elif defined( linux ) || defined( __linux )
45 # define cpPlugins_SYS_LINUX
46 # define cpPlugins_LIB_PREFIX "lib"
47 # define cpPlugins_LIB_EXT "so"
48 # define cpPlugins_SEPARATOR ":"
49 #elif defined( __APPLE__ ) || defined( MACOSX ) || defined( macintosh ) || defined( Macintosh )
50 # define cpPlugins_SYS_MACOS
51 # define cpPlugins_LIB_PREFIX "lib"
52 # define cpPlugins_LIB_EXT "dylib"
53 # define cpPlugins_SEPARATOR ":"
54 #elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
55 # define cpPlugins_SYS_FREEBSD
56 # define cpPlugins_LIB_PREFIX "lib"
57 # define cpPlugins_LIB_EXT "so"
58 # define cpPlugins_SEPARATOR ":"
60 # error "This operating system is not supported by cpPlugins"
64 * =========================================================================
65 * Some helper functions
66 * =========================================================================
75 // -------------------------------------------------------------------------
76 #ifdef cpPlugins_SYS_WINDOWS
77 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
78 #else // cpPlugins_SYS_WINDOWS
79 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
80 #endif // cpPlugins_SYS_WINDOWS
82 // -------------------------------------------------------------------------
83 #define cpPlugins_CHRONO \
84 std::chrono::duration_cast< std::chrono::milliseconds >( \
85 std::chrono::system_clock::now( ).time_since_epoch( ) \
92 // ---------------------------------------------------------------------
93 inline bool operator()( char c ) const
95 #ifdef cpPlugins_SYS_WINDOWS
96 return( c == '\\' || c == '/' );
97 #else // cpPlugins_SYS_WINDOWS
99 #endif // cpPlugins_SYS_WINDOWS
103 // -----------------------------------------------------------------------
104 inline bool IsBlank( const char& value )
106 return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
109 // -----------------------------------------------------------------------
110 template< class _TTokens >
111 inline void TokenizeString(
112 _TTokens& tokens, const std::string& str, const std::string& delims
116 if( str.size( ) > 0 )
118 auto ssize = str.size( );
119 char* buffer = new char[ ssize + 1 ];
120 for( unsigned long i = 0; i < ssize; ++i )
121 buffer[ i ] = str[ i ];
122 buffer[ ssize ] = '\0';
124 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
127 tokens.push_back( std::string( it ) );
128 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
136 // -----------------------------------------------------------------------
137 inline std::string ReplaceString(
138 const std::string& str, const std::string& sub, const std::string& nsub
141 std::string res = str;
143 while( ( index = res.find( sub ) ) != std::string::npos )
144 res.replace( index, sub.size( ), nsub );
148 // -----------------------------------------------------------------------
149 inline bool ReadFileIntoString( std::string& buffer, const std::string& fname )
152 std::ifstream file_stream( fname.c_str( ) );
155 file_stream.seekg( 0, std::ios::end );
156 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
157 file_stream.seekg( 0, std::ios::beg );
159 ( std::istreambuf_iterator< char >( file_stream ) ),
160 std::istreambuf_iterator< char >( )
162 file_stream.close( );
166 // -----------------------------------------------------------------------
167 inline std::string CanonicalPath( const std::string& path )
169 std::string ret = "";
170 #ifdef cpPlugins_SYS_WINDOWS
171 TCHAR buffer[ 4096 ] = TEXT( "" );
172 TCHAR** lppPart = { NULL };
173 GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
174 ret = std::string( buffer );
175 #else // cpPlugins_SYS_WINDOWS
176 char* canonical_path = realpath( path.c_str( ), NULL );
177 if( canonical_path != NULL )
179 ret = canonical_path;
180 free( canonical_path );
183 #endif // cpPlugins_SYS_WINDOWS
189 #endif // __CPPLUGINS_CONFIG__H__