Skip to content
Snippets Groups Projects
Commit 14e4bd1c authored by janwych's avatar janwych
Browse files

DOOCSProcessVariableFactory implementation for single variables - draft

git-svn-id: https://svnsrv.desy.de/desy/mtca4u_applications/DOOCS_Adapter/trunk@48 688d77b5-b833-4f6b-b27f-eb88d88625d6
parent 3a9d7288
No related branches found
No related tags found
No related merge requests found
......@@ -8,8 +8,10 @@
#include "ProcessVariable.h"
// friends
struct CallbacksTestFixture;
struct InterPVTestFixture;
class DOOCSProcessVariableFactory;
namespace mtca4u {
......@@ -29,6 +31,9 @@ protected:
// test structs to access the constructor
friend struct ::CallbacksTestFixture;
friend struct ::InterPVTestFixture;
// the factory needs to be able to reach the constructor
friend class DOOCSProcessVariableFactory;
public:
......
#ifndef __dpvaf__
#define __dpvaf__
#include <boost/any.hpp>
#include "ProcessVariableFactory.h"
#include "eq_fct.h"
#include "m4uD_type.hpp"
#include "DOOCSProcessVariableAdapter.hpp"
namespace mtca4u{
class DOOCSProcessVariableFactory : public ProcessVariableFactory {
EqFct *ef;
protected:
boost::any createProcessVariable ( std::type_info const & variableType, std::string name )
{
if(variableType == typeid(int) ) {
boost::shared_ptr< m4uD_type<int, D_int> > mydtype ( new m4uD_type<int, D_int> ( name.c_str(), ef ) );
return boost::shared_ptr < ProcessVariable<int> > ( new DOOCSProcessVariableAdapter<int , m4uD_type<int , D_int > > (mydtype) );
} else
if(variableType == typeid(float) ) {
boost::shared_ptr< m4uD_type<float, D_float> > mydtype ( new m4uD_type<float, D_float> ( name.c_str(), ef ) );
return boost::shared_ptr < ProcessVariable<float> > ( new DOOCSProcessVariableAdapter<float , m4uD_type<float , D_float > > (mydtype) );
} else
if(variableType == typeid(double) ) {
boost::shared_ptr< m4uD_type<double, D_double> > mydtype ( new m4uD_type<double, D_double> ( name.c_str(), ef ) );
return boost::shared_ptr < ProcessVariable<double> > ( new DOOCSProcessVariableAdapter<double, m4uD_type<double, D_double> > (mydtype) );
} else
// TODO STRING!!!
{
throw std::bad_typeid();
}
}
boost::any createProcessArray ( std::type_info const & variableType, std::string name, size_t arraySize) { return NULL; } // TODO proper implementation to come after arrays support
public:
DOOCSProcessVariableFactory (EqFct *_ef) : ef(_ef) {}
};
}// namespace mtca4u
#endif // __dpvaf__
#define BOOST_TEST_MODULE test_dpva_f
#include <boost/test/included/unit_test.hpp>
using namespace boost::unit_test;
#include "DOOCSProcessVariableFactory.hpp"
BOOST_AUTO_TEST_CASE( testGetProcessVariable )
{
mtca4u::DOOCSProcessVariableFactory DOOCSPVFactory( NULL );
boost::shared_ptr<mtca4u::ProcessVariable<int> > firstInteger = DOOCSPVFactory.getProcessVariable<int>("firstInteger");
firstInteger->set(42);
boost::shared_ptr<mtca4u::ProcessVariable<int> > secondInteger = DOOCSPVFactory.getProcessVariable<int>("firstInteger");
boost::shared_ptr<mtca4u::ProcessVariable<int> > thirdInteger = DOOCSPVFactory.getProcessVariable<int>("thirdInteger");
thirdInteger->set(55);
// make sure the second integer is the same instance as the first integer, but the third is not
BOOST_CHECK_EQUAL(*secondInteger, 42);
secondInteger->set(43);
BOOST_CHECK_EQUAL(*firstInteger, 43);
BOOST_CHECK_EQUAL(*thirdInteger, 55);
BOOST_CHECK_THROW( DOOCSPVFactory.getProcessVariable<uint64_t>("tooLong"), std::bad_typeid );
BOOST_CHECK_THROW( DOOCSPVFactory.getProcessVariable<double>("firstInteger"), std::bad_cast ); // FIXME why not boost::bad_any_cast?
// check that name conflicts with arrays work
//~ boost::shared_ptr<mtca4u::ProcessArray<int> > intArray = DOOCSPVFactory.getProcessArray<int>("intArray", 42);
//~ BOOST_CHECK_THROW( DOOCSPVFactory.getProcessVariable<int>("intArray"), boost::bad_any_cast );
}
/*
BOOST_AUTO_TEST_CASE( testGetProcessVariable )
{
mtca4u::StubProcessVariableFactory stubProcessVariableFactory;
boost::shared_ptr<mtca4u::ProcessVariable<int> > firstInteger = stubProcessVariableFactory.getProcessVariable<int>("firstInteger");
firstInteger->set(42);
boost::shared_ptr<mtca4u::ProcessVariable<int> > secondInteger = stubProcessVariableFactory.getProcessVariable<int>("firstInteger");
boost::shared_ptr<mtca4u::ProcessVariable<int> > thirdInteger = stubProcessVariableFactory.getProcessVariable<int>("thirdInteger");
thirdInteger->set(55);
// make sure the second integer is the same instance as the first integer, but the third is not
BOOST_CHECK(*secondInteger == 42);
secondInteger->set(43);
BOOST_CHECK(*firstInteger == 43);
BOOST_CHECK(*thirdInteger == 55);
BOOST_CHECK_THROW( stubProcessVariableFactory.getProcessVariable<uint64_t>("tooLong"), std::bad_typeid );
BOOST_CHECK_THROW( stubProcessVariableFactory.getProcessVariable<double>("firstInteger"), boost::bad_any_cast );
// check that name conflicts with arrays work
boost::shared_ptr<mtca4u::ProcessArray<int> > intArray = stubProcessVariableFactory.getProcessArray<int>("intArray", 42);
BOOST_CHECK_THROW( stubProcessVariableFactory.getProcessVariable<int>("intArray"), boost::bad_any_cast );
}
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment