CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ContainerTraits.hh
Go to the documentation of this file.
1 #ifndef CASM_ContainerTraits_HH
2 #define CASM_ContainerTraits_HH
3 
4 #include <vector>
5 
6 #include "casm/external/Eigen/Dense"
7 #include "casm/misc/CASM_TMP.hh"
8 
9 namespace CASM {
10 
20 template <typename _Container>
21 struct ContainerTraits {};
22 
23 template <typename _value_type, typename Allocator>
24 struct ContainerTraits<std::vector<_value_type, Allocator> > {
25  using Container = std::vector<_value_type, Allocator>;
26  using value_type = typename Container::value_type;
27  using size_type = typename Container::size_type;
29 
30  static size_type size(const Container &vec) { return vec.size(); }
31 
32  static size_type rows(const Container &vec) { return vec.size(); }
33 
34  static size_type cols(const Container &vec) { return 1; }
35 };
36 
38 
39 template <typename _value_type, int a, int b, int c, int d, int e>
40 struct ContainerTraits<Eigen::Matrix<_value_type, a, b, c, d, e> > {
41  typedef Eigen::Matrix<_value_type, a, b, c, d, e> Container;
42  typedef typename Container::Index size_type;
43  typedef typename Container::Scalar value_type;
44  typedef typename Container::Scalar value_type2D;
46 
48  static size_type size(const Container &mat) { return mat.size(); }
49 
51  static size_type rows(const Container &mat) { return mat.rows(); }
52 
54  static size_type cols(const Container &mat) { return mat.cols(); }
55 };
56 /*
58 template<>
59 struct ContainerTraits<Eigen::VectorXd> {
60  typedef Eigen::VectorXd Container;
61  typedef Eigen::VectorXd::Index size_type;
62  typedef Eigen::VectorXd::Scalar value_type;
63  typedef Eigen::VectorXd::Scalar value_type2D;
64  typedef CASM_TMP::ParenthesesAccess<Container, value_type, size_type> Access;
65 
67  static size_type size(const Eigen::VectorXd &vec) {
68  return vec.size();
69  }
70 
72  static size_type size(const Eigen::VectorXd &vec) {
73  return vec.size();
74  }
75 
77  static size_type size(const Eigen::VectorXd &vec) {
78  return vec.size();
79  }
80 };
81 
83 template<>
84 struct ContainerTraits<Eigen::VectorXi> {
85  typedef Eigen::VectorXi Container;
86  typedef Eigen::VectorXi::Index size_type;
87  typedef Eigen::VectorXi::Scalar value_type;
88  typedef CASM_TMP::ParenthesesAccess<Container, value_type, size_type> Access;
89 
91  static size_type size(const Eigen::VectorXi &vec) {
92  return vec.size();
93  }
94 };
95 */
96 } // namespace CASM
97 
98 #endif
Main CASM namespace.
Definition: APICommand.hh:8
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Definition: stream_io.hh:24
Helper Functor for Counter container access using operator[].
Definition: CASM_TMP.hh:110
Helper Functor for Counter container access using operator()
Definition: CASM_TMP.hh:165
static size_type cols(const Container &mat)
Return size of container.
static size_type rows(const Container &mat)
Return size of container.
CASM_TMP::ParenthesesAccess< Container, value_type, size_type > Access
static size_type size(const Container &mat)
Return size of container.
Specialize container traits Expects: