labelledScalar.H 4.99 KB
Newer Older
Franjo's avatar
Franjo committed
1
2
3
4
5
6
7
8
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
Andrew Heather's avatar
Andrew Heather committed
9
    This file is part of OpenFOAM.
Franjo's avatar
Franjo committed
10

Andrew Heather's avatar
Andrew Heather committed
11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
Franjo's avatar
Franjo committed
15

Andrew Heather's avatar
Andrew Heather committed
16
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
Franjo's avatar
Franjo committed
17
18
19
20
21
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
Andrew Heather's avatar
Andrew Heather committed
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
Franjo's avatar
Franjo committed
23
24

Class
Mark Olesen's avatar
Mark Olesen committed
25
    Foam::Module::labelledScalar
Franjo's avatar
Franjo committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

Description
    A class containing point label and its coordinates. It is used for
    exchanging data over processors

\*---------------------------------------------------------------------------*/

#ifndef labelledScalar_H
#define labelledScalar_H

#include "label.H"
#include "scalar.H"
#include "contiguous.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
44
45
namespace Module
{
Franjo's avatar
Franjo committed
46
47

/*---------------------------------------------------------------------------*\
Andrew Heather's avatar
Andrew Heather committed
48
                       Class labelledScalar Declaration
Franjo's avatar
Franjo committed
49
50
51
52
53
\*---------------------------------------------------------------------------*/

class labelledScalar
{
    // Private data
Andrew Heather's avatar
Andrew Heather committed
54

Franjo's avatar
Franjo committed
55
56
57
58
59
60
        //- label
        label sLabel_;

        //- value
        scalar value_;

Andrew Heather's avatar
Andrew Heather committed
61
62

public:
Franjo's avatar
Franjo committed
63
64

    // Constructors
Andrew Heather's avatar
Andrew Heather committed
65

Franjo's avatar
Franjo committed
66
67
68
69
70
71
72
        //- Null construct
        labelledScalar()
        :
            sLabel_(-1),
            value_(0.0)
        {}

Andrew Heather's avatar
Andrew Heather committed
73

Franjo's avatar
Franjo committed
74
75
76
77
78
79
80
        //- Construct from label and value
        labelledScalar(const label sl, const scalar s)
        :
            sLabel_(sl),
            value_(s)
        {}

Andrew Heather's avatar
Andrew Heather committed
81
82

    //- Destructor
83
    ~labelledScalar() = default;
Andrew Heather's avatar
Andrew Heather committed
84

Franjo's avatar
Franjo committed
85
86

    // Member functions
Andrew Heather's avatar
Andrew Heather committed
87

Franjo's avatar
Franjo committed
88
89
90
91
92
93
94
        //- return scalar label
        inline label scalarLabel() const
        {
            return sLabel_;
        }

        //- return the value
Andrew Heather's avatar
Andrew Heather committed
95
        inline scalar value() const
Franjo's avatar
Franjo committed
96
97
98
99
        {
            return value_;
        }

Andrew Heather's avatar
Andrew Heather committed
100

Franjo's avatar
Franjo committed
101
102
103
104
105
106
107
108
109
110
    // Member operators

        inline void operator=(const labelledScalar& ls)
        {
            sLabel_ = ls.sLabel_;
            value_ = ls.value_;
        }

        inline bool operator==(const labelledScalar& ls) const
        {
Andrew Heather's avatar
Andrew Heather committed
111
112
            if (sLabel_ == ls.sLabel_)
            {
Franjo's avatar
Franjo committed
113
                return true;
Andrew Heather's avatar
Andrew Heather committed
114
            }
Franjo's avatar
Franjo committed
115
116
117
118
119
120

            return false;
        }

        inline bool operator<(const labelledScalar& ls) const
        {
Andrew Heather's avatar
Andrew Heather committed
121
122
            if (value_ < ls.value_)
            {
Franjo's avatar
Franjo committed
123
                return true;
Andrew Heather's avatar
Andrew Heather committed
124
            }
Franjo's avatar
Franjo committed
125
126
127
128
129
130

            return false;
        }

        inline bool operator<=(const labelledScalar& ls) const
        {
Andrew Heather's avatar
Andrew Heather committed
131
132
            if (value_ <= ls.value_)
            {
Franjo's avatar
Franjo committed
133
                return true;
Andrew Heather's avatar
Andrew Heather committed
134
            }
Franjo's avatar
Franjo committed
135
136
137
138
139
140

            return false;
        }

        inline bool operator>(const labelledScalar& ls) const
        {
Andrew Heather's avatar
Andrew Heather committed
141
142
            if (value_ > ls.value_)
            {
Franjo's avatar
Franjo committed
143
                return true;
Andrew Heather's avatar
Andrew Heather committed
144
            }
Franjo's avatar
Franjo committed
145
146
147
148
149
150

            return false;
        }

        inline bool operator>=(const labelledScalar& ls) const
        {
Andrew Heather's avatar
Andrew Heather committed
151
152
            if (value_ >= ls.value_)
            {
Franjo's avatar
Franjo committed
153
                return true;
Andrew Heather's avatar
Andrew Heather committed
154
            }
Franjo's avatar
Franjo committed
155
156
157
158
159
160
161
162
163

            return false;
        }

        inline bool operator!=(const labelledScalar& ls) const
        {
            return !this->operator==(ls);
        }

Andrew Heather's avatar
Andrew Heather committed
164

Franjo's avatar
Franjo committed
165
    // Friend operators
Andrew Heather's avatar
Andrew Heather committed
166

Franjo's avatar
Franjo committed
167
168
169
170
171
172
        friend Ostream& operator<<(Ostream& os, const labelledScalar& ls)
        {
            os << token::BEGIN_LIST;
            os << ls.sLabel_ << token::SPACE;
            os << ls.value_ << token::END_LIST;

Andrew Heather's avatar
Andrew Heather committed
173
            os.check(FUNCTION_NAME);
Franjo's avatar
Franjo committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
            return os;
        }

        friend Istream& operator>>(Istream& is, labelledScalar& ls)
        {
            // Read beginning of labelledScalar
            is.readBegin("labelledScalar");

            is >> ls.sLabel_;
            is >> ls.value_;

            // Read end of labelledScalar
            is.readEnd("labelledScalar");

Andrew Heather's avatar
Andrew Heather committed
188
            is.check(FUNCTION_NAME);
Franjo's avatar
Franjo committed
189
190
191
192
            return is;
        }
};

Andrew Heather's avatar
Andrew Heather committed
193

194
195
196
197
198
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Module

//- Data for labelledScalar are contiguous
Franjo's avatar
Franjo committed
199
template<>
200
inline bool contiguous<Module::labelledScalar>()
Andrew Heather's avatar
Andrew Heather committed
201
202
203
204
{
    return true;
}

Franjo's avatar
Franjo committed
205
206
207
208
209
210
211
212
213
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //