Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/10537_varia…
Browse files Browse the repository at this point in the history
…ble_initial_view_vates

Conflicts:
	Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
	Code/Mantid/Framework/Kernel/src/ConfigService.cpp
  • Loading branch information
peterfpeterson committed Dec 17, 2014
2 parents 0f7810e + 3d0ba59 commit 71fb268
Show file tree
Hide file tree
Showing 2,581 changed files with 573,573 additions and 481,081 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Build/CMake/FindPyUnitTest.cmake
Expand Up @@ -30,8 +30,8 @@ macro ( PYUNITTEST_ADD_TEST _test_src_dir _testname_prefix )
COMMAND ${PYTHON_EXECUTABLE_DEBUG} -B ${_test_src_dir}/${_filename} )
# Set the PYTHONPATH so that the built modules can be found
set_tests_properties ( ${_pyunit_separate_name}_Debug PROPERTIES
ENVIRONMENT "PYTHONPATH=${_module_dir}"
WORKING_DIRECTORY ${_working_dir}
ENVIRONMENT "PYTHONPATH=${_module_dir_debug}"
WORKING_DIRECTORY ${_working_dir_debug}
TIMEOUT ${TESTING_TIMEOUT} )
# Release
add_test ( NAME ${_pyunit_separate_name} CONFIGURATIONS Release
Expand Down
325 changes: 184 additions & 141 deletions Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h

Large diffs are not rendered by default.

154 changes: 78 additions & 76 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h
Expand Up @@ -11,17 +11,15 @@
#include "MantidKernel/DynamicFactory.h"
#include "MantidKernel/SingletonHolder.h"

namespace Mantid
{
namespace API
{

/// Structure uniquely describing an algorithm with its name, category and version.
struct Algorithm_descriptor
{
std::string name;///< name
std::string category;///< category
int version;///< version
namespace Mantid {
namespace API {

/// Structure uniquely describing an algorithm with its name, category and
/// version.
struct Algorithm_descriptor {
std::string name; ///< name
std::string category; ///< category
int version; ///< version
};

//----------------------------------------------------------------------
Expand All @@ -34,11 +32,12 @@ class Algorithm;
instances of Algorithms. It inherits most of its implementation from
the Dynamic Factory base class.
It is implemented as a singleton class.
@author Russell Taylor, Tessella Support Services plc
@date 21/09/2007
Copyright &copy; 2007-2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
Copyright &copy; 2007-2011 ISIS Rutherford Appleton Laboratory, NScD Oak
Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Expand All @@ -55,113 +54,112 @@ class Algorithm;
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://github.com/mantidproject/mantid>
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_API_DLL AlgorithmFactoryImpl : public Kernel::DynamicFactory<Algorithm>
{
class MANTID_API_DLL AlgorithmFactoryImpl
: public Kernel::DynamicFactory<Algorithm> {
public:
// Unhide the base class version (to satisfy the intel compiler)
using Kernel::DynamicFactory<Algorithm>::create;
///Creates an instance of an algorithm
boost::shared_ptr<Algorithm> create(const std::string& ,const int& ) const;

/// algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally
template <class C>
std::pair<std::string,int> subscribe()
{
Kernel::Instantiator<C, Algorithm>* newI = new Kernel::Instantiator<C, Algorithm>;
/// Creates an instance of an algorithm
boost::shared_ptr<Algorithm> create(const std::string &, const int &) const;

/// algorithm factory specific function to subscribe algorithms, calls the
/// dynamic factory subscribe function internally
template <class C> std::pair<std::string, int> subscribe() {
Kernel::Instantiator<C, Algorithm> *newI =
new Kernel::Instantiator<C, Algorithm>;
return this->subscribe(newI);
}

/**
* Subscribes an algorithm using a custom instantiator. This
* object takes ownership of the instantiator
* @param instantiator - A pointer to a custom instantiator
* @param replaceExisting - Defines what happens if an algorithm of the same name/version already exists, see SubscribeAction
* @param replaceExisting - Defines what happens if an algorithm of the same
* name/version already exists, see SubscribeAction
* @returns The classname that was registered
*/
template<class T>
std::pair<std::string,int> subscribe(Kernel::AbstractInstantiator<T> *instantiator, const SubscribeAction replaceExisting = ErrorIfExists)
{
boost::shared_ptr<IAlgorithm> tempAlg = instantiator-> createInstance();
template <class T>
std::pair<std::string, int>
subscribe(Kernel::AbstractInstantiator<T> *instantiator,
const SubscribeAction replaceExisting = ErrorIfExists) {
boost::shared_ptr<IAlgorithm> tempAlg = instantiator->createInstance();
const int version = extractAlgVersion(tempAlg);
const std::string className = extractAlgName(tempAlg);
typename VersionMap::const_iterator it = m_vmap.find(className);
if (!className.empty())
{
const std::string key = createName(className,version);
if( it == m_vmap.end() )
{
if (!className.empty()) {
const std::string key = createName(className, version);
if (it == m_vmap.end()) {
m_vmap[className] = version;
}
else
{
if(version == it->second && replaceExisting == ErrorIfExists)
{
} else {
if (version == it->second && replaceExisting == ErrorIfExists) {
std::ostringstream os;
os << "Cannot register algorithm " << className << " twice with the same version\n";
os << "Cannot register algorithm " << className
<< " twice with the same version\n";
delete instantiator;
throw std::runtime_error(os.str());
}
if(version > it->second)
{
m_vmap[className]=version;
if (version > it->second) {
m_vmap[className] = version;
}
}
Kernel::DynamicFactory<Algorithm>::subscribe(key, instantiator, replaceExisting);
}
else
{
Kernel::DynamicFactory<Algorithm>::subscribe(key, instantiator,
replaceExisting);
} else {
delete instantiator;
throw std::invalid_argument("Cannot register empty algorithm name");
}
return std::make_pair(className,version);
return std::make_pair(className, version);
}
/// Unsubscribe the given algorithm
void unsubscribe(const std::string & algorithmName, const int version);
void unsubscribe(const std::string &algorithmName, const int version);
/// Does an algorithm of the given name and version exist
bool exists(const std::string & algorithmName, const int version = -1);
bool exists(const std::string &algorithmName, const int version = -1);

/// Get the algorithm names and version - mangled use decodeName to separate
const std::vector<std::string> getKeys() const;
const std::vector<std::string> getKeys(bool includeHidden) const;

/// Returns the highest version of the algorithm currently registered
int highestVersion(const std::string & algorithmName) const;
///Get the algorithm categories
const std::set<std::string> getCategories(bool includeHidden=false) const;
int highestVersion(const std::string &algorithmName) const;

/// Get the algorithm categories
const std::set<std::string> getCategories(bool includeHidden = false) const;

///Get the algorithm categories
const std::map<std::string,bool> getCategoriesWithState() const;
/// Get the algorithm categories
const std::map<std::string, bool> getCategoriesWithState() const;

/// Returns algorithm descriptors.
std::vector<Algorithm_descriptor> getDescriptors(bool includeHidden=false) const;
std::vector<Algorithm_descriptor>
getDescriptors(bool includeHidden = false) const;

///unmangles the names used as keys into the name and version
std::pair<std::string,int> decodeName(const std::string& mangledName)const;
/// unmangles the names used as keys into the name and version
std::pair<std::string, int> decodeName(const std::string &mangledName) const;

private:
private:
friend struct Mantid::Kernel::CreateUsingNew<AlgorithmFactoryImpl>;

/// Extract the name of an algorithm
const std::string extractAlgName(const boost::shared_ptr<IAlgorithm> alg) const;
const std::string
extractAlgName(const boost::shared_ptr<IAlgorithm> alg) const;
/// Extract the version of an algorithm
int extractAlgVersion(const boost::shared_ptr<IAlgorithm> alg) const;

///Create an algorithm object with the specified name
boost::shared_ptr<Algorithm> createAlgorithm(const std::string & name, const int version) const;

/// Create an algorithm object with the specified name
boost::shared_ptr<Algorithm> createAlgorithm(const std::string &name,
const int version) const;

/// Private Constructor for singleton class
AlgorithmFactoryImpl();
AlgorithmFactoryImpl();
/// Private copy constructor - NO COPY ALLOWED
AlgorithmFactoryImpl(const AlgorithmFactoryImpl&);
AlgorithmFactoryImpl(const AlgorithmFactoryImpl &);
/// Private assignment operator - NO ASSIGNMENT ALLOWED
AlgorithmFactoryImpl& operator = (const AlgorithmFactoryImpl&);
///Private Destructor
AlgorithmFactoryImpl &operator=(const AlgorithmFactoryImpl &);
/// Private Destructor
virtual ~AlgorithmFactoryImpl();
/// creates an algorithm name convolved from an name and version
std::string createName(const std::string&, const int&)const;
std::string createName(const std::string &, const int &) const;
/// fills a set with the hidden categories
void fillHiddenCategories(std::set<std::string> *categorySet) const;

Expand All @@ -170,19 +168,23 @@ class MANTID_API_DLL AlgorithmFactoryImpl : public Kernel::DynamicFactory<Algori
/// The map holding the registered class names and their highest versions
VersionMap m_vmap;
};


///Forward declaration of a specialisation of SingletonHolder for AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
/// Forward declaration of a specialisation of SingletonHolder for
/// AlgorithmFactoryImpl (needed for dllexport/dllimport) and a typedef for it.
#ifdef _WIN32
// this breaks new namespace declaraion rules; need to find a better fix
template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>;
template class MANTID_API_DLL
Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>;
#endif /* _WIN32 */

typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl> AlgorithmFactory;
typedef MANTID_API_DLL Mantid::Kernel::SingletonHolder<AlgorithmFactoryImpl>
AlgorithmFactory;

/// Convenient typedef for an UpdateNotification
typedef Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification AlgorithmFactoryUpdateNotification;
typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification> & AlgorithmFactoryUpdateNotification_ptr;
typedef Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification
AlgorithmFactoryUpdateNotification;
typedef const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<
Algorithm>::UpdateNotification> &AlgorithmFactoryUpdateNotification_ptr;

} // namespace API
} // namespace Mantid
Expand Down

0 comments on commit 71fb268

Please sign in to comment.