scalarRange.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::scalarRange
26 
27 Description
28  A scalar range specifier.
29 
30  The range selector can be specified as an "LOWER:UPPER" range, as a
31  "LOWER:" bound, as an ":UPPER" bound or simply as an "EXACT" value.
32  The read constructor uses a colon (:) as a range marker and a comma (,)
33  to delimit the next possible range selector.
34 
35 SourceFiles
36  scalarRange.C
37 
38 \*---------------------------------------------------------------------------*/
39 #ifndef scalarRange_H
40 #define scalarRange_H
41 
42 #include "scalar.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of classes
50 class Istream;
51 class Ostream;
52 
53 // Forward declaration of friend functions and operators
54 class scalarRange;
55 Istream& operator>>(Istream&, scalarRange&);
56 Ostream& operator<<(Ostream&, const scalarRange&);
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class scalarRange Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class scalarRange
64 {
65  //- Enumeration defining the types of token
66  enum rangeType
67  {
68  EMPTY = 0,
69  EXACT,
70  LOWER,
71  UPPER,
72  RANGE
73  };
74 
75 
76  // Private data
77 
78  enum rangeType type_;
79  scalar value_;
80  scalar value2_;
81 
82 
83 public:
84 
85  static int debug;
86 
87 
88  // Constructors
89 
90  //- Construct an empty range
91  scalarRange();
92 
93  //- Construct a range from lower to upper
94  scalarRange(const scalar lower, const scalar upper);
95 
96  //- Construct from Istream.
97  // Since commas can be used as list delimiters,
98  // leading and trailing commas are ignored.
100 
101 
102  // Member Functions
103 
104  //- Is the range empty?
105  bool empty() const;
106 
107  //- Is the range non-empty?
108  bool valid() const;
109 
110  //- Is the range 'EXACT'?
111  bool isExact() const;
112 
113  //- The value constituting an 'EXACT' match
114  // or the values for 'UPPER' or 'LOWER' limits
115  scalar value() const;
116 
117  //- The lower limit
118  scalar lower() const;
119 
120  //- The upper limit
121  scalar upper() const;
122 
123  //- Return true if the value is within the range
124  bool selected(const scalar) const;
125 
126 
127  // Member Operators
128 
129  bool operator==(const scalarRange&) const;
130  bool operator!=(const scalarRange&) const;
131 
132 
133  // IOstream Operators
134 
136  friend Ostream& operator<<(Ostream&, const scalarRange&);
137 };
138 
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 } // End namespace Foam
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************************************************************* //
bool valid() const
Is the range non-empty?
Definition: scalarRange.C:82
bool operator!=(const scalarRange &) const
Definition: scalarRange.C:167
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool selected(const scalar) const
Return true if the value is within the range.
Definition: scalarRange.C:131
bool empty() const
Is the range empty?
Definition: scalarRange.C:76
friend Istream & operator>>(Istream &, scalarRange &)
bool operator==(const scalarRange &) const
Definition: scalarRange.C:156
Istream & operator>>(Istream &, directionInfo &)
scalar upper() const
The upper limit.
Definition: scalarRange.C:112
bool isExact() const
Is the range &#39;EXACT&#39;?
Definition: scalarRange.C:88
scalar lower() const
The lower limit.
Definition: scalarRange.C:100
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
scalarRange()
Construct an empty range.
Definition: scalarRange.C:36
friend Ostream & operator<<(Ostream &, const scalarRange &)
Ostream & operator<<(Ostream &, const ensightPart &)
static int debug
Definition: scalarRange.H:84
scalar value() const
The value constituting an &#39;EXACT&#39; match.
Definition: scalarRange.C:94
Namespace for OpenFOAM.
A scalar range specifier.
Definition: scalarRange.H:62