Newer
Older
Russell Taylor
committed
#ifndef MANTID_KERNEL_CONFIGSVC_H_
#define MANTID_KERNEL_CONFIGSVC_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "System.h"
//----------------------------------------------------------------------
// Forward declaration
//----------------------------------------------------------------------
namespace Poco
{
namespace Util
{
class PropertyFileConfiguration;
class SystemConfiguration;
}
}
namespace Mantid
{
Russell Taylor
committed
namespace Kernel
{
/** @class ConfigSvc ConfigSvc.h Kernel/ConfigSvc.h
The ConfigSvc class provides a simple facade to access the Configuration functionality of the Mantid Framework.
The class gathers information from config files and the system variables.
This information is available to all the objects within the framework as well as being used to configure the logging framework.
This class currently uses the Logging functionality provided through the POCO (portable components library).
@author Nicholas Draper, Tessella Support Services plc
@date 15/10/2007
Copyright © 2007 STFC Rutherford Appleton Laboratories
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ConfigSvc
{
/** Inner templated class to wrap the poco library objects that have protected
* desctructors and expose them as public.
*/
template<typename T >
class WrappedObject : public T
{
public:
/// The template type of class that is being wrapped
typedef T element_type;
/// Simple constructor
WrappedObject() : T()
{
m_pPtr = static_cast<T*>(this);
}
/** Constructor with a class to wrap
* @param F The object to wrap
*/
template<typename Field>
WrappedObject(Field& F) : T(F)
{
m_pPtr = static_cast<T*>(this);
}
/// Copy constructor
WrappedObject(const WrappedObject<T>& A) : T(A)
{
m_pPtr = static_cast<T*>(this);
}
/// Virtual destructor
virtual ~WrappedObject()
{}
/// Overloaded * operator returns the wrapped object pointer
const T& operator*() const { return *m_pPtr; }
/// Overloaded * operator returns the wrapped object pointer
T& operator*() { return m_pPtr; }
/// Overloaded -> operator returns the wrapped object pointer
const T* operator->() const{ return m_pPtr; }
/// Overloaded -> operator returns the wrapped object pointer
T* operator->() { return m_pPtr; }
/// Private pointer to the wrapped class
T* m_pPtr;
};
// Back to the ConfigSvc class itself...
public:
// Returns the single instance of the service
static ConfigSvc* Instance();
// Loads a config file
void loadConfig(const std::string& filename);
// Searches for a configuration property
std::string getString(const std::string& keyName);
// Searches for a configuration property and returns its value
template<typename T>
int getValue(const std::string& keyName, T& out);
// Searches for the given environment variable and returns it as a string
std::string getEnvironment(const std::string& keyName);
// Getters for properties of the host system
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
std::string getOSName();
std::string getComputerName();
std::string getOSArchitecture();
/* Removed as the use of these throughs a debug assertion about an invlid heap pointer
File dbgheap.c
Expression _CrtIsValidHeapPointer(pUserData)
/// Gets the name of the operation system version
///
/// @returns the string value of the operation system version
std::string getOSVersion();
/// Gets the path of the current directory
///
/// @returns the string value of the path of the current directory
std::string getCurrentDir();
/// Gets the path of the home directory
///
/// @returns the string value of the path of the home directory
std::string getHomeDir();
/// Gets the path of the temp directory
///
/// @returns the string value of the path of the temp directory
std::string getTempDir();
*/
private:
// Private constructors and destructor for singleton class
/// Private copy constructor. Prevents singleton being copied.
ConfigSvc(const ConfigSvc&) {}
virtual ~ConfigSvc();
/// the POCO file config object
WrappedObject<Poco::Util::PropertyFileConfiguration>* m_pConf;
/// the POCO system Config Object
WrappedObject<Poco::Util::SystemConfiguration>* m_pSysConfig;
/// Pointer to the factory instance
static ConfigSvc* m_instance;
};
Russell Taylor
committed
} // namespace Kernel
} // namespace Mantid
Russell Taylor
committed
#endif /*MANTID_KERNEL_CONFIGSVC_H_*/