## == Functions, packages and options ==
## =====================================
-INCLUDE(cmake/DetectOS.cmake)
INCLUDE(cmake/Restrictions.cmake)
INCLUDE(cmake/Options.cmake)
INCLUDE(cmake/Functions.cmake)
#include <string>
// -------------------------------------------------------------------------
-#define @prj_NAME_OS@
-#ifdef @prj_NAME_OS@
-# define cpExtensions_STRTOK( A, B, N ) strtok_s( A, B, N )
-# define cpExtensions_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O );
-#else // @prj_NAME_OS@
-# define cpExtensions_STRTOK( A, B, N ) std::strtok( A, B )
-# define cpExtensions_SPRINTF( B, S, O ) std::sprintf( B, "%s", O );
-#endif // @prj_NAME_OS@
+#define cpPlugins_bash_OS_@CMAKE_SYSTEM_NAME@
+#ifdef cpPlugins_bash_OS_Windows
+# define cpPlugins_bash_STRTOK( A, B, N ) strtok_s( A, B, N )
+# define cpPlugins_bash_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O );
+#else // cpPlugins_bash_OS_Windows
+# define cpPlugins_bash_STRTOK( A, B, N ) std::strtok( A, B )
+# define cpPlugins_bash_SPRINTF( B, S, O ) std::sprintf( B, "%s", O );
+#endif // cpPlugins_bash_OS_Windows
// -------------------------------------------------------------------------
namespace cpPlugins_bash
buffer[ i ] = str[ i ];
buffer[ ssize ] = '\0';
char* next;
- char* it = cpExtensions_STRTOK( buffer, delims.c_str( ), &next );
+ char* it = cpPlugins_bash_STRTOK( buffer, delims.c_str( ), &next );
while( it != NULL )
{
tokens.push_back( std::string( it ) );
- it = cpExtensions_STRTOK( NULL, delims.c_str( ), &next );
+ it = cpPlugins_bash_STRTOK( NULL, delims.c_str( ), &next );
} // elihw
delete [] buffer;
int main( int argc, char* argv[] )
{
// Create interface and load library
- cpPlugins::Interface::Plugins::Pointer interface =
- cpPlugins::Interface::Plugins::New( );
+ typedef cpPlugins::Interface::Plugins TPlugins;
+ TPlugins::Pointer interface = TPlugins::New( );
try
{
interface->LoadEnvironments( );
std::string directory = argv[ 1 ];
// Create interface and load library
- cpPlugins::Interface::Plugins::Pointer interface =
- cpPlugins::Interface::Plugins::New( );
+ typedef cpPlugins::Interface::Plugins TPlugins;
+ TPlugins::Pointer interface = TPlugins::New( );
try
{
interface->LoadEnvironments( );
std::string library_file = argv[ 1 ];
// Create interface and load library
- cpPlugins::Interface::Plugins::Pointer interface =
- cpPlugins::Interface::Plugins::New( );
+ typedef cpPlugins::Interface::Plugins TPlugins;
+ TPlugins::Pointer interface = TPlugins::New( );
try
{
interface->LoadEnvironments( );
std::string plugin = argv[ 1 ];
// Create interface and load library
- cpPlugins::Interface::Plugins::Pointer interface =
- cpPlugins::Interface::Plugins::New( );
+ typedef cpPlugins::Interface::Plugins TPlugins;
+ TPlugins::Pointer interface = TPlugins::New( );
try
{
interface->LoadEnvironments( );
+++ /dev/null
-## =====================
-## == OS-based values ==
-## =====================
-
-SET(prj_NAME_OS "${prj_NAME}_OS_${CMAKE_SYSTEM_NAME}")
-IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
- SET(prj_NAME_LIB_PREFIX "lib")
- SET(prj_NAME_LIB_EXT ".so")
- SET(prj_NAME_ENV_SEPARATOR ":")
- SET(prj_NAME_PATH_SEPARATOR "/")
-ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
- SET(prj_NAME_LIB_PREFIX "lib")
- SET(prj_NAME_LIB_EXT ".dylib")
- SET(prj_NAME_ENV_SEPARATOR ":")
- SET(prj_NAME_PATH_SEPARATOR "/")
-ELSEIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
- SET(prj_NAME_LIB_PREFIX "")
- SET(prj_NAME_LIB_EXT ".dll")
- SET(prj_NAME_ENV_SEPARATOR ";")
- SET(prj_NAME_PATH_SEPARATOR "\\\\\\\\")
-ENDIF("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
-
-## eof - $RCSfile$
FUNCTION(
CreateLib
lib_name
+ lib_dir
lib_type
lib_source_files
lib_header_files
## -- Ok, compile library
IF(_sources)
NormPaths(_cur_binary_dir ${CMAKE_CURRENT_BINARY_DIR})
- ADD_LIBRARY(${lib_name} SHARED ${_sources} ${_headers})
+ ADD_LIBRARY(${lib_name} ${lib_type} ${_sources} ${_headers})
SET_TARGET_PROPERTIES(
${lib_name}
PROPERTIES
FUNCTION(
LibFromDir
lib_name
+ lib_dir
lib_type
lib_source_dir
lib_version
## -- Create library
CreateLib(
- ${lib_name} ${lib_type}
+ ${lib_name} ${lib_dir} ${lib_type}
"${_sources}" "${_headers}" "${_qt_uis}"
"${lib_version}" "${lib_short_version}"
)
FUNCTION(
CompileInstances
out_lib_name
+ lib_dir
def_file
number_of_files
prefix
## -- Create library
CreateLib(
- "${_lib_name}" SHARED
+ "${_lib_name}" ${lib_dir} SHARED
"${_all_out_code}" "${_out_header}" ""
"${version}" "${short_version}"
)
## -- Ok, build library
IF(_all_src)
CreateLib(
- ${_lib_name} SHARED
+ ${_lib_name} leo SHARED
"${_all_src}" "${_all_hdr}" "${_qt_ui}"
"${version}" "${short_version}"
${ARGN}
## == Third party libraries ==
## ===========================
-LibFromDir(cpPlugins_tinyxml2 SHARED ${_dir}/tinyxml2 ${_ver})
+LibFromDir(cpPlugins_tinyxml2 ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/tinyxml2 ${_ver})
IF(Qt4_FOUND)
- LibFromDir(cpPlugins_QCustomPlot SHARED ${_dir}/QCustomPlot ${_ver})
+ LibFromDir(cpPlugins_QCustomPlot ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/QCustomPlot ${_ver})
TARGET_LINK_LIBRARIES(cpPlugins_QCustomPlot ${QT_LIBRARIES})
ENDIF(Qt4_FOUND)
-LibFromDir(cpExtensions SHARED ${_dir}/cpExtensions ${_ver})
+LibFromDir(cpExtensions ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpExtensions ${_ver})
TARGET_LINK_LIBRARIES(cpExtensions ${ITK_LIBRARIES} ${VTK_LIBRARIES} ${QT_LIBRARIES})
## =====================
COMMAND ${cpPlugins_bash_BuildDemangleHeader_APP} "${_demangle_dir}/DemangleBase.h"
DEPENDS ${cpPlugins_bash_BuildDemangleHeader_APP}
)
-LibFromDir(cpPlugins SHARED ${_dir}/cpPlugins ${_ver} "${_demangle_dir}/DemangleBase.h")
+LibFromDir(cpPlugins ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpPlugins ${_ver} ${_demangle_dir}/DemangleBase.h)
TARGET_LINK_LIBRARIES(cpPlugins cpPlugins_tinyxml2 cpExtensions ${cpPlugins_Instances})
## ======================
## ======================
IF(Qt4_FOUND)
- LibFromDir(cpBaseQtApplication SHARED ${_dir}/cpBaseQtApplication ${_ver})
+ LibFromDir(cpBaseQtApplication ${PROJECT_BINARY_DIR}/lib SHARED ${_dir}/cpBaseQtApplication ${_ver})
TARGET_LINK_LIBRARIES(cpBaseQtApplication ${cpPlugins_LIB})
ENDIF(Qt4_FOUND)
## == Libraries to dynamically load ==
## ===================================
-SET(
- cpPlugins_DynLibs
- local@cpExtensions
- )
+SET(cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/bin|cpExtensions")
+LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/lib|cpExtensions")
+LIST(APPEND cpPlugins_DynLibs "${LIBRARY_OUTPUT_PATH}|cpExtensions")
FOREACH(_lib ${cpPlugins_Instances})
- LIST(APPEND cpPlugins_DynLibs local@${_lib})
-ENDFOREACH(_lib)
-FOREACH(_lib ${VTK_LIBRARIES})
- GET_TARGET_PROPERTY(_lib_${_lib} ${_lib} LOCATION)
- LIST(APPEND cpPlugins_DynLibs global@${_lib_${_lib}})
-ENDFOREACH(_lib)
-FOREACH(_lib ${ITK_LIBRARIES})
- GET_TARGET_PROPERTY(_lib_${_lib} ${_lib} LOCATION)
- LIST(APPEND cpPlugins_DynLibs global@${_lib_${_lib}})
+ LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/bin|${_lib}")
+ LIST(APPEND cpPlugins_DynLibs "${CMAKE_INSTALL_PREFIX}/lib|${_lib}")
+ LIST(APPEND cpPlugins_DynLibs "${LIBRARY_OUTPUT_PATH}|${_lib}")
ENDFOREACH(_lib)
+LIST(APPEND cpPlugins_DynLibs "${VTK_INSTALL_PREFIX}/bin|vtk*")
+LIST(APPEND cpPlugins_DynLibs "${VTK_INSTALL_PREFIX}/lib|vtk*")
+LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/bin|itk*")
+LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/lib|itk*")
+LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/bin|ITK*")
+LIST(APPEND cpPlugins_DynLibs "${ITK_INSTALL_PREFIX}/lib|ITK*")
FILE(WRITE ${PROJECT_BINARY_DIR}/cpPlugins_Libraries.config "")
FOREACH(_lib ${cpPlugins_DynLibs})
FILE(APPEND ${PROJECT_BINARY_DIR}/cpPlugins_Libraries.config "${_lib}\n")
FOREACH(_instance ${_instances})
CompileInstances(
_lib_name
+ ${PROJECT_BINARY_DIR}/lib
${_instance} ${cpPlugins_NUMBER_OF_FILES}
"" "${prj_VERSION}" "${prj_SHORT_VERSION}"
)
// Get the plugins interface
this->m_Plugins = TPlugins::New( );
- try { this->m_Plugins->OpenEnvironments( env.str( ) ); } catch( ... ) { }
- try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { }
+ try { this->m_Plugins->AddEnvironments( env.str( ) ); } catch( ... ) { }
this->updateEnvironment( );
+ try { this->m_Plugins->SavePaths( this->m_RunPath ); } catch( ... ) { }
// Create local workspace
this->m_Workspace = TWorkspace::New( );
_addEnvironmentPaths( const std::string& envs )
{
try { this->m_Plugins->AddEnvironments( envs ); } catch( ... ) { }
- try { this->m_Plugins->SaveEnvironments( this->m_RunPath ); } catch( ... ) { }
+ try { this->m_Plugins->SavePaths( this->m_RunPath ); } catch( ... ) { }
this->updateEnvironment( );
this->_updatePlugins( );
}
* Identify OS
* =========================================================================
*/
-#define @prj_NAME_OS@
-#define cpExtensions_LIB_PREFIX "@prj_NAME_LIB_PREFIX@"
-#define cpExtensions_LIB_EXT "@prj_NAME_LIB_EXT@"
-#define cpExtensions_ENV_SEPARATOR "@prj_NAME_ENV_SEPARATOR@"
-#define cpExtensions_PATH_SEPARATOR '@prj_NAME_PATH_SEPARATOR@'
+#define cpExtensions_OS_@CMAKE_SYSTEM_NAME@
+#ifdef cpExtensions_OS_Windows
+# define cpExtensions_LIB_PREFIX ""
+# define cpExtensions_ENV_SEPARATOR ";"
+# define cpExtensions_PATH_SEPARATOR '\\'
+# define cpExtensions_LIB_EXT ".dll"
+#else // cpExtensions_OS_Windows
+# define cpExtensions_LIB_PREFIX "lib"
+# define cpExtensions_ENV_SEPARATOR ":"
+# define cpExtensions_PATH_SEPARATOR '/'
+# ifdef cpExtensions_OS_Linux
+# define cpExtensions_LIB_EXT ".so"
+# else // cpExtensions_OS_Linux
+# define cpExtensions_LIB_EXT ".dylib"
+# endif // cpExtensions_OS_Linux
+#endif // cpExtensions_OS_Windows
-#ifdef cpPlugins_OS_Windows
+#ifdef cpExtensions_OS_Windows
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
-# endif
+# endif // WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
# include <tchar.h>
-#endif
+#endif // cpExtensions_OS_Windows
/*
* =========================================================================
#include <cpExtensions/Config.h>
// -------------------------------------------------------------------------
-#ifdef cpPlugins_OS_Windows
+#ifdef cpExtensions_OS_Windows
# define cpExtensions_STRTOK( A, B, N ) strtok_s( A, B, N )
# define cpExtensions_SPRINTF( B, S, O ) sprintf_s( B, S, "%s", O );
-#else // cpPlugins_OS_Windows
+#else // cpExtensions_OS_Windows
# define cpExtensions_STRTOK( A, B, N ) std::strtok( A, B )
# define cpExtensions_SPRINTF( B, S, O ) std::sprintf( B, "%s", O );
-#endif // cpPlugins_OS_Windows
+#endif // cpExtensions_OS_Windows
// -------------------------------------------------------------------------
#define cpExtensions_CHRONO \
// -----------------------------------------------------------------------
inline bool IsPathSeparator( char c )
{
-#ifdef cpPlugins_Windows
- return( c == '\\' || c == cpExtensions_PATH_SEPARATOR );
-#else // cpPlugins_Windows
+#ifdef cpExtensions_OS_Windows
+ return( c == '/' || c == cpExtensions_PATH_SEPARATOR );
+#else // cpExtensions_OS_Windows
return( c == cpExtensions_PATH_SEPARATOR );
-#endif // cpPlugins_Windows
+#endif // cpExtensions_OS_Windows
}
// -----------------------------------------------------------------------
inline std::string CanonicalPath( const std::string& path )
{
std::string ret = "";
-#ifdef cpPlugins_OS_Windows
+#ifdef cpExtensions_OS_Windows
TCHAR buffer[ 4096 ] = TEXT( "" );
TCHAR** lppPart = { NULL };
GetFullPathName( path.c_str( ), 4096, buffer, lppPart );
ret = std::string( buffer );
-#else // cpPlugins_OS_Windows
+#else // cpExtensions_OS_Windows
char* canonical_path = realpath( path.c_str( ), NULL );
if( canonical_path != NULL )
{
free( canonical_path );
} // fi
-#endif // cpPlugins_OS_Windows
+#endif // cpExtensions_OS_Windows
return( ret );
}
-#ifndef __@prj_NAME@__h__
-#define __@prj_NAME@__h__
+#ifndef __@prj_NAME@__Config__h__
+#define __@prj_NAME@__Config__h__
#define ITK_MANUAL_INSTANTIATION
#include <@prj_NAME@_Export.h>
* Identify OS
* =========================================================================
*/
-#define @prj_NAME_OS@
-#define @prj_NAME@_LIB_PREFIX "@prj_NAME_LIB_PREFIX@"
-#define @prj_NAME@_LIB_EXT "@prj_NAME_LIB_EXT@"
-#define @prj_NAME@_ENV_SEPARATOR "@prj_NAME_ENV_SEPARATOR@"
-#define @prj_NAME@_PATH_SEPARATOR "@prj_NAME_PATH_SEPARATOR@"
+#define @prj_NAME@_OS_@CMAKE_SYSTEM_NAME@
+#ifdef @prj_NAME@_OS_Windows
+# define @prj_NAME@_LIB_PREFIX ""
+# define @prj_NAME@_ENV_SEPARATOR ";"
+# define @prj_NAME@_PATH_SEPARATOR '\\'
+# define @prj_NAME@_LIB_EXT ".dll"
+#else // @prj_NAME@_OS_Windows
+# define @prj_NAME@_LIB_PREFIX "lib"
+# define @prj_NAME@_ENV_SEPARATOR ":"
+# define @prj_NAME@_PATH_SEPARATOR '/'
+# ifdef @prj_NAME@_OS_Linux
+# define @prj_NAME@_LIB_EXT ".so"
+# else // @prj_NAME@_OS_Linux
+# define @prj_NAME@_LIB_EXT ".dylib"
+# endif // @prj_NAME@_OS_Linux
+#endif // @prj_NAME@_OS_Windows
#ifdef @prj_NAME@_OS_Windows
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
-# endif
+# endif // WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
# include <tchar.h>
return( dynamic_cast< const Self* >( other ) != NULL ); \
}
-#endif // __@prj_NAME@__h__
+#endif // __@prj_NAME@__Config__h__
// eof - $RCSfile$
#include <cpPlugins/OS/DLLManager.h>
#include <cpPlugins/Interface/Dirent.h>
#include <cpExtensions/Utility.h>
+#include <regex>
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-AddEnvironments( const std::string& new_environment )
+AddEnvironments( const std::string& env )
{
- std::vector< std::string > tokens;
- cpExtensions::Tokenize( tokens, new_environment, cpPlugins_ENV_SEPARATOR );
- for( auto i = tokens.begin( ); i != tokens.end( ); ++i )
- {
- std::stringstream dir;
- dir << cpExtensions::CanonicalPath( *i );
- if( dir.str( ) != "" )
- this->m_Paths.insert( dir.str( ) );
-
- } // rof
+ std::vector< std::string > directories;
+ cpExtensions::Tokenize( directories, env, cpPlugins_ENV_SEPARATOR );
+ for( auto dir = directories.begin( ); dir != directories.end( ); ++dir )
+ this->m_Paths.insert( cpExtensions::CanonicalPath( *dir ) );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
LoadEnvironments( )
{
- std::stringstream all_errors;
+ std::set< std::string > libs;
for( auto d = this->m_Paths.begin( ); d != this->m_Paths.end( ); ++d )
{
- std::stringstream name;
- name << *d << cpPlugins_CONFIG;
+ std::stringstream fname;
+ fname << *d << cpPlugins_PATH_SEPARATOR << cpPlugins_CONFIG;
std::string buffer;
- if( cpExtensions::Read( buffer, name.str( ) ) )
+ if( cpExtensions::Read( buffer, fname.str( ) ) )
{
std::istringstream input( buffer );
for( std::string line; std::getline( input, line ); )
{
std::vector< std::string > tokens;
- cpExtensions::Tokenize( tokens, line, "@" );
- std::string library_file = "";
- if( tokens[ 0 ] == "local" )
- library_file =
- cpExtensions::CanonicalPath(
- *d + std::string( cpPlugins_LIB_PREFIX ) +
- tokens[ 1 ] + std::string( cpPlugins_LIB_EXT )
- );
- else if( tokens[ 0 ] == "global" )
- library_file = tokens[ 1 ];
-
- if( library_file != "" )
+ cpExtensions::Tokenize( tokens, line, "|" );
+ if( tokens.size( ) == 2 )
{
- std::string error = "";
- void* hnd = cpPlugins::OS::DLLManager::Load( library_file, error );
- if( hnd != NULL )
- this->m_Libraries[ library_file ] = hnd;
+ std::string pth = tokens[ 0 ];
+ std::string lib = tokens[ 1 ];
+ if( lib.find( "*" ) != std::string::npos )
+ {
+ std::string ext( cpPlugins_LIB_EXT );
+ DIR* dir;
+ struct dirent* ent;
+ if( ( dir = opendir( pth.c_str( ) ) ) != NULL )
+ {
+ while( ( ent = readdir( dir ) ) != NULL )
+ {
+ std::string fname( ent->d_name );
+ long pos = long( fname.size( ) ) - long( ext.size( ) );
+ if( pos > 0 )
+ {
+ if( fname.substr( pos ) == ext )
+ {
+ std::regex re( lib );
+std::smatch match;
+if( std::regex_search( fname, match, re ) && match.size( ) >= 1 )
+ {
+ std::stringstream str;
+ str
+ << pth << cpPlugins_PATH_SEPARATOR << fname;
+ libs.insert( str.str( ) );
+ } // fi
+
+ } // fi
+
+ } // fi
+
+ } // elihw
+ closedir( dir );
+
+ } // fi
+ }
else
- all_errors << " ; " << error;
+ {
+ std::stringstream str;
+ str
+ << pth << cpPlugins_PATH_SEPARATOR << cpPlugins_LIB_PREFIX
+ << lib << cpPlugins_LIB_EXT;
+ libs.insert( str.str( ) );
+
+ } // fi
} // fi
} // fi
} // rof
+ for( auto l = libs.begin( ); l != libs.end( ); ++l )
+ {
+ std::string lib = cpExtensions::CanonicalPath( *l );
+ if( lib != "" )
+ {
+ if( this->m_Libraries.find( lib ) == this->m_Libraries.end( ) )
+{
+ std::string error = "";
+ void* hnd = cpPlugins::OS::DLLManager::Load( lib, error );
+ if( hnd != NULL )
+ this->m_Libraries[ lib ] = hnd;
- // Throw errors
- if( all_errors.str( ) != "" )
- throw std::runtime_error(
- std::string( "Loading environment libraries errors: " ) +
- all_errors.str( )
- );
+} // fi
+
+ } // fi
+
+ } // rof
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-SaveEnvironments( const std::string& dir ) const
+LoadPaths( const std::string& dir )
{
- std::stringstream buffer;
- for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
- buffer << *i << std::endl;
-
- std::stringstream fname;
+ std::stringstream fname, envs;
fname << dir;
if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
fname << cpExtensions_PATH_SEPARATOR;
fname << cpPlugins_PATHS;
- if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
- throw std::runtime_error( "Error writing environment file." );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-OpenEnvironments( const std::string& dir )
-{
- std::vector< std::string > tokens;
- cpExtensions::Tokenize( tokens, dir, cpPlugins_ENV_SEPARATOR );
- for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt )
- {
- std::stringstream fname;
- fname << *tIt;
- if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
- fname << cpExtensions_PATH_SEPARATOR;
- fname << cpPlugins_PATHS;
std::string buffer;
if( cpExtensions::Read( buffer, fname.str( ) ) )
{
std::istringstream input( buffer );
- std::stringstream paths;
for( std::string line; std::getline( input, line ); )
- paths << line << cpPlugins_ENV_SEPARATOR;
- this->AddEnvironments( paths.str( ) );
- }
- else
- {
- bool success = true;
- try
- {
- this->LoadDirectory( dir );
- }
- catch( ... )
- {
- success = false;
-
- } // yrt
- if( success )
- this->AddEnvironments( dir );
+ envs << line << cpPlugins_ENV_SEPARATOR;
} // fi
+ if( envs.str( ).size( ) > 0 )
+ this->AddEnvironments( envs.str( ) );
+}
- } // rof
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+SavePaths( const std::string& dir ) const
+{
+ std::stringstream buffer;
+ for( auto i = this->m_Paths.begin( ); i != this->m_Paths.end( ); ++i )
+ buffer << *i << std::endl;
+
+ std::stringstream fname;
+ fname << dir;
+ if( !cpExtensions::IsPathSeparator( dir.back( ) ) )
+ fname << cpExtensions_PATH_SEPARATOR;
+ fname << cpPlugins_PATHS;
+ if( !cpExtensions::Write( buffer.str( ), fname.str( ) ) )
+ throw std::runtime_error( "Error writing environment file." );
}
// -------------------------------------------------------------------------
if( p != NULL )
str << p << cpPlugins_ENV_SEPARATOR;
str << ".";
- this->OpenEnvironments( str.str( ) );
-
- // Try to read locally defined paths
- /* TODO
- std::vector< std::string > tokens;
- cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
- for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
- {
- try
- {
- this->OpenEnvironments( *t );
- }
- catch( ... ) { }
-
- } // rof
- */
+ this->AddEnvironments( str.str( ) );
}
// -------------------------------------------------------------------------
TStrings GetCategories( ) const;
TStrings GetFilters( const std::string& category ) const;
- void AddEnvironments( const std::string& new_environment );
+ void AddEnvironments( const std::string& env );
void LoadEnvironments( );
- void SaveEnvironments( const std::string& dir ) const;
- void OpenEnvironments( const std::string& dir );
+ void LoadPaths( const std::string& dir );
+ void SavePaths( const std::string& dir ) const;
void LoadFile( const std::string& fname );
void LoadPlugin( const std::string& pname );
{
void* hnd = NULL;
#ifdef cpPlugins_OS_Windows
+ UINT old = ::SetErrorMode( SEM_FAILCRITICALERRORS );
+ ::SetErrorMode( old | SEM_FAILCRITICALERRORS );
hnd = ::LoadLibraryA( fname.c_str( ) );
+ ::SetErrorMode( old );
+ if( hnd == NULL )
+ error = "Could not load library.";
#else // cpPlugins_OS_Windows
hnd = dlopen( fname.c_str( ), RTLD_LAZY | RTLD_GLOBAL );
if( hnd == NULL )
auto filter = this->_CreateITK< _TFilter >( );
filter->ClearPoints( );
double pnt[ 3 ];
- for( unsigned long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
+ for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
{
mesh->GetPoint( i, pnt );
filter->AddPoint( pnt[ 0 ], pnt[ 1 ] );