ESA JPIP server  0.1
range.h
Go to the documentation of this file.
1 #ifndef _JPEG2000_RANGE_H_
2 #define _JPEG2000_RANGE_H_
3 
4 
5 #include <iostream>
6 #include <assert.h>
7 
8 
9 namespace jpeg2000
10 {
11  using namespace std;
12 
13 
20  class Range
21  {
22  public:
23  int first;
24  int last;
25 
26 
31  {
32  first = 0;
33  last = 0;
34  }
35 
41  Range(int first, int last)
42  {
43  assert((first >= 0) && (first <= last));
44 
45  this->first = first;
46  this->last = last;
47  }
48 
52  Range(const Range& range)
53  {
54  *this = range;
55  }
56 
60  Range& operator=(const Range& range)
61  {
62  first = range.first;
63  last = range.last;
64 
65  return *this;
66  }
67 
73  bool IsValid() const
74  {
75  return ((first >= 0) && (first <= last));
76  }
77 
84  int GetItem(int i) const
85  {
86  return (first + i);
87  }
88 
94  int GetIndex(int item) const
95  {
96  return (item - first);
97  }
98 
102  int Length() const
103  {
104  return (last - first + 1);
105  }
106 
107  friend bool operator==(const Range& a, const Range& b)
108  {
109  return ((a.first == b.first) && (a.last == b.last));
110  }
111 
112  friend bool operator!=(const Range& a, const Range& b)
113  {
114  return ((a.first != b.first) || (a.last != b.last));
115  }
116 
117  friend ostream& operator << (ostream &out, const Range &range)
118  {
119  if(range.IsValid()) out << "[" << range.first << " - " << range.last << "]";
120  else out << "[ ]";
121 
122  return out;
123  }
124 
125  virtual ~Range()
126  {
127  }
128  };
129 
130 }
131 
132 
133 #endif /* _JPEG2000_RANGE_H_ */
friend bool operator!=(const Range &a, const Range &b)
Definition: range.h:112
int GetItem(int i) const
Returns an item of the range, starting at the first value.
Definition: range.h:84
STL namespace.
friend bool operator==(const Range &a, const Range &b)
Definition: range.h:107
int first
First value of the range.
Definition: range.h:23
int GetIndex(int item) const
Returns the index of an item of the range.
Definition: range.h:94
int Length() const
Returns the length of the range (last - first + 1).
Definition: range.h:102
virtual ~Range()
Definition: range.h:125
Range()
Initializes the object.
Definition: range.h:30
bool IsValid() const
Returns true if the first value if greater or equal to zero, and it is less or equal to the last valu...
Definition: range.h:73
Represents a range of integer values, defined by two values, first and last, which are assumed to be ...
Definition: range.h:20
Set of classes for handling (reading and indexing) image files with the format defined in the Part 1 ...
Definition: codestream_index.h:10
Range(int first, int last)
Initializes the object.
Definition: range.h:41
Range & operator=(const Range &range)
Copy assignment.
Definition: range.h:60
int last
Last value of the range.
Definition: range.h:24
Range(const Range &range)
Copy constructor.
Definition: range.h:52
ostream & operator<<(ostream &out, const Request &request)
Definition: request.cc:65