xc
MatrixRange.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 //MatrixRange.h
22 
23 #ifndef MATRIXRANGE_H
24 #define MATRIXRANGE_H
25 
26 #include "RangoIndice.h"
27 
30  {
31  RangoIndice row_range;
32  RangoIndice column_range;
33  public:
34  MatrixRange(const RangoIndice &rf,const RangoIndice &rc)
35  :row_range(rf),column_range(rc) {}
36  template <class M>
37  MatrixRange(const M &);
38  size_t getNumberOfRows(void) const
39  { return row_range.Size(); }
40  size_t getNumberOfColumns(void) const
41  { return column_range.Size(); }
42  size_t Size(void) const
43  { return getNumberOfRows()*getNumberOfColumns(); }
44  const RangoIndice &getRowRange(void) const
45  { return row_range; }
46  RangoIndice &getRowRange(void)
47  { return row_range; }
48  const RangoIndice &getColumnRange(void) const
49  { return column_range; }
50  RangoIndice &GetgetColumnRange(void)
51  { return column_range; }
52  bool isRow(void) const
53  { return (row_range.Size()==1); }
54  bool isColumn(void) const
55  { return (column_range.Size()==1); }
56  bool Vacio(void) const;
57  inline static const char &Separador(void)
58  { return RangoIndice::Separador(); }
59  void Clip(const size_t &fmax,const size_t &cmax);
60  void Intersec(const MatrixRange &otro);
61  MatrixRange Intersec(const MatrixRange &otro) const;
62  void Print(std::ostream &os) const;
63  };
64 
65 MatrixRange clip(const MatrixRange &r,const size_t &fmax,const size_t &cmax);
66 MatrixRange intersec(const MatrixRange &,const MatrixRange &);
67 template <class M>
68 MatrixRange clip(const MatrixRange &,const M &);
69 std::ostream &operator<<(std::ostream &os,const MatrixRange &rango);
70 
72 template <class M>
73 MatrixRange::MatrixRange(const M &m)
74  : row_range(1,m.getNumberOfRows()),column_range(1,m.getNumberOfColumns()) {}
75 
77 template <class M>
78 MatrixRange clip(const MatrixRange &rm,const M &m)
79  { return rm.Intersec(MatrixRange(m)); }
80 #endif
void Intersec(const MatrixRange &otro)
Asigna a ESTE la intersección de ambos rangos.
Definition: MatrixRange.cc:41
bool Vacio(void) const
Return verdadero si el rango no contiene ningún índice.
Definition: MatrixRange.cc:25
void Print(std::ostream &os) const
Imprime el rango.
Definition: MatrixRange.cc:29
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: MatrixRange.h:29
void Clip(const size_t &fmax, const size_t &cmax)
Reduce los valores del rango de manera que ambos sean menores que los being passed as parameter...
Definition: MatrixRange.cc:34
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: RangoIndice.h:30