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 # ifndef WIN32_LEAN_AND_MEAN
38 # define WIN32_LEAN_AND_MEAN
43 #elif defined( linux ) || defined( __linux )
44 # define cpPlugins_SYS_LINUX
45 # define cpPlugins_LIB_PREFIX "lib"
46 # define cpPlugins_LIB_EXT "so"
47 #elif defined( __APPLE__ ) || defined( MACOSX ) || defined( macintosh ) || defined( Macintosh )
48 # define cpPlugins_SYS_MACOS
49 # define cpPlugins_LIB_PREFIX "lib"
50 # define cpPlugins_LIB_EXT "dylib"
51 #elif defined( __FreeBSD__ ) || defined( __FreeBSD_kernel__ )
52 # define cpPlugins_SYS_FREEBSD
53 # define cpPlugins_LIB_PREFIX "lib"
54 # define cpPlugins_LIB_EXT "so"
56 # error "This operating system is not supported by cpPlugins"
60 * =========================================================================
61 * Some helper functions
62 * =========================================================================
71 // -------------------------------------------------------------------------
72 #ifdef cpPlugins_SYS_WINDOWS
73 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
74 #else // cpPlugins_SYS_WINDOWS
75 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
76 #endif // cpPlugins_SYS_WINDOWS
78 // -------------------------------------------------------------------------
79 #define cpPlugins_CHRONO \
80 std::chrono::duration_cast< std::chrono::milliseconds >( \
81 std::chrono::system_clock::now( ).time_since_epoch( ) \
88 // ---------------------------------------------------------------------
89 inline bool operator()( char c ) const
91 #ifdef cpPlugins_SYS_WINDOWS
92 return( c == '\\' || c == '/' );
93 #else // cpPlugins_SYS_WINDOWS
95 #endif // cpPlugins_SYS_WINDOWS
99 // -----------------------------------------------------------------------
100 inline bool IsBlank( const char& value )
102 return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
105 // -----------------------------------------------------------------------
106 template< class _TTokens >
107 inline void TokenizeString(
108 _TTokens& tokens, const std::string& str, const std::string& delims
112 if( str.size( ) > 0 )
114 auto ssize = str.size( );
115 char* buffer = new char[ ssize + 1 ];
116 for( unsigned long i = 0; i < ssize; ++i )
117 buffer[ i ] = str[ i ];
118 buffer[ ssize ] = '\0';
120 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
123 tokens.push_back( std::string( it ) );
124 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
132 // -----------------------------------------------------------------------
133 inline std::string ReplaceString(
134 const std::string& str, const std::string& sub, const std::string& nsub
137 std::string res = str;
139 while( ( index = res.find( sub ) ) != std::string::npos )
140 res.replace( index, sub.size( ), nsub );
144 // -----------------------------------------------------------------------
145 inline bool ReadFileIntoString( std::string& buffer, const std::string& fname )
148 std::ifstream file_stream( fname.c_str( ) );
151 file_stream.seekg( 0, std::ios::end );
152 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
153 file_stream.seekg( 0, std::ios::beg );
155 ( std::istreambuf_iterator< char >( file_stream ) ),
156 std::istreambuf_iterator< char >( )
158 file_stream.close( );
162 // -----------------------------------------------------------------------
163 inline std::string CanonicalPath( const std::string& path )
165 std::string ret = "";
166 #ifdef cpPlugins_SYS_WINDOWS
167 TCHAR buffer[ 4096 ] = TEXT( "" );
168 TCHAR** lppPart = { NULL };
169 GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
170 ret = std::string( buffer );
171 #else // cpPlugins_SYS_WINDOWS
172 char* canonical_path = realpath( path.c_str( ), NULL );
173 if( canonical_path != NULL )
175 ret = canonical_path;
176 free( canonical_path );
179 #endif // cpPlugins_SYS_WINDOWS
185 #endif // __CPPLUGINS_CONFIG__H__