FreeFOAM The Cross-Platform CFD Toolkit
Keyed.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 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 <OpenFOAM/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 List<label>& 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  //- Construct by transferring the item, with a key
95  inline Keyed(const Xfer<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 // ************************ vim: set sw=4 sts=4 et: ************************ //