#ifndef __JELEMENT__ #define __JELEMENT__ #include "JIO/JSerialisable.hh" #include "JTools/JCollection.hh" namespace JTOOLS { namespace { using JIO::JReader; using JIO::JWriter; } /** * Data structure for point in two dimensions. * * This class implements the JComparator<>::JComparable interface. */ template class JElement2D : public JComparator::JComparable { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JElement2D value_type; typedef typename JComparator::JComparable JComparable_t; /** * Default constructor. */ JElement2D() : JComparable_t(), //x(0.0), //y(0.0) x(), y() {} /** * Constructor. * * \param __x x value */ JElement2D(const key_type& __x) : JComparable_t(), x(__x), //y(0.0) y() {} /** * Constructor. * * \param __x x value * \param __y y value */ JElement2D(const key_type& __x, const mapped_type& __y) : JComparable_t(), x(__x), y(__y) {} /** * Constructor. * * \param element JComparable */ JElement2D(const JComparable_t& element) : JComparable_t(), x(element.getKey()), y(element.getValue()) {} /** * Read JElement2D from input. * * \param in JReader * \param element JElement2D * \return JReader */ friend inline JReader& operator>>(JReader& in, JElement2D& element) { in >> element.x; in >> element.y; return in; } /** * Write JElement2D to output. * * \param out JWriter * \param element JElement2D * \return JWriter */ friend inline JWriter& operator<<(JWriter& out, const JElement2D& element) { out << element.x; out << element.y; return out; } const key_type& getKey() const { return x; } const mapped_type& getValue() const { return y; } mapped_type& getValue() { return y; } void setValue(const mapped_type __y) { y = __y; } const key_type& getX() const { return x; } const mapped_type& getY() const { return y; } protected: key_type x; mapped_type y; }; /** * Data structure for JSpline. */ template class JSplineElement2D : public JElement2D { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JSplineElement2D value_type; typedef typename JComparator::JComparable JComparable_t; typedef JElement2D base_class; /** * Default constructor. */ JSplineElement2D() : base_class(), u(0.0) {} /** * Constructor. * * \param x x value */ JSplineElement2D(const key_type& x) : base_class(x), u(0.0) {} /** * Constructor. * * \param x x value * \param y y value */ JSplineElement2D(const key_type& x, const mapped_type& y) : base_class(x,y), u(0.0) {} const mapped_type& get2ndDerivative() const { return u; } void set2ndDerivative(const mapped_type& __u) { u = __u; } protected: mapped_type u; }; /** * Data structure for JSpline. */ template class JSplineElement2S : public JSplineElement2D { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JSplineElement2S value_type; typedef typename JComparator::JComparable JComparable_t; typedef JSplineElement2D base_class; /** * Default constructor. */ JSplineElement2S() : base_class(), v(0.0) {} /** * Constructor. * * \param x x value */ JSplineElement2S(const key_type& x) : base_class(x), v(0.0) {} /** * Constructor. * * \param x x value * \param y y value */ JSplineElement2S(const key_type& x, const mapped_type& y) : base_class(x,y), v(0.0) {} const mapped_type& getIntegral() const { return v; } void setIntegral(const mapped_type& __v) { v = __v; } protected: mapped_type v; }; /** * Data structure for point in three dimensions. */ class JElement3D { public: /** * Default constructor. */ JElement3D() : x(0.0), y(0.0), z(0.0) {} /** * Constructor. * * \param __x x value */ JElement3D(const double& __x) : x(__x), y(0.0), z(0.0) {} /** * Constructor. * * \param __x x value * \param __y y value */ JElement3D(const double& __x, const double& __y) : x(0.0), y(0.0), z(0.0) {} /** * Constructor. * * \param __x x value * \param __y y value * \param __z z value */ JElement3D(const double& __x, const double& __y, const double& __z) : x(__x), y(__y), z(__z) {} /** * Read JElement3D from input. * * \param in JReader * \param element JElement3D * \return JReader */ friend inline JReader& operator>>(JReader& in, JElement3D& element) { in >> element.x; in >> element.y; in >> element.z; return in; } /** * Write JElement3D to output. * * \param out JWriter * \param element JElement3D * \return JWriter */ friend inline JWriter& operator<<(JWriter& out, const JElement3D& element) { out << element.x; out << element.y; out << element.z; return out; } const double& getX() const { return x; } const double& getY() const { return y; } const double& getZ() const { return z; } protected: double x; double y; double z; }; /** * Standard data structure. */ typedef JElement2D JElement2D_t; /** * Standard data structure for JSpline. */ typedef JSplineElement2D JSplineElement2D_t; /** * Standard data structure for JSpline. */ typedef JSplineElement2S JSplineElement2S_t; /** * Standard data structure for JPolint. */ typedef JElement2D JPolintElement2D_t; } #endif