C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
DimensionsBookkeeper.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 // -*- C++ -*-
4 #ifndef CPPQEDCORE_QUANTUMDATA_DIMENSIONSBOOKKEEPER_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_DIMENSIONSBOOKKEEPER_H_INCLUDED
6 
7 #include "DimensionsBookkeeperFwd.h"
8 
9 #include "Exception.h"
10 #include "TMP_Tools.h"
11 #include "BlitzTiny.h"
12 
13 namespace mpl=boost::mpl;
14 
15 
18 
19 
21 
27 template<int RANK, bool IS_CONST>
29 {
30 public:
31  static const int N_RANK=RANK;
32  static const int DIMESIONS_BOOKKEEPER_RANK=RANK;
33 
35 
37 
44  explicit DimensionsBookkeeper(mpl::bool_<IS_CONST> =mpl::false_())
45  : dimensions_(), totalDimension_() {}
46 
47  explicit DimensionsBookkeeper(const Dimensions& dimensions)
48  : dimensions_(dimensions), totalDimension_(product(dimensions)) {}
49 
50  const Dimensions& getDimensions () const {return dimensions_;}
51  size_t getTotalDimension() const {return totalDimension_;}
52 
53  size_t getDimension(mpl::int_<RANK> =mpl::int_<1>()) const {return totalDimension_;}
54 
55  size_t getDimension(size_t i) const {return dimensions_[i];}
56 
57  void setDimensions(const Dimensions& dimensions) {dimensions_=dimensions; totalDimension_=product(dimensions);}
58 
59 private:
62 
63 };
64 
65 
67 template<int RANK, bool IS_CONST1, bool IS_CONST2>
68 inline bool
70 {
71  return blitz::all(d1.getDimensions()==d2.getDimensions());
72 }
73 
75 template<int RANK, bool IS_CONST1, bool IS_CONST2>
76 inline bool
78 {
79  return !(d1==d2);
80 }
81 
82 #endif // CPPQEDCORE_QUANTUMDATA_DIMENSIONSBOOKKEEPER_H_INCLUDED
The class that is (meant to be, at least) the base of all exceptions in the framework.
Definition: Exception.h:18
Applies add_const if ADD_CONST = true.
Definition: TMP_Tools.h:62
blitz::TinyVector< size_t, RANK > ExtTiny
A tiny vector describing extensions of objects of arbitrary arity.
Definition: BlitzTiny.h:29
bool operator!=(const DimensionsBookkeeper< RANK, IS_CONST1 > &d1, const DimensionsBookkeeper< RANK, IS_CONST2 > &d2)
dimensionality comparison for types derived from DimensionsBookkeeper
DimensionsBookkeeper(const Dimensions &dimensions)
Standard constructor usable also in the IS_CONST=true case.
Thrown in the case of dimensionality mismatch of constructs over the same Hilbert space...
Stores and manipulates dimensions of constructs over composite Hilbert spaces of arbitrary arity...
DimensionsBookkeeper(mpl::bool_< IS_CONST >=mpl::false_())
Constructor usable only in the IS_CONST=false case.
size_t getDimension(mpl::int_< RANK >=mpl::int_< 1 >()) const
Get the (single) dimension for a unary system.
static const int DIMESIONS_BOOKKEEPER_RANK
Ditto (to break ambiguity if a class is derived from another base featuring N_RANK).
Defines template aliases for blitz::TinyVectors used for characterising the size of multi-arrays and ...
bool operator==(const DimensionsBookkeeper< RANK, IS_CONST1 > &d1, const DimensionsBookkeeper< RANK, IS_CONST2 > &d2)
dimensionality comparison for types derived from DimensionsBookkeeper
void setDimensions(const Dimensions &dimensions)
This will work only in the non-const case.
const Dimensions & getDimensions() const
Get the Dimensions vector.
static const int N_RANK
Arity of the Hilbert space.
Template metaprogramming tools, extending (and based on) Boost.MPL.
ExtTiny< RANK > Dimensions
The dimensions as a static vector of size N_RANK.
Defines tentative base classes for the exception classes of the framework.
size_t getTotalDimension() const
Get the total dimension of a system of arbitrary arity.