dataEntry.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 // based on OpenFOAM dictionary, with some modifications/simplifications
21 // to be tailored to our needs
22 
23 
24 #ifndef __dataEntry_hpp__
25 #define __dataEntry_hpp__
26 
27 
28 #include "iEntry.hpp"
29 #include "iTstream.hpp"
30 #include "oTstream.hpp"
31 
32 
33 
34 namespace pFlow
35 {
36 
37 class dictionary;
38 
39 
40 class dataEntry
41 :
42  public iEntry
43 {
44 
45 protected:
46 
48 
49  // - ref to parrent dictionary
51 
52  // - list the tokens as input token stream
54 
55 
57 
58  // - read dataEntry from stream
59  bool readDataEntry(iIstream& is);
60 
61  // - write dataEntry to stream
62  bool writeDataEntry(iOstream& os) const;
63 
64 public:
65 
67 
69 
70  // - construct null dataEntry
71  dataEntry();
72 
73  // - construct from keyword and parDict, empty dataEntry
74  dataEntry(const word& keyword, const dictionary& parDict);
75 
76  // - construct from keyword, parDict and input token stream
77  dataEntry(const word& keyWord, const dictionary& parDict, const iTstream& is);
78 
79  //- construct from keyword, parDict and input stream
80  dataEntry(const word& keyWord, const dictionary& parDict, iIstream& is);
81 
82  // - construct from keyword, parDict and a single token
83  dataEntry(const word& keyword, const dictionary& parDict, const token& tok);
84 
85  // - construct from keyword, parDict, and data of type T
86  template<typename T>
87  dataEntry(const word& keyword, const dictionary& parDict, const T& v);
88 
89  // - copy construct with new keyword and parDict
90  dataEntry(const word& keyword, const dictionary& parDict, const dataEntry& entry );
91 
92  // - copy construct
93  dataEntry(const dataEntry& src )= default;
94 
95 
97 
98  // - global name of entry, separated with dots
99  virtual word globalName()const;
100 
101 
102  // - access to token stream
103  virtual iTstream& stream();
104 
105  // - not permited to be called
106  virtual dictionary* dictPtr();
107 
108  // - not permited to be called
109  virtual const dictionary* dictPtr() const;
110 
111  // - should returen false;
112  virtual bool isDictionary()const;
113 
114  // - const ref to parrent dictionary
115  virtual const dictionary& parrentDict() const;
116 
117  // - not permited to be called
118  virtual dictionary& dict();
119 
120  // - not permited to be called
121  virtual const dictionary& dict() const;
122 
123  // clone the object
124  virtual iEntry* clonePtr() const;
125 
126  virtual uniquePtr<iEntry> clone() const;
127 
128  // clone the object and change its ownership to parDict
129  virtual iEntry* clonePtr(const dictionary& parDict) const;
130 
131  virtual uniquePtr<iEntry> clone(const dictionary& parDict)const;
132 
134 
135  // - read from stream
136  virtual bool read(iIstream& is);
137 
138  // - write to stream
139  virtual bool write(iOstream& os) const;
140 
141 };
142 
143 
144 
145 
146 template<typename T>
147 dataEntry::dataEntry(const word& keyword, const dictionary& parDict, const T& v)
148 :
149  dataEntry(keyword, parDict)
150 {
151 
152  oTstream os("oTStream for " + globalName());
153 
154  os<< v << endStatementToken();
155 
156  tokenStream_ = std::move(os.tokens());
157 }
158 
159 
160 } // pFlow
161 
162 
163 #endif //__dataEntry_hpp__
pFlow::oTstream
Definition: oTstream.hpp:23
pFlow::dataEntry::readDataEntry
bool readDataEntry(iIstream &is)
Definition: dataEntry.cpp:35
iTstream.hpp
pFlow::token
Definition: token.hpp:42
pFlow::dataEntry::stream
virtual iTstream & stream()
Definition: dataEntry.cpp:261
pFlow::endStatementToken
token endStatementToken()
Definition: token.hpp:504
pFlow::dataEntry::parrentDict
virtual const dictionary & parrentDict() const
Definition: dataEntry.cpp:297
pFlow::dataEntry::globalName
virtual word globalName() const
Definition: dataEntry.cpp:291
pFlow::dataEntry::writeDataEntry
bool writeDataEntry(iOstream &os) const
Definition: dataEntry.cpp:98
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
oTstream.hpp
pFlow::iEntry::keyword
virtual const word & keyword() const
Definition: iEntry.hpp:84
pFlow::oTstream::tokens
const tokenList & tokens() const
Definition: oTstream.cpp:32
pFlow
Definition: demComponent.hpp:28
pFlow::dataEntry::parDict_
const dictionary & parDict_
Definition: dataEntry.hpp:50
pFlow::dataEntry::dataEntry
dataEntry()
Definition: dataEntry.cpp:159
pFlow::dataEntry
Definition: dataEntry.hpp:40
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::dataEntry::tokenStream_
iTstream tokenStream_
Definition: dataEntry.hpp:53
pFlow::dataEntry::dictPtr
virtual dictionary * dictPtr()
Definition: dataEntry.cpp:269
iEntry.hpp
pFlow::dataEntry::nullDataEntry
static dataEntry nullDataEntry
Definition: dataEntry.hpp:66
pFlow::dataEntry::isDictionary
virtual bool isDictionary() const
Definition: dataEntry.cpp:286
pFlow::iTstream
Definition: iTstream.hpp:21
pFlow::dataEntry::read
virtual bool read(iIstream &is)
Definition: dataEntry.cpp:345
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::dataEntry::clone
virtual uniquePtr< iEntry > clone() const
Definition: dataEntry.cpp:321
pFlow::iEntry
Definition: iEntry.hpp:38
pFlow::dataEntry::clonePtr
virtual iEntry * clonePtr() const
Definition: dataEntry.cpp:327
pFlow::dataEntry::dict
virtual dictionary & dict()
Definition: dataEntry.cpp:303
pFlow::dataEntry::write
virtual bool write(iOstream &os) const
Definition: dataEntry.cpp:366
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38