FreeFOAM The Cross-Platform CFD Toolkit
primitiveEntry.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "primitiveEntry.H"
27 #include <OpenFOAM/dictionary.H>
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 :
33  entry(key),
34  ITstream(tokens)
35 {
36  name() += "::" + keyword();
37 }
38 
39 
41 :
42  entry(keyword),
43  ITstream(keyword, tokenList(1, t))
44 {}
45 
46 
48 (
49  const keyType& keyword,
50  const tokenList& tokens
51 )
52 :
53  entry(keyword),
54  ITstream(keyword, tokens)
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 
61 {
62  if (size())
63  {
64  return operator[](0).lineNumber();
65  }
66  else
67  {
68  return -1;
69  }
70 }
71 
73 {
74  if (size())
75  {
76  return operator[](size()-1).lineNumber();
77  }
78  else
79  {
80  return -1;
81  }
82 }
83 
84 
86 {
87  ITstream& dataStream = const_cast<primitiveEntry&>(*this);
88  dataStream.rewind();
89  return dataStream;
90 }
91 
92 
94 {
95  FatalErrorIn("const dictionary& primitiveEntry::dict() const")
96  << "Attempt to return primitive entry " << info()
97  << " as a sub-dictionary"
98  << abort(FatalError);
99 
100  return dictionary::null;
101 }
102 
103 
105 {
106  FatalErrorIn("const dictionary& primitiveEntry::dict()")
107  << "Attempt to return primitive entry " << info()
108  << " as a sub-dictionary"
109  << abort(FatalError);
110 
111  return const_cast<dictionary&>(dictionary::null);
112 }
113 
114 
116 (
117  const tokenList& varTokens,
118  const label posI
119 )
120 {
121  tokenList& tokens = *this;
122 
123  if (varTokens.empty())
124  {
125  label end = tokens.size() - 1;
126 
127  for (label j=posI; j<end; j++)
128  {
129  tokens[j] = tokens[j+1];
130  }
131 
132  tokens.setSize(tokens.size() - 1);
133  }
134  else if (varTokens.size() > 1)
135  {
136  tokens.setSize(tokens.size() + varTokens.size() - 1);
137 
138  label end = tokens.size() - 1;
139  label offset = varTokens.size() - 1;
140 
141  for (label j=end; j>posI; j--)
142  {
143  tokens[j] = tokens[j-offset];
144  }
145  }
146 
147  forAll(varTokens, j)
148  {
149  tokens[posI + j] = varTokens[j];
150  }
151 }
152 
153 
154 // ************************ vim: set sw=4 sts=4 et: ************************ //