OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include <stdexcept>
26 
27 #include <boost/operators.hpp>
28 
30 
31 namespace geom {
32 
34  private boost::equality_comparable<Mat2>,
35  private boost::additive<Mat2>,
36  private boost::multiplicative2<Mat2, Real>
37 {
38 public:
39  static Mat2 Identity();
40 
42  Mat2();
43 
45 
53  Mat2(Real i00, Real i01, Real i10, Real i11);
54 
56  Mat2(const Mat2& m);
57 
59  explicit Mat2(const Real[4]);
60 
62  Mat2& operator=(const Mat2& m);
63 
65  bool operator==(const Mat2& rhs) const;
66 
68  Real& operator()(std::size_t r, std::size_t c)
69  {
70  if (r>1 || c >1) {
71  throw std::out_of_range("row and column must be in the range [0-1]");
72  }
73  return data_[r][c];
74  }
76  const Real& operator()(std::size_t r, std::size_t c) const
77  {
78  if (r>1 || c >1) {
79  throw std::out_of_range("row and column must be in the range [0-1]");
80  }
81  return data_[r][c];
82  }
83 
85  Mat2& operator+=(const Mat2& rhs);
87  Mat2& operator-=(const Mat2& rhs);
88 
89  Mat2& operator*=(const Real d);
90  Mat2& operator/=(const Real d);
91 
92  Mat2& operator*=(const Mat2& m);
93 
94  Real* Data() {return &data_[0][0];}
95  const Real* Data() const {return &data_[0][0];}
96 
97 private:
98  Real data_[2][2];
99 
100  void set(Real i00, Real i01, Real i10, Real i11);
101 };
102 
103 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& os, const Mat2& m);
104 
105 } // ns geom
106 
107 
108 #endif