Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
containers
Identifiers
Keyed
KeyedI.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) 1991-2010 OpenCFD Ltd.
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
\*---------------------------------------------------------------------------*/
25
26
#include <
OpenFOAM/IOstreams.H
>
27
28
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29
30
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
32
template
<
class
T>
33
inline
Foam::Keyed<T>::Keyed
()
34
:
35
key_(-1)
36
{}
37
38
39
template
<
class
T>
40
inline
Foam::Keyed<T>::Keyed
(
const
T
& item,
const
label key)
41
:
42
T
(item),
43
key_(key)
44
{}
45
46
47
template
<
class
T>
48
inline
Foam::Keyed<T>::Keyed
(
const
Xfer<T>
& item,
const
label key)
49
:
50
T
(item),
51
key_(key)
52
{}
53
54
55
template
<
class
T>
56
inline
Foam::Keyed<T>::Keyed
(
Istream
& is)
57
{
58
is >> *
this
;
59
}
60
61
62
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63
64
template
<
class
T>
65
inline
Foam::label
Foam::Keyed<T>::key
()
const
66
{
67
return
key_;
68
}
69
70
template
<
class
T>
71
inline
Foam::label&
Foam::Keyed<T>::key
()
72
{
73
return
key_;
74
}
75
76
77
template
<
class
T>
78
inline
Foam::List<Foam::Keyed<T>
>
79
Foam::Keyed<T>::createList
(
const
List<T>
& lst,
const
label key)
80
{
81
List<Keyed<T>
> newList(lst.
size
());
82
83
forAll
(lst, elemI)
84
{
85
newList[elemI] =
Keyed
(lst[elemI], key);
86
}
87
return
newList;
88
}
89
90
91
template
<
class
T>
92
inline
Foam::List<Foam::Keyed<T>
>
93
Foam::Keyed<T>::createList
(
const
List<T>
& lst,
const
List<label>
& keys)
94
{
95
if
(lst.
size
() != keys.
size
())
96
{
97
FatalErrorIn
98
(
99
"Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
100
)
101
<<
"size mismatch adding keys to a list:"
<<
nl
102
<<
"List has size "
<< lst.
size
()
103
<<
" and keys has size "
<< keys.
size
() <<
nl
104
<<
abort
(
FatalError
);
105
}
106
107
List<Keyed<T>
> newList(lst.
size
());
108
109
forAll
(lst, elemI)
110
{
111
newList[elemI] =
Keyed
(lst[elemI], keys[elemI]);
112
}
113
return
newList;
114
}
115
116
117
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
118
119
template
<
class
T>
120
inline
Foam::Istream
&
Foam::operator>>
(
Istream
& is,
Keyed<T>
& item)
121
{
122
// Read beginning of Keyed item/key pair
123
is.
readBegin
(
"Keyed<T>"
);
124
125
is >>
static_cast<
T
&
>
(item);
126
is >> item.key_;
127
128
// Read end of Keyed item/key pair
129
is.
readEnd
(
"Keyed<T>"
);
130
131
// Check state of Ostream
132
is.
check
(
"Istream& operator>>(Istream&, Keyed&)"
);
133
134
return
is;
135
}
136
137
138
template
<
class
T>
139
inline
Foam::Ostream
& Foam::operator<<(Ostream& os, const Keyed<T>& item)
140
{
141
os <<
token::BEGIN_LIST
142
<<
static_cast<
const
T
&
>
(item)
143
<<
token::SPACE
<< item.key_
144
<<
token::END_LIST
;
145
146
return
os;
147
}
148
149
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151
// ************************ vim: set sw=4 sts=4 et: ************************ //