-
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.
- Loading branch information
1 parent
948341d
commit e6adb86
Showing
10 changed files
with
407 additions
and
313 deletions.
There are no files selected for viewing
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
103 changes: 103 additions & 0 deletions
103
Code/Mantid/Framework/API/inc/MantidAPI/FunctionProperty.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,103 @@ | ||
#ifndef MANTID_API_FUNCTIONPROPERTY_H_ | ||
#define MANTID_API_FUNCTIONPROPERTY_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidAPI/IFitFunction.h" | ||
#include "MantidKernel/PropertyWithValue.h" | ||
#include "MantidKernel/Logger.h" | ||
#include "MantidKernel/Exception.h" | ||
|
||
#include <boost/shared_ptr.hpp> | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
/** A property class for functions. Holds a shared pointer to a function. The string representation | ||
is the creation string accepted by the FunctionFactory. | ||
@author Roman Tolchenov, Tessella plc | ||
@date 08/02/2012 | ||
Copyright © 2007-2010 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> | ||
*/ | ||
class MANTID_API_DLL FunctionProperty : public Kernel::PropertyWithValue< boost::shared_ptr<IFitFunction> > | ||
{ | ||
public: | ||
/// Constructor. | ||
explicit FunctionProperty( const std::string &name ); | ||
|
||
/// Copy constructor | ||
FunctionProperty( const FunctionProperty& right ); | ||
|
||
/// Copy assignment operator. Only copies the value (i.e. the pointer to the workspace) | ||
FunctionProperty& operator=( const FunctionProperty& right ); | ||
|
||
/// Bring in the PropertyWithValue assignment operator explicitly (avoids VSC++ warning) | ||
virtual boost::shared_ptr<IFitFunction>& operator=( const boost::shared_ptr<IFitFunction>& value ); | ||
|
||
///Add the value of another property | ||
virtual FunctionProperty& operator+=( Kernel::Property const * ); | ||
|
||
/// 'Virtual copy constructor' | ||
Kernel::Property* clone() { return new FunctionProperty(*this); } | ||
|
||
/// Virtual destructor | ||
virtual ~FunctionProperty(); | ||
|
||
/// Get the name of the workspace | ||
virtual std::string value() const; | ||
|
||
/// Get the value the property was initialised with -its default value | ||
virtual std::string getDefault() const; | ||
|
||
/// Set the value of the property | ||
virtual std::string setValue( const std::string& value ); | ||
|
||
/// Checks whether the entered function is valid. | ||
std::string isValid() const; | ||
|
||
/// Is default | ||
bool isDefault() const; | ||
|
||
/// Create a history record | ||
virtual const Kernel::PropertyHistory createHistory() const; | ||
|
||
private: | ||
|
||
/// The name of the workspace (as used by the AnalysisDataService) | ||
std::string m_definition; | ||
|
||
/// for access to logging streams | ||
static Kernel::Logger& g_log; | ||
}; | ||
|
||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_API_FUNCTIONPROPERTY_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "MantidAPI/FunctionProperty.h" | ||
#include "MantidAPI/FunctionFactory.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
Kernel::Logger& FunctionProperty::g_log = Kernel::Logger::get("FunctionProperty"); | ||
|
||
/** Constructor. | ||
* Sets the property names but initialises the function pointer to null. | ||
* @param name :: The name to assign to the property | ||
*/ | ||
FunctionProperty::FunctionProperty( const std::string &name ) : | ||
Kernel::PropertyWithValue <boost::shared_ptr<IFitFunction> >( | ||
name, | ||
boost::shared_ptr<IFitFunction>( ), | ||
new Kernel::NullValidator< boost::shared_ptr<IFitFunction> >, | ||
Kernel::Direction::InOut | ||
) | ||
{ | ||
} | ||
|
||
/// Copy constructor | ||
FunctionProperty::FunctionProperty( const FunctionProperty& right ) : | ||
Kernel::PropertyWithValue< boost::shared_ptr<IFitFunction> >( right ) | ||
{ | ||
} | ||
|
||
/// Copy assignment operator. Copies the pointer to the function. | ||
FunctionProperty& FunctionProperty::operator=( const FunctionProperty& right ) | ||
{ | ||
if ( &right == this ) return *this; | ||
Kernel::PropertyWithValue< boost::shared_ptr<IFitFunction> >::operator=( right ); | ||
return *this; | ||
} | ||
|
||
/** Bring in the PropertyWithValue assignment operator explicitly (avoids VSC++ warning) | ||
* @param value :: The value to set to | ||
* @return assigned PropertyWithValue | ||
*/ | ||
boost::shared_ptr<IFitFunction>& FunctionProperty::operator=( const boost::shared_ptr<IFitFunction>& value ) | ||
{ | ||
return Kernel::PropertyWithValue< boost::shared_ptr<IFitFunction> >::operator=( value ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
///Add the value of another property | ||
FunctionProperty& FunctionProperty::operator+=( Kernel::Property const * ) | ||
{ | ||
throw Kernel::Exception::NotImplementedError("+= operator is not implemented for FunctionProperty."); | ||
return *this; | ||
} | ||
|
||
/// Virtual destructor | ||
FunctionProperty::~FunctionProperty() | ||
{ | ||
} | ||
|
||
/** Get the function definition | ||
* @return The function definition | ||
*/ | ||
std::string FunctionProperty::value() const | ||
{ | ||
return m_value->asString(); | ||
} | ||
|
||
/** Get the value the property was initialised with -its default value | ||
* @return The default value | ||
*/ | ||
std::string FunctionProperty::getDefault() const | ||
{ | ||
return ""; | ||
} | ||
|
||
/** Set the function definition. | ||
* Also tries to create the function with FunctionFactory. | ||
* @param value :: The function definition string. | ||
* @return Error message from FunctionFactory or "" on success. | ||
*/ | ||
std::string FunctionProperty::setValue( const std::string& value ) | ||
{ | ||
std::string error = ""; | ||
try | ||
{ | ||
m_value = boost::shared_ptr<IFitFunction>(FunctionFactory::Instance().createInitialized(value)); | ||
m_definition = value; | ||
} | ||
catch(std::exception& e) | ||
{ | ||
error = e.what(); | ||
} | ||
return error; | ||
} | ||
|
||
/** Checks whether the entered function is valid. | ||
* To be valid it has to be | ||
* @returns A user level description of the problem or "" if it is valid. | ||
*/ | ||
std::string FunctionProperty::isValid() const | ||
{ | ||
return isDefault() ? "Funcion is empty." : ""; | ||
} | ||
|
||
/** Indicates if the object is still pointing to the same workspace, using the workspace name | ||
* @return true if the value is the same as the initial value or false otherwise | ||
*/ | ||
bool FunctionProperty::isDefault() const | ||
{ | ||
return m_value == boost::shared_ptr<IFitFunction>(); | ||
} | ||
|
||
/// Create a history record | ||
/// @return A populated PropertyHistory for this class | ||
const Kernel::PropertyHistory FunctionProperty::createHistory() const | ||
{ | ||
return Kernel::PropertyHistory(this->name(),this->value(),this->type(),this->isDefault(),Kernel::PropertyWithValue<boost::shared_ptr<IFitFunction> >::direction()); | ||
} | ||
|
||
} // namespace API | ||
} // namespace Mantid |
Oops, something went wrong.