Keyed.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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::Keyed
26 
27 Description
28  A container with an integer key attached to any item.
29 
30  The key can useful for sorting.
31 
32 SourceFiles
33  KeyedI.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Keyed_H
38 #define Keyed_H
39 
40 #include "List.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of friend functions and operators
48 
49 template<class T> class Keyed;
50 
51 template<class T> Istream& operator>>(Istream&, Keyed<T>&);
52 template<class T> Ostream& operator<<(Ostream&, const Keyed<T>&);
53 
54 /*---------------------------------------------------------------------------*\
55  Class Keyed Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class T>
59 class Keyed
60 :
61  public T
62 {
63  // Private Data
64 
65  label key_;
66 
67 public:
68 
69  // Static Members
70 
71  //- Add labels to a list of values
72  inline static List<Keyed<T>> createList
73  (
74  const List<T>&,
75  const label key=0
76  );
77 
78  //- Add labels to a list of values
79  inline static List<Keyed<T>> createList
80  (
81  const List<T>&,
82  const labelUList& keys
83  );
84 
85 
86  // Constructors
87 
88  //- Construct null
89  inline Keyed();
90 
91  //- Construct as a copy of item, with a key
92  inline Keyed(const T& item, const label key=0);
93 
94  //- Move constructor transferring the item, with a key
95  inline Keyed(T&& item, const label key=0);
96 
97  //- Construct from Istream
98  inline Keyed(Istream&);
99 
100 
101  // Member Functions
102 
103  // Access
104 
105  //- Return const access to the integer key
106  inline label key() const;
107 
108  //- Return non-const access to the integer key
109  inline label& key();
110 
111 
112  // IOstream Operators
113 
114  friend Istream& operator>> <T>(Istream&, Keyed<T>&);
115  friend Ostream& operator<< <T>(Ostream&, const Keyed<T>&);
116 };
117 
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 } // End namespace Foam
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 #include "KeyedI.H"
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 #endif
130 
131 // ************************************************************************* //
A container with an integer key attached to any item.
Definition: Keyed.H:48
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Keyed()
Construct null.
Definition: KeyedI.H:33
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static List< Keyed< T > > createList(const List< T > &, const label key=0)
Add labels to a list of values.
Definition: KeyedI.H:79
Istream & operator>>(Istream &, directionInfo &)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
label key() const
Return const access to the integer key.
Definition: KeyedI.H:65
Namespace for OpenFOAM.