Skip to content
Snippets Groups Projects
Commit dabd9008 authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

ENH: add otbconfigurationfile.cxx in common with generic getparam and singleton

parent 4820eabc
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.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"
namespace otb
{
/** Initialize the singleton */
ConfigurationFile::Pointer ConfigurationFile::Instance = NULL;
ConfigurationFile
::ConfigurationFile()
{
std::string OTBBinDir(OTB_CONFIG);
try
{
m_OTBConfig = new ConfigFile(OTBBinDir + "/otb.conf");
}
catch (ConfigFile::file_not_found& e)
{
itkExceptionMacro(<< "Error - File '" << e.filename << "' not found.");
}
}
ConfigurationFile
::~ConfigurationFile()
{
}
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
......@@ -45,46 +45,41 @@ namespace otb
/** Standard macro */
itkTypeMacro(ConfigurationFile,Object);
/** This is protected for the singleton. Use GetInstance() instead. */
itkNewMacro(Self);
/** Get the unique instanc1e of the model */
// static Pointer GetInstance()
// {
// if (!Instance)
// {
// Instance = Self::New();
// }
// return Instance;
// };
static Pointer GetInstance();
ConfigFile * GetOTBConfig()
{
return m_OTBConfig;
};
std::string GetLanguage()
{
return m_OTBConfig->read<std::string>( "OTB_LANG" );
/** Get parameter*/
template<typename T> T GetParameter(const std::string & key) const {
try
{
return m_OTBConfig->read<T>( key );
}
catch( ConfigFile::key_not_found& e ) {
itkExceptionMacro(<< "Error - Key '" << e.key << "' not found.");
}
};
// std::string lib(OTB_CONFIG);
protected:
/** This is protected for the singleton. Use GetInstance() instead. */
itkNewMacro(Self);
/** Constructor */
ConfigurationFile()
{
std::string OTBBinDir(OTB_CONFIG);
m_OTBConfig = new ConfigFile(OTBBinDir + "/otb.conf");
}
;
ConfigurationFile();
/** Destructor */
~ConfigurationFile(){};
~ConfigurationFile();
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const {};
void PrintSelf(std::ostream& os, itk::Indent indent) const ;
private:
/** The instance singleton */
// static Pointer Instance = NULL;
static Pointer Instance;
ConfigFile * m_OTBConfig;
};
}// end namespace
......
......@@ -27,14 +27,13 @@ int otbConfigurationTest(int argc, char * argv[])
//Instantiation
// ConfigurationType::Pointer conf = ConfigurationType::GetInstance();
ConfigurationType::Pointer conf = ConfigurationType::New();
ConfigurationType::Pointer conf = ConfigurationType::GetInstance();
// conf->Load();
std::string lang = conf->GetParameter<std::string>("OTB_LANG");
std::string lang = conf->GetLanguage();
std::cout << conf << std::endl;
std::cout << "config language " << lang << std::endl;
if (lang != "fr")
if (lang != "fr_FR.UTF-8")
return EXIT_FAILURE;
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment