Skip to content

Commit

Permalink
Refs #8550. VectorColumn: implementation of the remaining methods.
Browse files Browse the repository at this point in the history
Plus registration macro and some additional tests.
  • Loading branch information
arturbekasov committed Dec 5, 2013
1 parent 2f3f48f commit d3ca69f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Expand Up @@ -139,18 +139,25 @@ namespace DataObjects
/// Create another copy of the column
virtual VectorColumn* clone() const
{
// TODO: implement
VectorColumn* newColumn = new VectorColumn<Type>();
newColumn->m_data = m_data;
newColumn->setName(m_name);
newColumn->setPlotType(m_plotType);
return newColumn;
}

/// Cast to double
virtual double toDouble(size_t i) const
{
UNUSED_ARG(i);
throw std::runtime_error("VectorColumn is not convertible to double.");
}

/// Assign from double
virtual void fromDouble(size_t i, double value)
{
UNUSED_ARG(i);
UNUSED_ARG(value);
throw std::runtime_error("VectorColumn is not assignable from double.");
}

Expand All @@ -164,12 +171,14 @@ namespace DataObjects
/// Inserts an item.
virtual void insert(size_t index)
{
// TODO: implement
// Insert empty vector at the given position
m_data.insert( m_data.begin() + index, std::vector<Type>() );
}

/// Removes an item.
virtual void remove(size_t index)
{
m_data.erase(m_data.begin() + index);
}

/// Pointer to a data element
Expand Down Expand Up @@ -197,6 +206,8 @@ namespace DataObjects
} // namespace Mantid

#define DECLARE_VECTORCOLUMN(Type,TypeName) \
template<> std::string VectorColumn<Type>::typeName() { return #TypeName; };
template<> std::string VectorColumn<Type>::typeName() { return #TypeName; }; \
Kernel::RegistrationHelper register_column_##TypeName( \
( API::ColumnFactory::Instance().subscribe< VectorColumn<Type> >(#TypeName), 0) ); \

#endif /* MANTID_DATAOBJECTS_VECTORCOLUMN_H_ */
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/VectorColumn.cpp
@@ -1,9 +1,14 @@
#include "MantidAPI/ColumnFactory.h"
#include "MantidDataObjects/VectorColumn.h"

namespace Mantid
{
namespace DataObjects
{
// Please feel free to declare new types as you need them. Syntax is:
// DECLARE_VECTORCOLUMN(type, name-of-the-type);

DECLARE_VECTORCOLUMN(int, vector_int);
DECLARE_VECTORCOLUMN(double, vector_double);
} // namespace DataObjects
} // namespace Mantid
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/VectorColumnTest.h
Expand Up @@ -28,6 +28,9 @@ class VectorColumnTest : public CxxTest::TestSuite
{
VectorColumn<int> col;
TS_ASSERT_EQUALS( col.type(), "vector_int");

VectorColumn<double> col2;
TS_ASSERT_EQUALS( col2.type(), "vector_double");
}

void test_read()
Expand Down

0 comments on commit d3ca69f

Please sign in to comment.