diff --git a/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h b/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h index add5ec353b2494d3bc0c6bb57116711eb0261f1b..f47c4d3ec98ceb641c1e0b03b328cd15230bbdff 100644 --- a/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h +++ b/Modules/Applications/AppClassification/app/otbTrainImagesClassifier.h @@ -19,7 +19,6 @@ #include "otbWrapperApplicationFactory.h" #include <iostream> -#include "otbConfigurationFile.h" //Image #include "otbVectorImage.h" diff --git a/Modules/Core/Common/include/otbConfigurationFile.h b/Modules/Core/Common/include/otbConfigurationFile.h deleted file mode 100644 index c90de810875b8550a0f3a2176f4db361bdad0fd6..0000000000000000000000000000000000000000 --- a/Modules/Core/Common/include/otbConfigurationFile.h +++ /dev/null @@ -1,117 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __otbConfigurationFile_h -#define __otbConfigurationFile_h - -#include "otbConfigure.h" - -#include "itkObject.h" -#include "itkObjectFactory.h" -#include "otb_configfile.h" -#include "itksys/FundamentalType.h" - -namespace otb -{ - -/** \class ConfigurationFile - * \brief Manage OTB ConfigurationFile file - * - * The path to the file can be set with environment variable OTB_CONFIG_FILE - * - * - * \ingroup OTBCommon -*/ - -class ConfigurationFile - : public itk::Object -{ -public: - /** Standard class typedef */ - - typedef ConfigurationFile Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Standard macro */ - itkTypeMacro(ConfigurationFile, Object); - - /** Get the unique instanc1e of the model */ - static Pointer GetInstance(); - - ConfigFile * GetOTBConfig(); - - bool IsValid() const; - - bool HasKey(const std::string& key) const; - - /** Get parameter*/ - template<typename T> T GetParameter(const std::string& key) const - { - if (m_OTBConfig == NULL) - { - itkExceptionMacro(<< "Configuration file not found."); - } - - try - { - return m_OTBConfig->read<T>(key); - } - catch (ConfigFile::key_not_found& e) - { - itkExceptionMacro(<< "Error - Key '" << e.key << "' not found."); - } - } - - /** Returns the DEM directory entry in the config file, or an empty string if not found */ - std::string GetDEMDirectory() const; - - /** Returns the Geoid entry in the config file, or an empty string if not found */ - std::string GetGeoidFile() const; - - /** Returns the available RAM in bytes */ - ::itksysFundamentalType_UInt64 GetAvailableRAMInBytes() const; - - /** Returns the available RAM in MBytes*/ - ::itksysFundamentalType_UInt64 GetAvailableRAMInMBytes() const - { - return static_cast< ::itksysFundamentalType_UInt64 >(GetAvailableRAMInBytes() / 1024 / 1024); - } - -protected: - /** This is protected for the singleton. Use GetInstance() instead. */ - itkNewMacro(Self); - /** Constructor */ - ConfigurationFile(); - - /** Destructor */ - virtual ~ConfigurationFile(); - /** PrintSelf method */ - void PrintSelf(std::ostream& os, itk::Indent indent) const; - -private: - - /** Try to instanciate a ConfigFile from a path. Return NULL on error */ - ConfigFile * LoadSilent(std::string path); - - /** The instance singleton */ - static Pointer Instance; - ConfigFile * m_OTBConfig; -}; -} // end namespace -#endif diff --git a/Modules/Core/Common/otb-module.cmake b/Modules/Core/Common/otb-module.cmake index aa8758bf56771ae1f5b3c6b78bd9ffa6d25d2f2d..51a3ba82f10fbabcfb767440df3e698ebd736402 100644 --- a/Modules/Core/Common/otb-module.cmake +++ b/Modules/Core/Common/otb-module.cmake @@ -4,7 +4,6 @@ otb_module(OTBCommon DEPENDS OTBITKPendingPatches OTBITK - OTBConfigFile TEST_DEPENDS OTBTestKernel DESCRIPTION diff --git a/Modules/Core/Common/src/CMakeLists.txt b/Modules/Core/Common/src/CMakeLists.txt index dec107c7220c2390dca2ef471185855c367da3ae..9652e6ec1d1a40b19c6d81a9e16d9617bb52a1b0 100644 --- a/Modules/Core/Common/src/CMakeLists.txt +++ b/Modules/Core/Common/src/CMakeLists.txt @@ -5,7 +5,7 @@ set(OTBCommon_SRC otbSystem.cxx otbStandardWriterWatcher.cxx otbUtils.cxx - otbConfigurationFile.cxx + otbConfigurationManager.cxx otbStandardOneLineFilterWatcher.cxx otbWriterWatcherBase.cxx otbCommandLineArgumentParser.cxx @@ -13,7 +13,6 @@ set(OTBCommon_SRC add_library(OTBCommon ${OTBCommon_SRC}) target_link_libraries(OTBCommon - ${OTBConfigFile_LIBRARIES} ${OTBITK_LIBRARIES} ) diff --git a/Modules/Core/Common/src/otbConfigurationFile.cxx b/Modules/Core/Common/src/otbConfigurationFile.cxx deleted file mode 100644 index 5863f29bdb8614c55fb02050f31c593f029ebd5c..0000000000000000000000000000000000000000 --- a/Modules/Core/Common/src/otbConfigurationFile.cxx +++ /dev/null @@ -1,218 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "otbConfigurationFile.h" -#include "otbMacro.h" -#include "itksys/SystemTools.hxx" - -namespace otb -{ -/** Initialize the singleton */ -ConfigurationFile::Pointer ConfigurationFile::Instance = NULL; - -ConfigurationFile -::ConfigurationFile() -{ - m_OTBConfig = NULL; - - const char* envVar = itksys::SystemTools::GetEnv("OTB_CONFIG_FILE"); - if (envVar) - { - if (!itksys::SystemTools::FileExists(envVar, true)) - { - itkWarningMacro(<< "When loading the OTB configuration file, " - "the OTB_CONFIG_FILE env. var was found, but points a non-existant file : " - << envVar); - } - else - { - m_OTBConfig = LoadSilent(envVar); - } - } -} - -ConfigurationFile -::~ConfigurationFile() -{ - delete m_OTBConfig; -} - -ConfigFile * -ConfigurationFile -::LoadSilent(std::string path) -{ - ConfigFile * config = NULL; - try - { - config = new ConfigFile(path); - } - catch (...) - { - otbMsgDevMacro(<< "Unable to load config file from " << path ); - } - - return config; -} - - -ConfigFile * -ConfigurationFile -::GetOTBConfig() -{ - return m_OTBConfig; -} - -bool -ConfigurationFile -::IsValid() const -{ - return m_OTBConfig != NULL; -} - -bool -ConfigurationFile -::HasKey(const std::string& key) const -{ - return m_OTBConfig != NULL && m_OTBConfig->keyExists(key); -} - -std::string -ConfigurationFile -::GetDEMDirectory() const -{ - std::string ret; - - if (HasKey("OTB_DEM_DIRECTORY")) - { - std::string fromConfigFile; - try - { - fromConfigFile = GetParameter<std::string> ("OTB_DEM_DIRECTORY"); - } - catch (itk::ExceptionObject& ex) - { - std::stringstream oss; - oss << "Error caught when accessing OTB_DEM_DIRECTORY in the config file."; - oss << "The error was " << ex; - otbMsgDevMacro( << oss.str() ); - } - - if ( !itksys::SystemTools::FileExists(fromConfigFile.c_str()) ) - { - otbMsgDevMacro( << "Error caught when accessing OTB_DEM_DIRECTORY in the config file: " - << fromConfigFile << " does not exist on the file system" ); - } - else if ( !itksys::SystemTools::FileIsDirectory(fromConfigFile.c_str()) ) - { - otbMsgDevMacro( << "Error caught when accessing OTB_DEM_DIRECTORY in the config file: " - << fromConfigFile << " is not a directory" ); - } - else - { - ret = fromConfigFile; - } - } - return ret; -} - -std::string -ConfigurationFile -::GetGeoidFile() const -{ - std::string ret; - - if (HasKey("OTB_GEOID_FILE")) - { - std::string fromConfigFile; - try - { - fromConfigFile = GetParameter<std::string> ("OTB_GEOID_FILE"); - } - catch (itk::ExceptionObject& ex) - { - std::stringstream oss; - oss << "Error caught when accessing OTB_GEOID_FILE in the config file."; - oss << "The error was " << ex; - otbMsgDevMacro( << oss.str() ); - } - - if ( !itksys::SystemTools::FileExists(fromConfigFile.c_str()) ) - { - otbMsgDevMacro( << "Error caught when accessing OTB_GEOID_FILE in the config file: " - << fromConfigFile << " does not exist on the file system" ); - } - else if ( itksys::SystemTools::FileIsDirectory(fromConfigFile.c_str()) ) - { - otbMsgDevMacro( << "Error caught when accessing OTB_GEOID_FILE in the config file: " - << fromConfigFile << " is a directory" ); - } - else - { - ret = fromConfigFile; - } - } - return ret; -} - -::itksysFundamentalType_UInt64 -ConfigurationFile -::GetAvailableRAMInBytes() const -{ - ::itksysFundamentalType_UInt64 availableRAMInBytes = 0; - - otbMsgDevMacro(<< "Retrieving available RAM size from configuration"); - // Retrieve it from the configuration - try - { - typedef otb::ConfigurationFile ConfigurationType; - ConfigurationType::Pointer conf = ConfigurationType::GetInstance(); - - availableRAMInBytes = conf->GetParameter< ::itksysFundamentalType_UInt64 >( - "OTB_STREAM_MAX_SIZE_BUFFER_FOR_STREAMING"); - } - catch(...) - { - // We should never have to go here if the configuration file is - // correct and found. - // In case it is not, fallback on the cmake - // defined constants. - return OTB_STREAM_MAX_SIZE_BUFFER_FOR_STREAMING; - } - return availableRAMInBytes; -} - -ConfigurationFile::Pointer -ConfigurationFile -::GetInstance() -{ - if (!Instance) - { - Instance = Self::New(); - } - return Instance; -} - -void -ConfigurationFile -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent; - os << (*m_OTBConfig); - -} -} // end namespace otb diff --git a/Modules/Core/Common/test/CMakeLists.txt b/Modules/Core/Common/test/CMakeLists.txt index fe3c256e13911c7d4bbc4aa9c75fe1d2d5d05071..05f7d4eb53edd68fab279ff1744718b045dfde8d 100644 --- a/Modules/Core/Common/test/CMakeLists.txt +++ b/Modules/Core/Common/test/CMakeLists.txt @@ -8,7 +8,6 @@ otbImageRegionTileMapSplitter.cxx otbCompareAsciiTestScientificNotation.cxx otbImageRegionAdaptativeSplitter.cxx otbRGBAPixelConverter.cxx -otbConfigurationTest.cxx otbRectangle.cxx otbCompareAsciiTests4.cxx otbCompareAsciiTests3.cxx @@ -25,6 +24,7 @@ otbCompareAsciiTests2.cxx otbImageRegionNonUniformMultidimensionalSplitter.cxx otbCompareAsciiTests5.cxx otbRectangleNew.cxx +otbConfigurationManagerTest.cxx ) add_executable(otbCommonTestDriver ${OTBCommonTests}) @@ -110,10 +110,6 @@ otb_add_test(NAME coTvRGBAPixelConverter COMMAND otbCommonTestDriver otbRGBAPixelConverter ) -otb_add_test(NAME coTuConfigurationTestDEM COMMAND otbCommonTestDriver - otbConfigurationTestDEM - ) - otb_add_test(NAME coTvRectangle COMMAND otbCommonTestDriver --compare-ascii ${EPSILON_3} ${BASELINE_FILES}/otbRectangleTest.txt @@ -310,3 +306,16 @@ otb_add_test(NAME tsTvCompareAscii5epsilon2 COMMAND otbCommonTestDriver otb_add_test(NAME coTuRectangleNew COMMAND otbCommonTestDriver otbRectangleNew) +otb_add_test(NAME coTvConfigurationManagerDefault COMMAND otbCommonTestDriver + otbConfigurationManagerTest + 128) + + + +otb_add_test(NAME coTvConfigurationManagerEnvVar COMMAND otbTestDriver + --add-before-env OTB_MAX_RAM_HINT "256" + --add-before-env OTB_DEM_DIRECTORY "/path/to/dem/" + --add-before-env OTB_GEOID_FILE "/path/to/geoid.file" + Execute $<TARGET_FILE:otbCommonTestDriver> + otbConfigurationManagerTest + 256 /path/to/dem/ /path/to/geoid.file) diff --git a/Modules/Core/Common/test/otbCommonTestDriver.cxx b/Modules/Core/Common/test/otbCommonTestDriver.cxx index 7f21e3796143f041bf9f876c210531e1044a0717..b158c4d2b1fc5252a03af3f96d00151a5920fab0 100644 --- a/Modules/Core/Common/test/otbCommonTestDriver.cxx +++ b/Modules/Core/Common/test/otbCommonTestDriver.cxx @@ -9,8 +9,6 @@ void RegisterTests() REGISTER_TEST(otbImageRegionAdaptativeSplitter); REGISTER_TEST(otbRGBAPixelConverterNew); REGISTER_TEST(otbRGBAPixelConverter); - REGISTER_TEST(otbConfigurationTest); - REGISTER_TEST(otbConfigurationTestDEM); REGISTER_TEST(otbRectangle); REGISTER_TEST(otbCompareAsciiTests4); REGISTER_TEST(otbCompareAsciiTests3); @@ -30,4 +28,5 @@ void RegisterTests() REGISTER_TEST(otbImageRegionNonUniformMultidimensionalSplitter); REGISTER_TEST(otbCompareAsciiTests5); REGISTER_TEST(otbRectangleNew); + REGISTER_TEST(otbConfigurationManagerTest); } diff --git a/Modules/Core/Common/test/otbConfigurationTest.cxx b/Modules/Core/Common/test/otbConfigurationTest.cxx deleted file mode 100644 index f48578c2bc0dcf920a82ef3febb073a8d630c4a2..0000000000000000000000000000000000000000 --- a/Modules/Core/Common/test/otbConfigurationTest.cxx +++ /dev/null @@ -1,94 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "otbMacro.h" -#include <fstream> -#include "otbConfigurationFile.h" - -int otbConfigurationTest(int itkNotUsed(argc), char * itkNotUsed(argv) []) -{ - -// std::cout << "begin config test" << std::endl; - typedef otb::ConfigurationFile ConfigurationType; - - //Instantiation -// ConfigurationType::Pointer conf = ConfigurationType::GetInstance(); - ConfigurationType::Pointer conf = ConfigurationType::GetInstance(); -// conf->Load(); - std::string lang; - try - { - lang = conf->GetParameter<std::string> ("OTB_LANG"); - } - catch (...) - { - std::cout << "Can't get parameter " << lang << std::endl; - return EXIT_FAILURE; - } - std::cout << conf << std::endl; - - if (lang.compare("fr_FR.UTF-8") != 0 && lang.compare("en_EN.UTF-8") != 0) - { - std::cout << "Locale language " << lang << std::endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - - -int otbConfigurationTestDEM(int argc, char *argv[]) -{ - std::string demDir = otb::ConfigurationFile::GetInstance()->GetDEMDirectory(); - - if (argc > 1) - { - // expected something - std::string expected = argv[1]; - - if (demDir.empty()) - { - std::cerr << "GetDEMDirectory returned nothing but " << expected << " was expected" << std::endl; - return EXIT_FAILURE; - } - else - { - if (demDir == expected) - { - return EXIT_SUCCESS; - } - else - { - std::cerr << "GetDEMDirectory returned " << demDir << " but " << expected << " was expected" << std::endl; - return EXIT_FAILURE; - } - } - } - else - { - if (!demDir.empty()) - { - std::cerr << "GetDEMDirectory returned " << demDir << " but nothing was expected" << std::endl; - return EXIT_FAILURE; - } - else - { - return EXIT_SUCCESS; - } - } - return EXIT_SUCCESS; -} diff --git a/Modules/ThirdParty/ConfigFile/CMakeLists.txt b/Modules/ThirdParty/ConfigFile/CMakeLists.txt deleted file mode 100644 index ea9aeea8cb2b3ec0bc8fa54f4ed1c6de56c3e7c5..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -project(OTBConfigFile) -set(OTBConfigFile_THIRD_PARTY 1) - -set(OTBConfigFile_LIBRARIES - otbconfigfile - ) - -set(OTBConfigFile_INCLUDE_DIRS - ${OTBConfigFile_SOURCE_DIR}/src - ) - -otb_module_impl() diff --git a/Modules/ThirdParty/ConfigFile/otb-module.cmake b/Modules/ThirdParty/ConfigFile/otb-module.cmake deleted file mode 100644 index fc2bfa3c73a54e762655370bcde4db6be307e4f8..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/otb-module.cmake +++ /dev/null @@ -1,10 +0,0 @@ -set(DOCUMENTATION "This module imports ConfigFile to the build system") - -otb_module(OTBConfigFile - DEPENDS - - TEST_DEPENDS - - DESCRIPTION - "${DOCUMENTATION}" - ) diff --git a/Modules/ThirdParty/ConfigFile/src/CMakeLists.txt b/Modules/ThirdParty/ConfigFile/src/CMakeLists.txt deleted file mode 100644 index 8524fa75dba6e3ab03d2e9d7049e680be49d9660..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(OTB3P_INSTALL_EXPORT_NAME "${OTBConfigFile-targets}") -set(OTB3P_INSTALL_INCLUDE_DIR "${OTBConfigFile_INSTALL_INCLUDE_DIR}") -set(OTB3P_INSTALL_RUNTIME_DIR "${OTBConfigFile_INSTALL_RUNTIME_DIR}") -set(OTB3P_INSTALL_LIBRARY_DIR "${OTBConfigFile_INSTALL_LIBRARY_DIR}") -set(OTB3P_INSTALL_ARCHIVE_DIR "${OTBConfigFile_INSTALL_ARCHIVE_DIR}") - -add_subdirectory(otbconfigfile) -otb_module_target(otbconfigfile NO_INSTALL) - -install(FILES otb_configfile.h - DESTINATION ${OTBConfigFile_INSTALL_INCLUDE_DIR} - COMPONENT Development - ) diff --git a/Modules/ThirdParty/ConfigFile/src/otb_configfile.h b/Modules/ThirdParty/ConfigFile/src/otb_configfile.h deleted file mode 100644 index ce509eef6c268d67967c4b7525be96cb2b47176f..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/otb_configfile.h +++ /dev/null @@ -1,22 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __otb_configfile_h - -#include "otbconfigfile/ConfigFile.h" - -#endif diff --git a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/CMakeLists.txt b/Modules/ThirdParty/ConfigFile/src/otbconfigfile/CMakeLists.txt deleted file mode 100644 index 9daebb27eaeb7e3671904a117108cd3e3d6ae9b9..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# TODO : upgrade to latest libsvm >= 3.19 - -set(OTB3P_INSTALL_EXPORT_NAME "${OTBConfigFile-targets}") -set(OTB3P_INSTALL_INCLUDE_DIR "${OTBConfigFile_INSTALL_INCLUDE_DIR}") -set(OTB3P_INSTALL_RUNTIME_DIR "${OTBConfigFile_INSTALL_RUNTIME_DIR}") -set(OTB3P_INSTALL_LIBRARY_DIR "${OTBConfigFile_INSTALL_LIBRARY_DIR}") -set(OTB3P_INSTALL_ARCHIVE_DIR "${OTBConfigFile_INSTALL_ARCHIVE_DIR}") - -add_library(otbconfigfile ConfigFile.cpp) - -if(OTB_LIBRARY_PROPERTIES) - set_target_properties(otbconfigfile PROPERTIES ${OTB_LIBRARY_PROPERTIES}) -endif(OTB_LIBRARY_PROPERTIES) - -install(TARGETS otbconfigfile - EXPORT ${OTB3P_INSTALL_EXPORT_NAME} - RUNTIME DESTINATION ${OTB3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries - LIBRARY DESTINATION ${OTB3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries - ARCHIVE DESTINATION ${OTB3P_INSTALL_ARCHIVE_DIR} COMPONENT Development - ) - -install(FILES - ConfigFile.h - DESTINATION ${OTB3P_INSTALL_INCLUDE_DIR}/otbconfigfile - COMPONENT Development - ) - -otb_module_target( otbconfigfile NO_INSTALL ) diff --git a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.cpp b/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.cpp deleted file mode 100644 index acb4dbc6d225822b64671fcf4af012b3198e8687..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// ConfigFile.cpp - -#include "ConfigFile.h" - -using std::string; - -ConfigFile::ConfigFile( string filename, string delimiter, - string comment, string sentry ) - : myDelimiter(delimiter), myComment(comment), mySentry(sentry) -{ - // Construct a ConfigFile, getting keys and values from given file - - std::ifstream in( filename.c_str() ); - - if( !in ) throw file_not_found( filename ); - - in >> (*this); -} - - -ConfigFile::ConfigFile() - : myDelimiter( string(1,'=') ), myComment( string(1,'#') ) -{ - // Construct a ConfigFile without a file; empty -} - - -void ConfigFile::remove( const string& key ) -{ - // Remove key and its value - myContents.erase( myContents.find( key ) ); - return; -} - - -bool ConfigFile::keyExists( const string& key ) const -{ - // Indicate whether key is found - mapci p = myContents.find( key ); - return ( p != myContents.end() ); -} - - -/* static */ -void ConfigFile::trim( string& s ) -{ - // Remove leading and trailing whitespace - static const char whitespace[] = " \n\t\v\r\f"; - s.erase( 0, s.find_first_not_of(whitespace) ); - s.erase( s.find_last_not_of(whitespace) + 1U ); -} - - -std::ostream& operator<<( std::ostream& os, const ConfigFile& cf ) -{ - // Save a ConfigFile to os - for( ConfigFile::mapci p = cf.myContents.begin(); - p != cf.myContents.end(); - ++p ) - { - os << p->first << " " << cf.myDelimiter << " "; - os << p->second << std::endl; - } - return os; -} - - -std::istream& operator>>( std::istream& is, ConfigFile& cf ) -{ - // Load a ConfigFile from is - // Read in keys and values, keeping internal whitespace - typedef string::size_type pos; - const string& delim = cf.myDelimiter; // separator - const string& comm = cf.myComment; // comment - const string& sentry = cf.mySentry; // end of file sentry - const pos skip = delim.length(); // length of separator - - string nextline = ""; // might need to read ahead to see where value ends - - while( is || nextline.length() > 0 ) - { - // Read an entire line at a time - string line; - if( nextline.length() > 0 ) - { - line = nextline; // we read ahead; use it now - nextline = ""; - } - else - { - std::getline( is, line ); - } - - // Ignore comments - line = line.substr( 0, line.find(comm) ); - - // Check for end of file sentry - if( sentry != "" && line.find(sentry) != string::npos ) return is; - - // Parse the line if it contains a delimiter - pos delimPos = line.find( delim ); - if( delimPos < string::npos ) - { - // Extract the key - string key = line.substr( 0, delimPos ); - line.replace( 0, delimPos+skip, "" ); - - // See if value continues on the next line - // Stop at blank line, next line with a key, end of stream, - // or end of file sentry - bool terminate = false; - while( !terminate && is ) - { - std::getline( is, nextline ); - terminate = true; - - string nlcopy = nextline; - ConfigFile::trim(nlcopy); - if( nlcopy == "" ) continue; - - nextline = nextline.substr( 0, nextline.find(comm) ); - if( nextline.find(delim) != string::npos ) - continue; - if( sentry != "" && nextline.find(sentry) != string::npos ) - continue; - - nlcopy = nextline; - ConfigFile::trim(nlcopy); - if( nlcopy != "" ) line += "\n"; - line += nextline; - terminate = false; - } - - // Store key and value - ConfigFile::trim(key); - ConfigFile::trim(line); - cf.myContents[key] = line; // overwrites if key is repeated - } - } - - return is; -} diff --git a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.h b/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.h deleted file mode 100644 index c2f002447c35f98d5b51d5c2cd6ad834957f4610..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/ConfigFile.h +++ /dev/null @@ -1,253 +0,0 @@ -// ConfigFile.h -// Class for reading named values from configuration files -// Richard J. Wagner v2.1 24 May 2004 wagnerr@umich.edu - -// Copyright (c) 2004 Richard J. Wagner -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. - -// Typical usage -// ------------- -// -// Given a configuration file "settings.inp": -// atoms = 25 -// length = 8.0 # nanometers -// name = Reece Surcher -// -// Named values are read in various ways, with or without default values: -// ConfigFile config( "settings.inp" ); -// int atoms = config.read<int>( "atoms" ); -// double length = config.read( "length", 10.0 ); -// string author, title; -// config.readInto( author, "name" ); -// config.readInto( title, "title", string("Untitled") ); -// -// See file example.cpp for more examples. - -#ifndef CONFIGFILE_H -#define CONFIGFILE_H - -#include <string> -#include <map> -#include <iostream> -#include <fstream> -#include <sstream> - -using std::string; - -class ConfigFile { -// Data -protected: - string myDelimiter; // separator between key and value - string myComment; // separator between value and comments - string mySentry; // optional string to signal end of file - std::map<string,string> myContents; // extracted keys and values - - typedef std::map<string,string>::iterator mapi; - typedef std::map<string,string>::const_iterator mapci; - -// Methods -public: - ConfigFile( string filename, - string delimiter = "=", - string comment = "#", - string sentry = "EndConfigFile" ); - ConfigFile(); - - // Search for key and read value or optional default value - template<class T> T read( const string& key ) const; // call as read<T> - template<class T> T read( const string& key, const T& value ) const; - template<class T> bool readInto( T& var, const string& key ) const; - template<class T> - bool readInto( T& var, const string& key, const T& value ) const; - - // Modify keys and values - template<class T> void add( string key, const T& value ); - void remove( const string& key ); - - // Check whether key exists in configuration - bool keyExists( const string& key ) const; - - // Check or change configuration syntax - string getDelimiter() const { return myDelimiter; } - string getComment() const { return myComment; } - string getSentry() const { return mySentry; } - string setDelimiter( const string& s ) - { string old = myDelimiter; myDelimiter = s; return old; } - string setComment( const string& s ) - { string old = myComment; myComment = s; return old; } - - // Write or read configuration - friend std::ostream& operator<<( std::ostream& os, const ConfigFile& cf ); - friend std::istream& operator>>( std::istream& is, ConfigFile& cf ); - -protected: - template<class T> static string T_as_string( const T& t ); - template<class T> static T string_as_T( const string& s ); - static void trim( string& s ); - - -// Exception types -public: - struct file_not_found { - string filename; - file_not_found( const string& filename_ = string() ) - : filename(filename_) {} }; - struct key_not_found { // thrown only by T read(key) variant of read() - string key; - key_not_found( const string& key_ = string() ) - : key(key_) {} }; -}; - - -/* static */ -template<class T> -string ConfigFile::T_as_string( const T& t ) -{ - // Convert from a T to a string - // Type T must support << operator - std::ostringstream ost; - ost << t; - return ost.str(); -} - - -/* static */ -template<class T> -T ConfigFile::string_as_T( const string& s ) -{ - // Convert from a string to a T - // Type T must support >> operator - T t; - std::istringstream ist(s); - ist >> t; - return t; -} - - -/* static */ -template<> -inline string ConfigFile::string_as_T<string>( const string& s ) -{ - // Convert from a string to a string - // In other words, do nothing - return s; -} - - -/* static */ -template<> -inline bool ConfigFile::string_as_T<bool>( const string& s ) -{ - // Convert from a string to a bool - // Interpret "false", "F", "no", "n", "0" as false - // Interpret "true", "T", "yes", "y", "1", "-1", or anything else as true - bool b = true; - string sup = s; - for( string::iterator p = sup.begin(); p != sup.end(); ++p ) - *p = toupper(*p); // make string all caps - if( sup==string("FALSE") || sup==string("F") || - sup==string("NO") || sup==string("N") || - sup==string("0") || sup==string("NONE") ) - b = false; - return b; -} - - -template<class T> -T ConfigFile::read( const string& key ) const -{ - // Read the value corresponding to key - mapci p = myContents.find(key); - if( p == myContents.end() ) throw key_not_found(key); - return string_as_T<T>( p->second ); -} - - -template<class T> -T ConfigFile::read( const string& key, const T& value ) const -{ - // Return the value corresponding to key or given default value - // if key is not found - mapci p = myContents.find(key); - if( p == myContents.end() ) return value; - return string_as_T<T>( p->second ); -} - - -template<class T> -bool ConfigFile::readInto( T& var, const string& key ) const -{ - // Get the value corresponding to key and store in var - // Return true if key is found - // Otherwise leave var untouched - mapci p = myContents.find(key); - bool found = ( p != myContents.end() ); - if( found ) var = string_as_T<T>( p->second ); - return found; -} - - -template<class T> -bool ConfigFile::readInto( T& var, const string& key, const T& value ) const -{ - // Get the value corresponding to key and store in var - // Return true if key is found - // Otherwise set var to given default - mapci p = myContents.find(key); - bool found = ( p != myContents.end() ); - if( found ) - var = string_as_T<T>( p->second ); - else - var = value; - return found; -} - - -template<class T> -void ConfigFile::add( string key, const T& value ) -{ - // Add a key with given value - string v = T_as_string( value ); - trim(key); - trim(v); - myContents[key] = v; - return; -} - -#endif // CONFIGFILE_H - -// Release notes: -// v1.0 21 May 1999 -// + First release -// + Template read() access only through non-member readConfigFile() -// + ConfigurationFileBool is only built-in helper class -// -// v2.0 3 May 2002 -// + Shortened name from ConfigurationFile to ConfigFile -// + Implemented template member functions -// + Changed default comment separator from % to # -// + Enabled reading of multiple-line values -// -// v2.1 24 May 2004 -// + Made template specializations inline to avoid compiler-dependent linkage -// + Allowed comments within multiple-line values -// + Enabled blank line termination for multiple-line values -// + Added optional sentry to detect end of configuration file -// + Rewrote messy trimWhitespace() function as elegant trim() diff --git a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/README b/Modules/ThirdParty/ConfigFile/src/otbconfigfile/README deleted file mode 100644 index 27406cfe8cf708368e3d375017f3fbdd6501f7d5..0000000000000000000000000000000000000000 --- a/Modules/ThirdParty/ConfigFile/src/otbconfigfile/README +++ /dev/null @@ -1,57 +0,0 @@ -README for ConfigFile distribution -Richard J. Wagner v2.1 24 May 2004 - -Instructions ------------- - -The only necessary files for using this configuration file reader are -"ConfigFile.h" and "ConfigFile.cpp". The class name is ConfigFile. - -Usage examples are in "example.cpp". Linux or Unix users can type "make" to -compile and then type "make run" to run the example program. - -The test program in "tester.cpp" will check that the class properly reads -a variety of simple and complex configuration file entries. To run the test -program type "make test". - -When you are done with the examples and the test program, type "make clean" -to get rid of temporary files. - -For Windows or Mac users with a compiler such as Metrowerks CodeWarrior or -Microsoft Visual C++, simply add "example.cpp" and "ConfigFile.cpp" to an -empty C++ console application. Compile and run to see the configuration -file reader in action. Do likewise with "tester.cpp" to check that the -code works properly with your compiler. - -If you encounter any problems, please e-mail a copy of the output and a -description of the test system to me at "wagnerr@umich.edu". Any other -feedback is welcome too. - - -Installation ------------- - -Just copy the files "ConfigFile.h" and "ConfigFile.cpp" to your working -directory or some other place where your compiler can find them. Add -"ConfigFile.cpp" to your project and put the following line at the top of -your program to access the ConfigFile class: - -#include "ConfigFile.h" - - -Contents --------- - -README - this file -ConfigFile.h - declaration of ConfigFile class -ConfigFile.cpp - definitions of ConfigFile class -example.cpp - examples of using ConfigFile -tester.cpp - tests ConfigFile class -example.inp - configuration file for example program -test.inp - configuration file for tester program -Triplet.h - sample user-defined data type -Makefile - instructions used by "make" command -ConfigFile.html - Web page about ConfigFile -AntBlueMaize.jpg - background for ConfigFile.html -ArrowHome.gif - home icon for ConfigFile.html -main.css - style sheet for ConfigFile.html