initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / db / dictionary / entry / entry.H
blob5afab95b5ad4e69083711f76b58ca404004d61e6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "IDLList.H"
46 #include "fileName.H"
47 #include "autoPtr.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 namespace Foam
54 class ITstream;
55 class dictionary;
57 // Forward declaration of friend functions and operators
59 class entry;
60 Ostream& operator<<(Ostream&, const entry&);
62 /*---------------------------------------------------------------------------*\
63                            Class entry Declaration
64 \*---------------------------------------------------------------------------*/
66 class entry
68     public IDLList<entry>::link
70     // Private data
72         //- Keyword of entry
73         word keyword_;
76     // Private Member Functions
78         //- Get the next valid keyword otherwise return false
79         static bool getKeyword(word& keyword, Istream& is);
82 public:
84     // Constructors
86         //- Construct from keyword
87         entry(const word& keyword);
89         //- Construct as copy
90         entry(const entry&);
92         //- Construct on freestore as copy with reference to the
93         //  dictionary the copy belongs to
94         virtual Foam::autoPtr<entry> clone
95         (
96             const dictionary& parentDict
97         ) const = 0;
99         //- Construct on freestore as copy
100         //  Note: the parent directory is set to dictionary::null
101         virtual Foam::autoPtr<entry> clone() const;
103         //- Construct from Istream and insert into dictionary
104         static bool New(dictionary& parentDict, Istream& is);
106         //- Construct on freestore from Istream and return
107         static Foam::autoPtr<entry> New(Istream& is);
110     // Destructor
112         virtual ~entry()
113         {}
116     // Member functions
118         //- Return keyword
119         const word& keyword() const
120         {
121             return keyword_;
122         }
124         //- Return non-const access to keyword
125         word& keyword()
126         {
127             return keyword_;
128         }
130         //- Return the dictionary name
131         virtual const fileName& name() const = 0;
133         //- Return the dictionary name
134         virtual fileName& name() = 0;
136         //- Return line number of first token in dictionary
137         virtual label startLineNumber() const = 0;
139         //- Return line number of last token in dictionary
140         virtual label endLineNumber() const = 0;
142         //- Return true if this entry is a stream
143         virtual bool isStream() const
144         {
145             return false;
146         }
148         //- Return token stream if this entry is a primitive entry
149         virtual ITstream& stream() const = 0;
151         //- Return true if this entry is a dictionary
152         virtual bool isDict() const
153         {
154             return false;
155         }
157         //- Return dictionary if this entry is a dictionary
158         virtual const dictionary& dict() const = 0;
160         //- Return non-const access to dictionary if this entry is a dictionary
161         virtual dictionary& dict() = 0;
163         //- Write
164         virtual void write(Ostream&) const = 0;
167     // Member operators
169         void operator=(const entry&);
171         bool operator==(const entry&) const;
172         bool operator!=(const entry&) const;
175     // Ostream operator
177         friend Ostream& operator<<(Ostream&, const entry&);
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace Foam
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 #endif
189 // ************************************************************************* //