1 #ifndef __CPPLUGINS_CONFIG__H__
2 #define __CPPLUGINS_CONFIG__H__
5 * =========================================================================
7 * =========================================================================
9 #define cpPlugins_PATHS "cpPlugins_PATHS"
12 * =========================================================================
14 * =========================================================================
17 #define ITK_MANUAL_INSTANTIATION
18 #ifndef ITK_DELETE_FUNCTION
19 # define ITK_DELETE_FUNCTION
20 #endif // ITK_DELETE_FUNCTION
23 #endif // ITK_OVERRIDE
26 * =========================================================================
28 * =========================================================================
30 #include <vtkConfigure.h>
33 #endif // VTK_OVERRIDE
36 * =========================================================================
38 * =========================================================================
40 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
41 # define cpPlugins_SYS_WINDOWS
42 # define cpPlugins_LIB_PREFIX ""
43 # define cpPlugins_LIB_EXT "dll"
44 # define cpPlugins_SEPARATOR ";"
45 # ifndef WIN32_LEAN_AND_MEAN
46 # define WIN32_LEAN_AND_MEAN
51 #elif defined( linux ) || defined( __linux )
52 # define cpPlugins_SYS_LINUX
53 # define cpPlugins_LIB_PREFIX "lib"
54 # define cpPlugins_LIB_EXT "so"
55 # define cpPlugins_SEPARATOR ":"
56 #elif defined( __APPLE__ ) || defined( MACOSX ) || defined( macintosh ) || defined( Macintosh )
57 # define cpPlugins_SYS_MACOS
58 # define cpPlugins_LIB_PREFIX "lib"
59 # define cpPlugins_LIB_EXT "dylib"
60 # define cpPlugins_SEPARATOR ":"
61 #elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
62 # define cpPlugins_SYS_FREEBSD
63 # define cpPlugins_LIB_PREFIX "lib"
64 # define cpPlugins_LIB_EXT "so"
65 # define cpPlugins_SEPARATOR ":"
67 # error "This operating system is not supported by cpPlugins"
71 * =========================================================================
72 * Some helper functions
73 * =========================================================================
82 // -------------------------------------------------------------------------
83 #ifdef cpPlugins_SYS_WINDOWS
84 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
85 #else // cpPlugins_SYS_WINDOWS
86 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
87 #endif // cpPlugins_SYS_WINDOWS
89 // -------------------------------------------------------------------------
90 #define cpPlugins_CHRONO \
91 std::chrono::duration_cast< std::chrono::milliseconds >( \
92 std::chrono::system_clock::now( ).time_since_epoch( ) \
99 // ---------------------------------------------------------------------
100 inline bool operator()( char c ) const
102 #ifdef cpPlugins_SYS_WINDOWS
103 return( c == '\\' || c == '/' );
104 #else // cpPlugins_SYS_WINDOWS
106 #endif // cpPlugins_SYS_WINDOWS
110 // -----------------------------------------------------------------------
111 inline bool IsBlank( const char& v )
113 return( v == ' ' || v == '\t' || v == '\n' || v == '\r' );
116 // -----------------------------------------------------------------------
117 template< class _TTokens >
118 inline void TokenizeString(
119 _TTokens& tokens, const std::string& str, const std::string& delims
123 if( str.size( ) > 0 )
125 auto ssize = str.size( );
126 char* buffer = new char[ ssize + 1 ];
127 for( unsigned long i = 0; i < ssize; ++i )
128 buffer[ i ] = str[ i ];
129 buffer[ ssize ] = '\0';
131 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
134 tokens.push_back( std::string( it ) );
135 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
143 // -----------------------------------------------------------------------
144 inline std::string ReplaceString(
145 const std::string& str, const std::string& sub, const std::string& nsub
148 std::string res = str;
150 while( ( index = res.find( sub ) ) != std::string::npos )
151 res.replace( index, sub.size( ), nsub );
155 // -----------------------------------------------------------------------
156 inline bool ReadFileIntoString(
157 std::string& buffer, const std::string& fname
161 std::ifstream file_stream( fname.c_str( ) );
164 file_stream.seekg( 0, std::ios::end );
165 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
166 file_stream.seekg( 0, std::ios::beg );
168 ( std::istreambuf_iterator< char >( file_stream ) ),
169 std::istreambuf_iterator< char >( )
171 file_stream.close( );
175 // -----------------------------------------------------------------------
176 inline std::string CanonicalPath( const std::string& path )
178 std::string ret = "";
179 #ifdef cpPlugins_SYS_WINDOWS
180 TCHAR buffer[ 4096 ] = TEXT( "" );
181 TCHAR** lppPart = { NULL };
182 GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
183 ret = std::string( buffer );
184 #else // cpPlugins_SYS_WINDOWS
185 char* canonical_path = realpath( path.c_str( ), NULL );
186 if( canonical_path != NULL )
188 ret = canonical_path;
189 free( canonical_path );
192 #endif // cpPlugins_SYS_WINDOWS
198 #endif // __CPPLUGINS_CONFIG__H__