xc
BoxConstRef.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //BoxConstRef.h
22 
23 #ifndef BOXCONSTREF_H
24 #define BOXCONSTREF_H
25 
26 #include "ProtoMatrix.h"
27 #include "RangoIndice.h"
28 
30 class BoxBaseRef: public ProtoMatrix
31  {
32  protected:
33  size_t offset_f;
34  size_t offset_c;
35  public:
36  BoxBaseRef(const ProtoMatrix &m,const size_t &f1= 1,const size_t &c1= 1);
37  BoxBaseRef(const ProtoMatrix &m,const size_t &,const size_t &,const size_t &,const size_t &);
38  BoxBaseRef(const ProtoMatrix &mat,const RangoIndice &row_range,const RangoIndice &column_range);
39  BoxBaseRef(const ProtoMatrix &mat,const RangoIndice &,const size_t &);
40  BoxBaseRef(const ProtoMatrix &mat,const size_t &,const RangoIndice &);
41  RangoIndice getRowRange(void) const;
42  RangoIndice getColumnRange(void) const;
43  };
44 
46 template <class MAT>
47 class BoxConstRef: public BoxBaseRef
48  {
49  const MAT &m;
50  public:
51  typedef typename MAT::const_reference const_reference;
52 
53  BoxConstRef(const MAT &m,const size_t &f1= 1,const size_t &c1= 1);
54  BoxConstRef(const MAT &m,const size_t &,const size_t &,const size_t &,const size_t &);
55  BoxConstRef(const MAT &mat,const RangoIndice &row_range,const RangoIndice &column_range);
56  BoxConstRef(const MAT &mat,const RangoIndice &,const size_t &);
57  BoxConstRef(const MAT &mat,const size_t &,const RangoIndice &);
58  virtual const_reference operator()(size_t iRow=1,size_t col=1) const
59  { return m(iRow+offset_f,col+offset_c); }
60  void Print(std::ostream &) const;
61  };
62 
64 template<class MAT>
65 BoxConstRef<MAT>::BoxConstRef(const MAT &mat,const size_t &f1,const size_t &c1)
66  : BoxBaseRef(mat,f1,c1), m(mat) {}
67 
69 template<class MAT>
70 BoxConstRef<MAT>::BoxConstRef(const MAT &mat,const size_t &f1,const size_t &c1,const size_t &f2,const size_t &c2)
71  : BoxBaseRef(mat,f1,c1,f2,c2), m(mat)
72  {}
73 
75 template<class MAT>
76 BoxConstRef<MAT>::BoxConstRef(const MAT &mat,const RangoIndice &row_range,const RangoIndice &column_range)
77  : BoxBaseRef(mat,row_range,column_range), m(mat) {}
78 
80 template<class MAT>
81 BoxConstRef<MAT>::BoxConstRef(const MAT &mat,const RangoIndice &row_range,const size_t &col)
82  : BoxBaseRef(mat,row_range,col), m(mat) {}
83 
85 template<class MAT>
86 BoxConstRef<MAT>::BoxConstRef(const MAT &mat,const size_t &iRow,const RangoIndice &column_range)
87  : BoxBaseRef(mat,iRow,column_range), m(mat) {}
88 
89 template<class MAT>
90 void BoxConstRef<MAT>::Print(std::ostream &os) const
91  {
92  os << '[';
93  size_t n_rows= this->getNumberOfRows(),n_columns= this->getNumColumns();
94  for(size_t i= 1;i<=n_rows;i++)
95  {
96  os << '[';
97  if(n_columns > 0) os << (*this)(i,1);
98  for(size_t j= 2;j<=n_columns;j++)
99  os << ',' << (*this)(i,j);
100  os << ']';
101  }
102  os << ']';
103  }
104 
105 template <class MAT>
106 inline std::ostream &operator<<(std::ostream &os,const BoxConstRef<MAT> &c)
107  {
108  c.Print(os);
109  return os;
110  }
111 
112 #endif
Reference to a matrix box.
Definition: BoxConstRef.h:47
Definition: ProtoMatrix.h:32
size_t offset_f
row offset.
Definition: BoxConstRef.h:33
BoxBaseRef(const ProtoMatrix &m, const size_t &f1=1, const size_t &c1=1)
Constructor por defecto.
Definition: BoxConstRef.cc:25
BoxConstRef(const MAT &m, const size_t &f1=1, const size_t &c1=1)
Constructor por defecto.
Definition: BoxConstRef.h:65
RangoIndice getColumnRange(void) const
Return the column range.
Definition: BoxConstRef.cc:54
Base class for the references to a matrix box.
Definition: BoxConstRef.h:30
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: RangoIndice.h:30
size_t offset_c
column offset.
Definition: BoxConstRef.h:34
RangoIndice getRowRange(void) const
Return the row range.
Definition: BoxConstRef.cc:50