Skip to content

Commit

Permalink
Refs #4399. Stub for PythonAlgorithm class.
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Feb 24, 2012
1 parent 00b5242 commit 1e3b4ec
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"

#include <boost/python/object.hpp>

namespace Mantid
{
namespace PythonInterface
{
/**
* Provides a marker class that makes it simpler to distinguish a
* C++ algorithm from a Python algorithm.
* Provides a class that forms an interface between a Python algorithm
* and a C++ algorithm.
*
* It defines several functions for declaring properties that handle the
* fact that the type is only known at runtime
*
* It works in tandem with the AlgorithmWrapper such that
* when the AlgorithmWrapper is exported to Python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set ( MODULE_TEMPLATE src/api.cpp.in )
set ( EXPORT_FILES
src/Exports/IAlgorithm.cpp
src/Exports/Algorithm.cpp
src/Exports/PythonAlgorithmExport.cpp
src/Exports/AlgorithmFactory.cpp
src/Exports/AlgorithmManager.cpp
src/Exports/AnalysisDataService.cpp
Expand Down Expand Up @@ -41,6 +42,7 @@ set ( EXPORT_FILES
# Files containing additional helper code that are not related to exporting class/functions
set ( SRC_FILES
src/PythonAlgorithm/AlgorithmWrapper.cpp
src/PythonAlgorithm/PythonAlgorithm.cpp
src/CloneMatrixWorkspace.cpp
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifdef _MSC_VER
#pragma warning( disable: 4250 ) // Disable warning regarding inheritance via dominance, we have no way around it with the design
#endif
#include "MantidPythonInterface/api/PythonAlgorithm/AlgorithmWrapper.h"
#include "MantidAPI/AlgorithmProxy.h"
#include "MantidAPI/Algorithm.h"
#ifdef _MSC_VER
#pragma warning( default: 4250 )
#endif
Expand All @@ -13,20 +13,15 @@
using Mantid::API::IAlgorithm;
using Mantid::API::Algorithm;
using Mantid::API::AlgorithmProxy;
using Mantid::PythonInterface::AlgorithmWrapper;

using namespace boost::python;

void export_algorithm()
{
register_ptr_to_python<boost::shared_ptr<AlgorithmProxy> >();
class_<AlgorithmProxy, bases<IAlgorithm>, boost::noncopyable>("AlgorithmProxy", "Proxy class returned by managed algorithms", no_init)
;

register_ptr_to_python<boost::shared_ptr<Algorithm> >();
class_<Algorithm, bases<IAlgorithm>, boost::noncopyable>("Algorithm", "Base-class for C algorithms", no_init)
;
class_<Algorithm, bases<IAlgorithm>, boost::noncopyable>("Algorithm", "Base-class for C algorithms", no_init);

class_<AlgorithmWrapper, bases<Algorithm>, boost::noncopyable>("PythonAlgorithm", "Base class for all Python algorithms")
;
register_ptr_to_python<boost::shared_ptr<AlgorithmProxy> >();
class_<AlgorithmProxy, bases<IAlgorithm>, boost::noncopyable>("AlgorithmProxy", "Proxy class returned by managed algorithms", no_init);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifdef _MSC_VER
#pragma warning( disable: 4250 ) // Disable warning regarding inheritance via dominance, we have no way around it with the design
#endif
#include "MantidPythonInterface/api/PythonAlgorithm/AlgorithmWrapper.h"
#ifdef _MSC_VER
#pragma warning( default: 4250 )
#endif

#include <boost/python/class.hpp>
#include <boost/python/register_ptr_to_python.hpp>
#include <boost/python/bases.hpp>
#include <boost/python/args.hpp>

using Mantid::API::Algorithm;
using Mantid::PythonInterface::AlgorithmWrapper;
using namespace boost::python;

void export_leaf_classes()
{
/**
* Export the algorithm wrapper that boost.python makes look like a PythonAlgorithm
*/
class_<AlgorithmWrapper, bases<Algorithm>, boost::noncopyable>("PythonAlgorithm", "Base class for all Python algorithms")
;
;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "MantidPythonInterface/api/PythonAlgorithm/PythonAlgorithm.h"

namespace Mantid
{
namespace PythonInterface
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from mantid.api import (PythonAlgorithm, AlgorithmProxy, Algorithm, IAlgorithm,
AlgorithmManager, registerAlgorithm)

########################### Test classes #####################################

class TestPyAlgDefaultAttrs(PythonAlgorithm):
def PyInit(self):
pass
Expand All @@ -26,7 +28,16 @@ def PyInit(self):

def PyExec(self):
pass

class TestPyAlgDeclaringProps(PythonAlgorithm):

def PyInit(self):
pass

def PyExec(self):
pass

###############################################################################

class PythonAlgorithmTest(unittest.TestCase):

Expand Down

0 comments on commit 1e3b4ec

Please sign in to comment.