xc
RangoIndice.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 //RangoIndice.h
22 
23 #ifndef RANGOINDICE_H
24 #define RANGOINDICE_H
25 
26 #include <ostream>
27 #include <vector>
28 
31  {
32  size_t mn;
33  size_t mx;
34  static const char sep;
35  public:
36  RangoIndice(const size_t &imin= 1,const size_t &imax= 1)
37  :mn(std::min(imin,imax)),mx(std::max(imin,imax)) {}
38  explicit RangoIndice(const std::vector<size_t> &);
39  void SetInfSup(const size_t &imin,const size_t &imax);
40  const size_t &Inf(void) const
41  { return mn; }
42  size_t &Inf(void)
43  { return mn; }
44  const size_t &Sup(void) const
45  { return mx; }
46  size_t &Sup(void)
47  { return mx; }
48  size_t Size(void) const
49  { return std::max(mx-mn+1,size_t(0)); }
50  size_t Offset(void) const
51  { return mn-1; }
53  bool Vacio(void) const
54  { return (mx<mn); }
55  inline static const char &Separador(void)
56  { return sep; }
57  void Clip(const size_t &imax);
58  void Intersec(const RangoIndice &otro);
59  RangoIndice Intersec(const RangoIndice &otro) const;
60  void Print(std::ostream &os) const;
61  };
62 
63 RangoIndice clip(const RangoIndice &,const size_t &);
64 RangoIndice intersec(const RangoIndice &,const RangoIndice &);
65 
66 std::ostream &operator<<(std::ostream &os,const RangoIndice &rango);
67 
68 #endif
void Clip(const size_t &imax)
Reduce los valores del rango de manera que ambos sean menores que el que se pasa como parámetro...
Definition: RangoIndice.cc:51
void Intersec(const RangoIndice &otro)
Asigna a ESTE la intersección de ambos rangos.
Definition: RangoIndice.cc:58
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: RangoIndice.h:30
void Print(std::ostream &os) const
Imprime el rango.
Definition: RangoIndice.cc:40
bool Vacio(void) const
Devuelve verdadero si el rango no contiene ningún índice.
Definition: RangoIndice.h:53