-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4399. Intermediate type handler class
Adds a place for common code between handler types.
- Loading branch information
1 parent
32b9713
commit da946f0
Showing
15 changed files
with
254 additions
and
46 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../PythonInterface/inc/MantidPythonInterface/api/PythonAlgorithm/PropertyWithValueFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef MANTID_PYTHONINTERFACE_PROEPRTYWITHVALUEFACTORY_H_ | ||
#define MANTID_PYTHONINTERFACE_PROEPRTYWITHVALUEFACTORY_H_ | ||
/** | ||
Copyright © 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
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> | ||
*/ | ||
//----------------------------------------------------------------------------- | ||
// Includes | ||
//----------------------------------------------------------------------------- | ||
#include "MantidKernel/System.h" | ||
#include <string> | ||
#include <boost/python/object.hpp> | ||
|
||
namespace Mantid | ||
{ | ||
//--------------------------------------------------------------------------- | ||
// Forward declarations | ||
//--------------------------------------------------------------------------- | ||
namespace Kernel | ||
{ | ||
class Property; | ||
} | ||
|
||
namespace PythonInterface | ||
{ | ||
/** | ||
* Defines a static factory class that creates PropertyWithValue | ||
* instances from python objects. | ||
*/ | ||
class PropertyWithValueFactory | ||
{ | ||
/// Creates a property from the given value and direction | ||
static Kernel::Property * createProperty(const std::string & name, const boost::python::object & defaultValue, | ||
const unsigned int direction); | ||
/// Creates a property from the value, validator and direction | ||
static Kernel::Property * createProperty(const std::string & name, const boost::python::object & defaultValue, | ||
const boost::python::object & validator, const unsigned int direction); | ||
}; | ||
} | ||
} | ||
|
||
#endif //MANTID_PYTHONINTERFACE_PROEPRTYWITHVALUEFACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ork/PythonInterface/inc/MantidPythonInterface/kernel/Registry/TypedPropertyValueHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef MANTID_PYTHONINTERFACE_TYPEDPROPERTYVALUEHANDLER_H_ | ||
#define MANTID_PYTHONINTERFACE_TYPEDPROPERTYVALUEHANDLER_H_ | ||
/** | ||
Copyright © 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
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> | ||
*/ | ||
#include "MantidPythonInterface/kernel/Registry/PropertyValueHandler.h" | ||
#include "MantidKernel/PropertyWithValue.h" | ||
#include <boost/python/object.hpp> | ||
#include <boost/python/extract.hpp> | ||
#include <string> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Kernel | ||
{ | ||
class IPropertyManager; | ||
} | ||
namespace PythonInterface | ||
{ | ||
namespace Registry | ||
{ | ||
/** | ||
* This class provides a templated class object that is able to take a | ||
* python object and perform operations with a given C type. | ||
*/ | ||
template<typename ValueType> | ||
struct DLLExport TypedPropertyValueHandler : public PropertyValueHandler | ||
{ | ||
/** | ||
* Set function to handle Python -> C++ calls and get the correct type | ||
* @param alg :: A pointer to an IPropertyManager | ||
* @param name :: The name of the property | ||
* @param value :: A boost python object that stores the value | ||
*/ | ||
void set(Kernel::IPropertyManager* alg, const std::string &name, const boost::python::object & value) | ||
{ | ||
alg->setProperty<ValueType>(name, boost::python::extract<ValueType>(value)); | ||
} | ||
/** | ||
* Create a PropertyWithValue from the given python object value | ||
* @param name :: The name of the property | ||
* @param defaultValue :: The defaultValue of the property. The object attempts to extract | ||
* a value of type ValueType from the python object | ||
* @param direction :: The direction of the property | ||
* @returns A pointer to a newly constructed property instance | ||
*/ | ||
Kernel::Property * create(const std::string & name, const boost::python::object & defaultValue, | ||
const unsigned int direction) const | ||
{ | ||
using boost::python::extract; | ||
const ValueType valueInC = extract<ValueType>(defaultValue)(); | ||
return new Kernel::PropertyWithValue<ValueType>(name, valueInC, direction); | ||
} | ||
/// Is the given object a derived type of this objects Type | ||
bool checkExtract(const boost::python::object & value) const | ||
{ | ||
boost::python::extract<ValueType> extractor(value); | ||
return extractor.check(); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#endif /* MANTID_PYTHONINTERFACE_TYPEDPROPERTYVALUEHANDLER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tid/Framework/PythonInterface/mantid/api/src/PythonAlgorithm/PropertyWithValueFactory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//----------------------------------------------------------------------------- | ||
// Includes | ||
//----------------------------------------------------------------------------- | ||
#include "MantidPythonInterface/api/PythonAlgorithm/PropertyWithValueFactory.h" | ||
#include "MantidKernel/PropertyWithValue.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace PythonInterface | ||
{ | ||
|
||
/** | ||
* Creates a PropertyWithValue<Type> instance from the given information. | ||
* The python type is mapped to a C type using the mapping defined by initPythonTypeMap() | ||
* @param name :: The name of the property | ||
* @param defaultValue :: A default value for this property. | ||
* @param direction :: Specifies whether the property is Input, InOut or Output | ||
* @returns A pointer to a new Property object | ||
*/ | ||
Kernel::Property * | ||
PropertyWithValueFactory::createProperty(const std::string & name , const boost::python::object & value, | ||
const unsigned int direction) | ||
{ | ||
return NULL; | ||
} | ||
|
||
/** | ||
* Creates a PropertyWithValue<Type> instance from the given information. | ||
* The python type is mapped to a C type using the mapping defined by initPythonTypeMap() | ||
* @param name :: The name of the property | ||
* @param defaultValue :: A default value for this property. | ||
* @param validator :: A validator object | ||
* @param direction :: Specifies whether the property is Input, InOut or Output | ||
* @returns A pointer to a new Property object | ||
*/ | ||
Kernel::Property * | ||
PropertyWithValueFactory::createProperty(const std::string & name , const boost::python::object & value, | ||
const boost::python::object & validator, const unsigned int direction) | ||
{ | ||
return NULL; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.