From 76a4f0fcf3a9bf54ef910cdb2c0bebea37182391 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 26 Apr 2012 22:32:35 +1000 Subject: A new attempt. Better strategies implementation. Still lacking: - Factories (to set the ids) - Solver - Systems of equations --- impl/VariableAssignment.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 impl/VariableAssignment.hpp (limited to 'impl/VariableAssignment.hpp') diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp new file mode 100644 index 0000000..e41f3d8 --- /dev/null +++ b/impl/VariableAssignment.hpp @@ -0,0 +1,30 @@ +#ifndef VARIABLE_ASSIGNMENT_HPP +#define VARIABLE_ASSIGNMENT_HPP + +#include "Variable.hpp" + +template +struct VariableAssignment { + VariableAssignment(unsigned int length) + : _length(length), _assignment(new T[length]) { } + ~VariableAssignment() { + delete[] _assignment; + } + const T& operator[] (const Variable x) const { + if (x.id() < 0 || x.id() >= _length) { + throw "Array out of bounds"; + } + return _assignment[x.id()]; + } + T& operator[] (const Variable& x) { + if (x.id() < 0 || x.id() >= _length) { + throw "Array out of bounds"; + } + return _assignment[x.id()]; + } + private: + unsigned int _length; + T* _assignment; +}; + +#endif -- cgit v1.2.3