initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / dictionary / entry / entry.H
blobddaefe74402a3a04b6ac00e7270a11a1d6c54cb3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::entry
28 Description
29     A keyword and a list of tokens is an 'entry'.
31     An entry can be read, written and printed, and the types and values of
32     its tokens analysed.  An entry is a high-level building block for data
33     description.  It is a front-end for the token parser. A list of entries
34     can be used as a set of keyword syntax elements, for example.
36 SourceFiles
37     entry.C
38     entryIO.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef entry_H
43 #define entry_H
45 #include "keyType.H"
46 #include "IDLList.H"
47 #include "fileName.H"
48 #include "autoPtr.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 class ITstream;
56 class dictionary;
58 // Forward declaration of friend functions and operators
60 class entry;
61 Ostream& operator<<(Ostream&, const entry&);
63 /*---------------------------------------------------------------------------*\
64                            Class entry Declaration
65 \*---------------------------------------------------------------------------*/
67 class entry
69     public IDLList<entry>::link
71     // Private data
73         //- Keyword of entry
74         keyType keyword_;
77     // Private Member Functions
79         //- Get the next valid keyword otherwise return false
80         static bool getKeyword(keyType& keyword, Istream& is);
83 public:
85     // Constructors
87         //- Construct from keyword
88         entry(const keyType& keyword);
90         //- Construct as copy
91         entry(const entry&);
93         //- Construct on freestore as copy with reference to the
94         //  dictionary the copy belongs to
95         virtual autoPtr<entry> clone
96         (
97             const dictionary& parentDict
98         ) const = 0;
100         //- Construct on freestore as copy
101         //  Note: the parent directory is set to dictionary::null
102         virtual autoPtr<entry> clone() const;
104         //- Construct from Istream and insert into dictionary
105         static bool New(dictionary& parentDict, Istream& is);
107         //- Construct on freestore from Istream and return
108         static autoPtr<entry> New(Istream& is);
111     // Destructor
113         virtual ~entry()
114         {}
117     // Member functions
119         //- Return keyword
120         const keyType& keyword() const
121         {
122             return keyword_;
123         }
125         //- Return non-const access to keyword
126         keyType& keyword()
127         {
128             return keyword_;
129         }
131         //- Return the dictionary name
132         virtual const fileName& name() const = 0;
134         //- Return the dictionary name
135         virtual fileName& name() = 0;
137         //- Return line number of first token in dictionary
138         virtual label startLineNumber() const = 0;
140         //- Return line number of last token in dictionary
141         virtual label endLineNumber() const = 0;
143         //- Return true if this entry is a stream
144         virtual bool isStream() const
145         {
146             return false;
147         }
149         //- Return token stream if this entry is a primitive entry
150         virtual ITstream& stream() const = 0;
152         //- Return true if this entry is a dictionary
153         virtual bool isDict() const
154         {
155             return false;
156         }
158         //- Return dictionary if this entry is a dictionary
159         virtual const dictionary& dict() const = 0;
161         //- Return non-const access to dictionary if this entry is a dictionary
162         virtual dictionary& dict() = 0;
164         //- Write
165         virtual void write(Ostream&) const = 0;
168     // Member operators
170         void operator=(const entry&);
172         bool operator==(const entry&) const;
173         bool operator!=(const entry&) const;
176     // Ostream operator
178         friend Ostream& operator<<(Ostream&, const entry&);
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 #endif
190 // ************************************************************************* //