FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

Keyed.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::Keyed
00026 
00027 Description
00028     A container with an integer key attached to any item.
00029 
00030     The key can useful for sorting.
00031 
00032 SourceFiles
00033     KeyedI.H
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef Keyed_H
00038 #define Keyed_H
00039 
00040 #include <OpenFOAM/List.H>
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 // Forward declaration of friend functions and operators
00048 
00049 template<class T> class Keyed;
00050 
00051 template<class T> Istream& operator>>(Istream&, Keyed<T>&);
00052 template<class T> Ostream& operator<<(Ostream&, const Keyed<T>&);
00053 
00054 /*---------------------------------------------------------------------------*\
00055                        Class Keyed Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 template<class T>
00059 class Keyed
00060 :
00061     public T
00062 {
00063     // Private data
00064 
00065         label key_;
00066 
00067 public:
00068 
00069     // Static Members
00070 
00071         //- Add labels to a list of values
00072         inline static List<Keyed<T> > createList
00073         (
00074             const List<T>&,
00075             const label key=0
00076         );
00077 
00078         //- Add labels to a list of values
00079         inline static List<Keyed<T> > createList
00080         (
00081             const List<T>&,
00082             const List<label>& keys
00083         );
00084 
00085 
00086     // Constructors
00087 
00088         //- Construct null
00089         inline Keyed();
00090 
00091         //- Construct as a copy of item, with a key
00092         inline Keyed(const T& item, const label key=0);
00093 
00094         //- Construct by transferring the item, with a key
00095         inline Keyed(const Xfer<T>& item, const label key=0);
00096 
00097         //- Construct from Istream
00098         inline Keyed(Istream&);
00099 
00100 
00101     // Member Functions
00102 
00103         // Access
00104 
00105             //- Return const access to the integer key
00106             inline label key() const;
00107 
00108             //- Return non-const access to the integer key
00109             inline label& key();
00110 
00111 
00112     // IOstream Operators
00113 
00114         friend Istream& operator>> <T>(Istream&, Keyed<T>&);
00115         friend Ostream& operator<< <T>(Ostream&, const Keyed<T>&);
00116 };
00117 
00118 
00119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00120 
00121 } // End namespace Foam
00122 
00123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00124 
00125 #include "KeyedI.H"
00126 
00127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00128 
00129 #endif
00130 
00131 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines