Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Range1D.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10// Range1D class used for representing a range of positive integers.
11// Its primary usage is in accessing vectors and matrices by subregions
12// of rows and columns
13//
14
15#ifndef TEUCHOS_RANGE1D_HPP
16#define TEUCHOS_RANGE1D_HPP
17
23#include "Teuchos_Assert.hpp"
24
25
26namespace Teuchos {
27
28
56class Range1D {
57public:
58
60 typedef Teuchos_Ordinal Index;
61
63 typedef Teuchos_Ordinal Ordinal;
64
66 enum EInvalidRange { INVALID };
67
69 static const Range1D Invalid;
70
80 inline Range1D();
81
91 inline Range1D(EInvalidRange);
92
112
114 inline bool full_range() const;
115
117 inline Ordinal lbound() const;
118
120 inline Ordinal ubound() const;
121
123 inline Ordinal size() const;
124
126 inline bool in_range(Ordinal i) const;
127
132 inline Range1D& operator+=( Ordinal incr );
133
138 inline Range1D& operator-=( Ordinal incr );
139
140private:
141
142 Ordinal lbound_;
143 Ordinal ubound_;
144
145 inline void assert_valid_range(Ordinal lbound, Ordinal ubound) const;
146
147}; // end class Range1D
148
149
156inline bool operator==(const Range1D& rng1, const Range1D& rng2 )
157{
158 return rng1.lbound() == rng2.lbound() && rng1.ubound() == rng2.ubound();
159}
160
161
168inline bool operator!=(const Range1D& rng1, const Range1D& rng2 )
169{
170 return !(rng1 == rng2);
171}
172
173
186{
187 return Range1D(i+rng_rhs.lbound(), i+rng_rhs.ubound());
188}
189
190
203{
204 return Range1D(i+rng_rhs.lbound(), i+rng_rhs.ubound());
205}
206
207
220{
221 return Range1D(rng_rhs.lbound()-i, rng_rhs.ubound()-i);
222}
223
224
241{ return rng.full_range() ? Range1D(lbound,ubound) : rng; }
242
243
248TEUCHOSCORE_LIB_DLL_EXPORT
249std::ostream& operator<<(std::ostream &out, const Range1D& rng);
250
251
252// //////////////////////////////////////////////////////////
253// Inline members
254
255inline
257 : lbound_(0), ubound_(std::numeric_limits<Ordinal>::max()-1)
258{}
259
260inline
262 : lbound_(0), ubound_(-2)
263{}
264
265
266inline
268 : lbound_(lbound_in), ubound_(ubound_in)
269{
270 assert_valid_range(lbound_in,ubound_in);
271}
272
273inline
275 return (lbound_ == 0 && ubound_ == std::numeric_limits<Ordinal>::max()-1);
276}
277
278inline
280 return lbound_;
281}
282
283inline
285 return ubound_;
286}
287
288inline
290 return ubound_ - lbound_ + 1;
291}
292
293inline
295 return lbound_ <= i && i <= ubound_;
296}
297
298inline
300 assert_valid_range( lbound_ + incr, ubound_ + incr );
301 lbound_ += incr;
302 ubound_ += incr;
303 return *this;
304}
305
306inline
308{
309 assert_valid_range( lbound_ - incr, ubound_ - incr );
310 lbound_ -= incr;
311 ubound_ -= incr;
312 return *this;
313}
314
315
316// See Range1D.cpp
317inline
318void Range1D::assert_valid_range(Ordinal lbound_in, Ordinal ubound_in) const
319{
321#ifdef TEUCHOS_DEBUG
324#endif
325}
326
327} // end namespace Teuchos
328
329#endif // end TEUCHOS_RANGE1D_HPP
Defines basic traits for the scalar field type.
Smart reference counting pointer class for automatic garbage collection.
Subregion Index Range Class.
Range1D operator+(const Range1D &rng_rhs, Range1D::Ordinal i)
rng_lhs = rng_rhs + i.
Range1D & operator-=(Ordinal incr)
Deincrement the range by a constant.
Range1D full_range(const Range1D &rng, Range1D::Ordinal lbound, Range1D::Ordinal ubound)
Return a bounded index range from a potentially unbounded index range.
bool full_range() const
Returns true if the range represents the entire region.
Teuchos_Ordinal Index
Deprecated.
Ordinal size() const
Return the size of the range (ubound() - lbound() + 1)
Range1D & operator+=(Ordinal incr)
Increment the range by a constant.
Range1D operator+(Range1D::Ordinal i, const Range1D &rng_rhs)
rng_lhs = i + rng_rhs.
TEUCHOSCORE_LIB_DLL_EXPORT std::ostream & operator<<(std::ostream &out, const Range1D &rng)
Print out to ostream.
Range1D()
Construct a full range.
bool operator!=(const Range1D &rng1, const Range1D &rng2)
rng1 == rng2.
static const Range1D Invalid
Used for Range1D(INVALID)
Ordinal lbound() const
Return lower bound of the range.
bool in_range(Ordinal i) const
Return true if the index is in range.
Teuchos_Ordinal Ordinal
Deprecated.
Range1D operator-(const Range1D &rng_rhs, Range1D::Ordinal i)
rng_lhs = rng_rhs - i.
bool operator==(const Range1D &rng1, const Range1D &rng2)
rng1 == rng2.
Ordinal ubound() const
Return upper bound of the range.
#define TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2)
This macro is checks that an inequality between two numbers is satisified and if not then throws a go...
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...