Newer
Older
#ifndef MANTID_KERNEL_PROPERTYMANAGER_H_
#define MANTID_KERNEL_PROPERTYMANAGER_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
Russell Taylor
committed
#include <vector>
#include "MantidKernel/IPropertyManager.h"
namespace Mantid {
namespace Kernel {
Russell Taylor
committed
//----------------------------------------------------------------------
// Forward Declaration
//----------------------------------------------------------------------
class SplittingInterval;
template <typename T> class TimeSeriesProperty;
Russell Taylor
committed
Property manager helper class.
This class is used by algorithms and services for helping to manage their own
set of properties.
Russell Taylor
committed
N.B. ONCE YOU HAVE DECLARED A PROPERTY TO THE MANAGER IT IS OWNED BY THIS CLASS
(I.E. DON'T DELETE IT!)
Property values of any type except std::string can be extracted using
getProperty().
Russell Taylor
committed
For assignment of string properties it is necessary to use getPropertyValue().
@author Russell Taylor, Tessella Support Services plc
@author Based on the Gaudi class PropertyMgr (see
http://proj-gaudi.web.cern.ch/proj-gaudi/)
@date 20/11/2007
Russell Taylor
committed
Copyright © 2007-2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
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/>.
Russell Taylor
committed
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_KERNEL_DLL PropertyManager : virtual public IPropertyManager {
PropertyManager();
PropertyManager(const PropertyManager &);
PropertyManager &operator=(const PropertyManager &);
PropertyManager &operator+=(const PropertyManager &rhs);
Janik Zikovsky
committed
void filterByTime(const Kernel::DateAndTime &start,
const Kernel::DateAndTime &stop);
void splitByTime(std::vector<SplittingInterval> &splitter,
std::vector<PropertyManager *> outputs) const;
void filterByProperty(const TimeSeriesProperty<bool> &filter);
virtual ~PropertyManager();
// Function to declare properties (i.e. store them)
void declareProperty(Property *p, const std::string &doc = "");
Russell Taylor
committed
// Sets all the declared properties from
void setProperties(
const std::string &propertiesJson,
const std::set<std::string> &ignoreProperties = std::set<std::string>());
void setProperties(
const ::Json::Value &jsonValue,
const std::set<std::string> &ignoreProperties = std::set<std::string>());
void setProperties(const ::Json::Value &jsonValue,
IPropertyManager *targetPropertyManager,
const std::set<std::string> &ignoreProperties = std::set<std::string>());
void setPropertiesWithSimpleString(
const std::string &propertiesString,
const std::set<std::string> &ignoreProperties = std::set<std::string>());
void setPropertyValue(const std::string &name, const std::string &value);
void setPropertyOrdinal(const int &index, const std::string &value);
bool existsProperty(const std::string &name) const;
bool validateProperties() const;
Gigg, Martyn Anthony
committed
size_t propertyCount() const;
std::string getPropertyValue(const std::string &name) const;
const std::vector<Property *> &getProperties() const;
/// removes the property from properties map
void removeProperty(const std::string &name, const bool delproperty = true);
Gigg, Martyn Anthony
committed
/// Clears the whole property map
void clear();
/// Get the value of a property
TypedValue getProperty(const std::string &name) const;
Gigg, Martyn Anthony
committed
/// Return the property manager serialized as a string.
virtual std::string asString(bool withDefaultValues = false) const;
/// Return the property manager serialized as a json object.
virtual ::Json::Value asJson(bool withDefaultValues = false) const;
Russell Taylor
committed
Russell Taylor
committed
protected:
using IPropertyManager::declareProperty;
Russell Taylor
committed
friend class PropertyManagerOwner;
Property *getPointerToProperty(const std::string &name) const;
Property *getPointerToPropertyOrdinal(const int &index) const;
Property *getPointerToPropertyOrNull(const std::string &name) const;
Gigg, Martyn Anthony
committed
/// Transform the given string to a key for the property index
const std::string createKey(const std::string &text) const;
Gigg, Martyn Anthony
committed
/// typedef for the map holding the properties
typedef std::map<std::string, Property *> PropertyMap;
/// The properties under management
PropertyMap m_properties;
Janik Zikovsky
committed
/// Stores the order in which the properties were declared.
std::vector<Property *> m_orderedProperties;
/// Typedef for a shared pointer to a PropertyManager
typedef boost::shared_ptr<PropertyManager> PropertyManager_sptr;
} // namespace Kernel
} // namespace Mantid
#endif /*MANTID_KERNEL_PROPERTYMANAGER_H_*/