Skip to content

Commit

Permalink
refs #9364 clone method on Parameter and test for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 25, 2014
1 parent ae95567 commit a46f4cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Expand Up @@ -79,6 +79,9 @@ namespace Mantid
const std::string& name() const { return m_name; }
/// Parameter name
const char* nameAsCString() const{ return m_name.c_str(); }

/// type-independent clone method;
virtual Parameter * clone()const=0;

/// Returns the value of the property as a string
virtual std::string asString() const{return m_str_value;}
Expand Down Expand Up @@ -135,6 +138,8 @@ namespace Mantid
/// Get the value of the parameter
inline const Type& operator()()const{ return m_value; }

Parameter * clone()const
{ return new ParameterType(*this);}
private:
friend class ParameterMap;
friend class Parameter;
Expand Down
27 changes: 27 additions & 0 deletions Code/Mantid/Framework/Geometry/test/ParameterMapTest.h
@@ -1,9 +1,11 @@
#ifndef PARAMETERMAPTEST_H_
#define PARAMETERMAPTEST_H_

#include "MantidGeometry/Instrument/Parameter.h"
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidKernel/V3D.h"
#include <cxxtest/TestSuite.h>

#include <boost/make_shared.hpp>
Expand Down Expand Up @@ -127,6 +129,31 @@ class ParameterMapTest : public CxxTest::TestSuite

}

void testClone()
{
const double value(5.1);

ParameterMap pmapA,pmapB;

pmapA.addDouble(m_testInstrument.get(), "testDouble", value);
pmapA.addV3D(m_testInstrument.get(), "testV3D", Mantid::Kernel::V3D(1,2,3));

auto parD= pmapA.getRecursive(m_testInstrument.get(),"testDouble");
auto parV3= pmapA.getRecursive(m_testInstrument.get(),"testV3D");

Mantid::Geometry::Parameter *pParD = parD->clone();
Mantid::Geometry::Parameter *pParV = parV3->clone();

TS_ASSERT_EQUALS(pParD->asString(),parD->asString())
TS_ASSERT_EQUALS(pParV->asString(),parV3->asString())

pmapB.add(m_testInstrument.get(),Parameter_sptr(pParD));
pmapB.add(m_testInstrument.get(),Parameter_sptr(pParV));

TS_ASSERT_EQUALS(pmapA,pmapB);
}


void testAdding_A_Parameter_That_Is_Not_Present_Puts_The_Parameter_In()
{
// Add a parameter for the first component of the instrument
Expand Down

0 comments on commit a46f4cd

Please sign in to comment.