OpenStructure
mat2.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef GEOM_MAT2_HH
20 #define GEOM_MAT2_HH
21 
22 #include <cstddef> // for size_t
23 #include <ostream>
24 #include <cassert>
25 
26 #include <boost/operators.hpp>
27 
29 
30 namespace geom {
31 
33  private boost::equality_comparable<Mat2>,
34  private boost::additive<Mat2>,
35  private boost::multiplicative2<Mat2, Real>
36 {
37 public:
38  static Mat2 Identity();
39 
41  Mat2();
42 
44 
52  Mat2(Real i00, Real i01, Real i10, Real i11);
53 
55  Mat2(const Mat2& m);
56 
58  explicit Mat2(const Real[4]);
59 
61  Mat2& operator=(const Mat2& m);
62 
64  bool operator==(const Mat2& rhs) const;
65 
67  Real& operator()(std::size_t r, std::size_t c)
68  {
69  assert(r<=1 && c<=1);
70  return data_[r][c];
71  }
73  const Real& operator()(std::size_t r, std::size_t c) const
74  {
75  assert(r<=1 && c<=1);
76  return data_[r][c];
77  }
78 
80  Mat2& operator+=(const Mat2& rhs);
82  Mat2& operator-=(const Mat2& rhs);
83 
84  Mat2& operator*=(const Real d);
85  Mat2& operator/=(const Real d);
86 
87  Mat2& operator*=(const Mat2& m);
88 
89  Real* Data() {return &data_[0][0];}
90  const Real* Data() const {return &data_[0][0];}
91 
92 private:
93  Real data_[2][2];
94 
95  void set(Real i00, Real i01, Real i10, Real i11);
96 };
97 
98 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& os, const Mat2& m);
99 
100 } // ns geom
101 
102 
103 #endif