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 * =========================================================================
60 #ifdef cpPlugins_SYS_WINDOWS
61 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
62 #else // cpPlugins_SYS_WINDOWS
63 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
64 #endif // cpPlugins_SYS_WINDOWS
70 // ---------------------------------------------------------------------
71 inline bool operator()( char c ) const
73 #ifdef cpPlugins_SYS_WINDOWS
74 return( c == '\\' || c == '/' );
75 #else // cpPlugins_SYS_WINDOWS
77 #endif // cpPlugins_SYS_WINDOWS
81 // -----------------------------------------------------------------------
82 inline bool IsBlank( const char& value )
84 return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
87 // -----------------------------------------------------------------------
88 template< class _TTokens >
89 inline void TokenizeString(
90 _TTokens& tokens, const std::string& str, const std::string& delims
96 auto ssize = str.size( );
97 char* buffer = new char[ ssize + 1 ];
98 for( unsigned long i = 0; i < ssize; ++i )
99 buffer[ i ] = str[ i ];
100 buffer[ ssize ] = '\0';
102 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
105 tokens.push_back( std::string( it ) );
106 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
114 // -----------------------------------------------------------------------
115 inline std::string ReplaceString(
116 const std::string& str, const std::string& sub, const std::string& nsub
119 std::string res = str;
121 while( ( index = res.find( sub ) ) != std::string::npos )
122 res.replace( index, sub.size( ), nsub );
126 // -----------------------------------------------------------------------
127 inline bool ReadFileIntoString( std::string& buffer, const std::string& fname )
130 std::ifstream file_stream( fname.c_str( ) );
133 file_stream.seekg( 0, std::ios::end );
134 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
135 file_stream.seekg( 0, std::ios::beg );
137 ( std::istreambuf_iterator< char >( file_stream ) ),
138 std::istreambuf_iterator< char >( )
140 file_stream.close( );
144 // -----------------------------------------------------------------------
145 inline std::string CanonicalPath( const std::string& path )
147 std::string ret = "";
148 #ifdef cpPlugins_SYS_WINDOWS
149 TCHAR buffer[ 4096 ] = TEXT( "" );
150 TCHAR** lppPart = { NULL };
151 GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
152 ret = std::string( buffer );
153 #else // cpPlugins_SYS_WINDOWS
154 char* canonical_path = realpath( path.c_str( ), NULL );
155 if( canonical_path != NULL )
157 ret = canonical_path;
158 free( canonical_path );
161 #endif // cpPlugins_SYS_WINDOWS
167 #endif // __CPPLUGINS_CONFIG__H__