GradedContainer.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <boost/operators.hpp>
4 
5 namespace boca
6 {
7 
12 template<template <typename> class Container_, typename Value_>
13 class GradedContainer : boost::totally_ordered<GradedContainer<Container_, Value_>>
14 {
15 
16 public:
17 
27 
31  GradedContainer(Container_<Value_> const& container, Value_ scalar) :
32  container_(container),
33  scalar_(scalar)
34  {}
35 
37 
46  void Set(Container_<Value_> const& container, Value_ scalar)
47  {
48  container_ = container;
49  scalar_ = scalar;
50  }
51 
55  void Set(Container_<Value_> const& container)
56  {
57  container_ = container;
58  }
59 
63  void Set(Value_ scalar)
64  {
65  scalar_ = scalar;
66  }
67 
69 
78  Container_<Value_> const& Container() const
79  {
80  return container_;
81  }
82 
86  Container_<Value_> &Container()
87  {
88  return container_;
89  }
90 
94  Value_ const& Scalar() const
95  {
96  return scalar_;
97  }
98 
102  Value_ &Scalar()
103  {
104  return scalar_;
105  }
106 
108 
117  auto Product() const
118  {
119  return container_ * scalar_;
120  }
121 
125  Container_<double> Normalize() const
126  {
127  return container_ / scalar_;
128  }
129 
131 
140  bool operator<(GradedContainer const &graded_container) const
141  {
142  return Normalize() < graded_container.Normalize();
143  }
144 
148  bool operator==(GradedContainer const &graded_container) const
149  {
150  return container_ == graded_container.container_ && scalar_ == graded_container.scalar_;
151  }
152 
156  friend auto &operator<<(std::ostream &stream, GradedContainer const &graded_container)
157  {
158  stream << Stream(graded_container.scalar_) << graded_container.container_;
159  return stream;
160  }
161 
163 
164 private:
165 
166  Container_<Value_> container_;
167 
168  Value_ scalar_ = Value_(0);
169 
170 };
171 
172 template<template <typename> class Container_, typename Value_>
173 class GradedVector : public GradedContainer<Container_, Value_>
174  , public boost::additive<GradedVector<Container_, Value_>>
175 {
176 
177 public:
178 
180 
189  Container_<Value_> &Vector()
190  {
192  }
193 
197  Container_<Value_> const& Vector() const
198  {
200  }
201 
203 
212  GradedVector &operator+=(GradedVector const &graded_container)
213  {
215  GradedContainer<Container_, Value_>::Scalar() += graded_container.Scalar();
216  return *this;
217  }
218 
222  GradedVector &operator-=(GradedVector const &graded_container)
223  {
225  GradedContainer<Container_, Value_>::Scalar() -= graded_container.Scalar();
226  return *this;
227  }
228 
230 
231 };
232 
233 template<template <typename> class Container_, typename Value_>
234 class GradedMatrix : public GradedContainer<Container_, Value_>
235  , public boost::additive<GradedMatrix<Container_, Value_>>
236 {
237 
238 public:
239 
241 
250  Container_<Value_> &Matrix()
251  {
253  }
254 
258  Container_<Value_> const& Matrix() const
259  {
261  }
262 
264 
273  GradedMatrix &operator+=(GradedMatrix const &graded_container)
274  {
276  GradedContainer<Container_, Value_>::Scalar() += graded_container.Scalar();
277  return *this;
278  }
279 
283  GradedMatrix &operator-=(GradedMatrix const &graded_container)
284  {
286  GradedContainer<Container_, Value_>::Scalar() -= graded_container.Scalar();
287  return *this;
288  }
289 
291 
292 };
293 
294 }
Container with associated scalar.
Definition: GradedContainer.hh:13
GradedContainer()
Default Constructor.
Definition: GradedContainer.hh:26
GradedContainer(Container_< Value_ > const &container, Value_ scalar)
Constructor accepting a Container and a Scalar.
Definition: GradedContainer.hh:31
Definition: GradedContainer.hh:234
Definition: GradedContainer.hh:173
Container_< Value_ > & Container()
Accessor of Container.
Definition: GradedContainer.hh:86
Container_< Value_ > const & Container() const
Getter for Container.
Definition: GradedContainer.hh:78
Container_< Value_ > const & Vector() const
Getter for Vector.
Definition: GradedContainer.hh:197
GradedMatrix & operator+=(GradedMatrix const &graded_container)
Addition.
Definition: GradedContainer.hh:273
std::string Stream(Value const &message, int width=20, bool right=false)
Definition: Debug.hh:48
void Set(Container_< Value_ > const &container, Value_ scalar)
Set Container and Scalar.
Definition: GradedContainer.hh:46
GradedMatrix & operator-=(GradedMatrix const &graded_container)
Substraction.
Definition: GradedContainer.hh:283
Container_< double > Normalize() const
Quotient.
Definition: GradedContainer.hh:125
Value_ const & Scalar() const
Getter for Scalar.
Definition: GradedContainer.hh:94
auto Product() const
Product.
Definition: GradedContainer.hh:117
GradedVector & operator+=(GradedVector const &graded_container)
Addiition.
Definition: GradedContainer.hh:212
Boosted Collider Analysis.
Definition: Analysis.hh:15
Value_ & Scalar()
Accessor for Scalar.
Definition: GradedContainer.hh:102
Container_< Value_ > & Vector()
Accessor for Vector.
Definition: GradedContainer.hh:189
bool operator<(GradedContainer const &graded_container) const
Less than comparison.
Definition: GradedContainer.hh:140
Container_< Value_ > const & Matrix() const
Getter for Matrix.
Definition: GradedContainer.hh:258
bool operator==(GradedContainer const &graded_container) const
Equallity comparison.
Definition: GradedContainer.hh:148
GradedVector & operator-=(GradedVector const &graded_container)
Substraction.
Definition: GradedContainer.hh:222
Container_< Value_ > & Matrix()
Accessor for Matrix.
Definition: GradedContainer.hh:250
void Set(Container_< Value_ > const &container)
Set Container.
Definition: GradedContainer.hh:55
void Set(Value_ scalar)
Set Scalar.
Definition: GradedContainer.hh:63
friend auto & operator<<(std::ostream &stream, GradedContainer const &graded_container)
Output stream operator.
Definition: GradedContainer.hh:156