Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_Range1D.hpp
Go to the documentation of this file.
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Teuchos: Common Tools Package
5
// Copyright (2004) Sandia Corporation
6
//
7
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8
// license for use of this work by or on behalf of the U.S. Government.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38
//
39
// ***********************************************************************
40
// @HEADER
41
42
// Range1D class used for representing a range of positive integers.
43
// Its primary usage is in accessing vectors and matrices by subregions
44
// of rows and columns
45
//
46
47
#ifndef TEUCHOS_RANGE1D_HPP
48
#define TEUCHOS_RANGE1D_HPP
49
53
54
#include "
Teuchos_ScalarTraits.hpp
"
55
#include "
Teuchos_Assert.hpp
"
56
57
58
namespace
Teuchos
{
59
60
88
class
Range1D
{
89
public
:
90
92
typedef
Teuchos_Ordinal
Index
;
93
95
typedef
Teuchos_Ordinal
Ordinal
;
96
98
enum
EInvalidRange
{
INVALID
};
99
101
static
const
Range1D
Invalid
;
102
112
inline
Range1D
();
113
123
inline
Range1D
(
EInvalidRange
);
124
143
inline
Range1D
(
Ordinal
lbound
,
Ordinal
ubound
);
144
146
inline
bool
full_range
()
const
;
147
149
inline
Ordinal
lbound
()
const
;
150
152
inline
Ordinal
ubound
()
const
;
153
155
inline
Ordinal
size
()
const
;
156
158
inline
bool
in_range
(
Ordinal
i)
const
;
159
164
inline
Range1D
&
operator+=
(
Ordinal
incr );
165
170
inline
Range1D
&
operator-=
(
Ordinal
incr );
171
172
private
:
173
174
Ordinal
lbound_
;
175
Ordinal
ubound_
;
176
177
inline
void
assert_valid_range
(
Ordinal
lbound
,
Ordinal
ubound
)
const
;
178
179
};
// end class Range1D
180
181
188
inline
bool
operator==
(
const
Range1D
& rng1,
const
Range1D
& rng2 )
189
{
190
return
rng1.
lbound
() == rng2.
lbound
() && rng1.
ubound
() == rng2.
ubound
();
191
}
192
193
200
inline
bool
operator!=
(
const
Range1D
& rng1,
const
Range1D
& rng2 )
201
{
202
return
!(rng1 == rng2);
203
}
204
205
217
inline
Range1D
operator+
(
const
Range1D
&rng_rhs,
Range1D::Ordinal
i)
218
{
219
return
Range1D
(i+rng_rhs.
lbound
(), i+rng_rhs.
ubound
());
220
}
221
222
234
inline
Range1D
operator+
(
Range1D::Ordinal
i,
const
Range1D
&rng_rhs)
235
{
236
return
Range1D
(i+rng_rhs.
lbound
(), i+rng_rhs.
ubound
());
237
}
238
239
251
inline
Range1D
operator-
(
const
Range1D
&rng_rhs,
Range1D::Ordinal
i)
252
{
253
return
Range1D
(rng_rhs.
lbound
()-i, rng_rhs.
ubound
()-i);
254
}
255
256
272
inline
Range1D
full_range
(
const
Range1D
&rng,
Range1D::Ordinal
lbound
,
Range1D::Ordinal
ubound
)
273
{
return
rng.
full_range
() ?
Range1D
(
lbound
,
ubound
) : rng; }
274
275
280
TEUCHOSCORE_LIB_DLL_EXPORT
281
std::ostream&
operator<<
(std::ostream &out,
const
Range1D
& rng);
282
283
284
// //////////////////////////////////////////////////////////
285
// Inline members
286
287
inline
288
Range1D::Range1D
()
289
:
lbound_
(0),
ubound_
(
std
::numeric_limits<
Ordinal
>::max()-1)
290
{}
291
292
inline
293
Range1D::Range1D
(
EInvalidRange
)
294
:
lbound_
(0),
ubound_
(-2)
295
{}
296
297
298
inline
299
Range1D::Range1D
(
Ordinal
lbound_in,
Ordinal
ubound_in)
300
:
lbound_
(lbound_in),
ubound_
(ubound_in)
301
{
302
assert_valid_range
(lbound_in,ubound_in);
303
}
304
305
inline
306
bool
Range1D::full_range
()
const
{
307
return
(
lbound_
== 0 &&
ubound_
== std::numeric_limits<Ordinal>::max()-1);
308
}
309
310
inline
311
Range1D::Ordinal
Range1D::lbound
()
const
{
312
return
lbound_
;
313
}
314
315
inline
316
Range1D::Ordinal
Range1D::ubound
()
const
{
317
return
ubound_
;
318
}
319
320
inline
321
Range1D::Ordinal
Range1D::size
()
const
{
322
return
ubound_
-
lbound_
+ 1;
323
}
324
325
inline
326
bool
Range1D::in_range
(
Ordinal
i)
const
{
327
return
lbound_
<= i && i <=
ubound_
;
328
}
329
330
inline
331
Range1D
&
Range1D::operator+=
(
Ordinal
incr ) {
332
assert_valid_range
(
lbound_
+ incr,
ubound_
+ incr );
333
lbound_
+= incr;
334
ubound_
+= incr;
335
return
*
this
;
336
}
337
338
inline
339
Range1D
&
Range1D::operator-=
(
Ordinal
incr )
340
{
341
assert_valid_range
(
lbound_
- incr,
ubound_
- incr );
342
lbound_
-= incr;
343
ubound_
-= incr;
344
return
*
this
;
345
}
346
347
348
// See Range1D.cpp
349
inline
350
void
Range1D::assert_valid_range
(
Ordinal
lbound_in,
Ordinal
ubound_in)
const
351
{
352
(void)lbound_in; (void)ubound_in;
353
#ifdef TEUCHOS_DEBUG
354
TEUCHOS_ASSERT_INEQUALITY
(lbound_in, >=, 0);
355
TEUCHOS_ASSERT_INEQUALITY
(ubound_in, >=, lbound_in - 1);
356
#endif
357
}
358
359
}
// end namespace Teuchos
360
361
#endif
// end TEUCHOS_RANGE1D_HPP
Teuchos_Assert.hpp
Teuchos_Ordinal
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
Definition
Teuchos_ConfigDefs.hpp:141
TEUCHOSCORE_LIB_DLL_EXPORT
#define TEUCHOSCORE_LIB_DLL_EXPORT
Definition
Teuchos_DLLExportMacro.h:9
Teuchos_ScalarTraits.hpp
Defines basic traits for the scalar field type.
Teuchos::Range1D::operator+
Range1D operator+(const Range1D &rng_rhs, Range1D::Ordinal i)
rng_lhs = rng_rhs + i.
Definition
Teuchos_Range1D.hpp:217
Teuchos::Range1D::operator-=
Range1D & operator-=(Ordinal incr)
Deincrement the range by a constant.
Definition
Teuchos_Range1D.hpp:339
Teuchos::Range1D::full_range
Range1D full_range(const Range1D &rng, Range1D::Ordinal lbound, Range1D::Ordinal ubound)
Return a bounded index range from a potentially unbounded index range.
Definition
Teuchos_Range1D.hpp:272
Teuchos::Range1D::full_range
bool full_range() const
Returns true if the range represents the entire region.
Definition
Teuchos_Range1D.hpp:306
Teuchos::Range1D::Index
Teuchos_Ordinal Index
Deprecated.
Definition
Teuchos_Range1D.hpp:92
Teuchos::Range1D::ubound_
Ordinal ubound_
Definition
Teuchos_Range1D.hpp:175
Teuchos::Range1D::lbound_
Ordinal lbound_
Definition
Teuchos_Range1D.hpp:174
Teuchos::Range1D::size
Ordinal size() const
Return the size of the range (ubound() - lbound() + 1).
Definition
Teuchos_Range1D.hpp:321
Teuchos::Range1D::EInvalidRange
EInvalidRange
Definition
Teuchos_Range1D.hpp:98
Teuchos::Range1D::INVALID
@ INVALID
Definition
Teuchos_Range1D.hpp:98
Teuchos::Range1D::operator+=
Range1D & operator+=(Ordinal incr)
Increment the range by a constant.
Definition
Teuchos_Range1D.hpp:331
Teuchos::Range1D::operator+
Range1D operator+(Range1D::Ordinal i, const Range1D &rng_rhs)
rng_lhs = i + rng_rhs.
Definition
Teuchos_Range1D.hpp:234
Teuchos::Range1D::operator<<
TEUCHOSCORE_LIB_DLL_EXPORT std::ostream & operator<<(std::ostream &out, const Range1D &rng)
Print out to ostream.
Teuchos::Range1D::Range1D
Range1D()
Construct a full range.
Definition
Teuchos_Range1D.hpp:288
Teuchos::Range1D::operator!=
bool operator!=(const Range1D &rng1, const Range1D &rng2)
rng1 == rng2.
Definition
Teuchos_Range1D.hpp:200
Teuchos::Range1D::Invalid
static const Range1D Invalid
Used for Range1D(INVALID).
Definition
Teuchos_Range1D.hpp:101
Teuchos::Range1D::assert_valid_range
void assert_valid_range(Ordinal lbound, Ordinal ubound) const
Definition
Teuchos_Range1D.hpp:350
Teuchos::Range1D::lbound
Ordinal lbound() const
Return lower bound of the range.
Definition
Teuchos_Range1D.hpp:311
Teuchos::Range1D::in_range
bool in_range(Ordinal i) const
Return true if the index is in range.
Definition
Teuchos_Range1D.hpp:326
Teuchos::Range1D::Ordinal
Teuchos_Ordinal Ordinal
Deprecated.
Definition
Teuchos_Range1D.hpp:95
Teuchos::Range1D::operator-
Range1D operator-(const Range1D &rng_rhs, Range1D::Ordinal i)
rng_lhs = rng_rhs - i.
Definition
Teuchos_Range1D.hpp:251
Teuchos::Range1D::operator==
bool operator==(const Range1D &rng1, const Range1D &rng2)
rng1 == rng2.
Definition
Teuchos_Range1D.hpp:188
Teuchos::Range1D::ubound
Ordinal ubound() const
Return upper bound of the range.
Definition
Teuchos_Range1D.hpp:316
TEUCHOS_ASSERT_INEQUALITY
#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...
Definition
Teuchos_Assert.hpp:126
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
std
Definition
DefaultMpiComm_TagTests.cpp:51
Generated by
1.17.0