Go to the documentation of this file.
54 "iIstream is not good for reading tokens .... \n";
61 if( nextTok == token::END_BLOCK)
64 "Not expecting a } for the start of a dictionray \n";
68 bool hasBlockToken =
true;
71 if(nextTok != token::BEGIN_BLOCK)
73 hasBlockToken =
false;
79 while ( !is.
eof() && iEntry::createEntry(*
this, is, hasBlockToken) )
94 for(
const auto& e:orderedEntries_)
110 if(
auto [ptr, exist] = entries_.find(keyword); exist)
125 if(
auto [ptr, exist] = entries_.find(keyword); exist)
127 return const_cast<iEntry*
> (ptr);
141 parDict_(dictionary::nullDict),
154 parDict_(dictionary::nullDict),
169 parDict_(dictionary::nullDict),
184 parDict_(dictionary::nullDict),
189 if(!read(dictStream))
192 "error in reading dictionary from file "<< file <<
endl;
229 if( !readDictionary(is) )
232 "error in reading dictionary " << name_ <<
endl;
256 auto ptr = entry->
clone(*
this);
257 auto key = entry->name();
259 if( !addPtr(key, ptr) )
262 " error in cloning dicrionary / dataEntry " << entry->globalName() <<
endl;
279 parDict_(dictionary::nullDict),
288 auto ptr = entry->
clone(*
this);
289 auto key = entry->name();
291 if( !addPtr(key, ptr) )
294 " error in cloning dicrionary / dataEntry " << entry->globalName() <<
endl;
315 if( &rhs ==
this)
return *
this;
319 for(
auto& entry: rhs.orderedEntries_)
324 auto ptr = entry->clone(*
this);
325 auto key = entry->name();
327 if( !addPtr(key, ptr) )
330 " error in cloning dicrionary / dataEntry " << entry->globalName() <<
endl;
393 if(entry ==
nullptr)
return false;
395 iEntry* oldEntryPtr =
nullptr;
396 iEntry* newEntryPtr = entry.get();
399 if(
auto [ptr, exist] = entries_.find(keyword); exist )
404 "keyword " << keyword <<
" already exists in the dicrionary " <<
405 this->globalName() <<
". The old entry will be replaced by the new one. \n";
413 if( entries_.insertReplace(keyword, entry) )
419 auto oIter = orderedEntries_.find(oldEntryPtr);
420 *oIter = newEntryPtr;
424 orderedEntries_.push_back(newEntryPtr);
441 return addPtr(keyword, ptr);
451 return addPtr(keyword, ptr);
461 return addPtr(keyword, ptr);
471 return addPtr(keyword, ptr);
481 return addPtr(keyword, ptr);
492 return addPtr(keyword, ptr);
502 return addPtr(keyword, ptr);
512 return addPtr(keyword, ptr);
522 return addPtr(keyword, ptr);
532 return addPtr(keyword, ptr);
537 orderedEntries_.clear();
546 if(
auto entry = findEntry(keyword); entry!=
nullptr && entry->isDictionary() )
553 "keyword " << keyword<<
" is not an sub-dictionary of " << this->globalName()<<
endl;
565 if(
auto entry = findEntry(keyword); entry!=
nullptr && entry->isDictionary() )
572 "keyword " << keyword<<
" is not an sub-dictionary of " << this->globalName()<<
endl;
585 if(
auto entry = findEntry(keyword); entry!=
nullptr && entry->isDictionary() )
592 "keyword " << keyword<<
" is not an sub-dictionary of " << this->globalName()<<
endl;
600 if(
auto entry = findEntry(keyword); entry && !entry->isDictionary() )
607 "keyword " << keyword<<
" is not a dataEntry of " << this->globalName()<<
endl;
615 if(
auto entry = findEntry(keyword); entry && !entry->isDictionary() )
622 "keyword " << keyword<<
" is not a dataEntry of " << this->globalName()<<
endl;
633 if(
auto entry = findEntry(keyword); entry && !entry->isDictionary() )
640 "keyword " << keyword<<
" is not a dataEntry of " << this->globalName()<<
endl;
651 if(
auto entry = findEntry(keyword); entry!=
nullptr && entry->isDictionary() )
665 return subDictOrCreate(keyword);
670 "Unable to create sub-dictionary "<< keyword <<
" in dictionary " << globalName() <<
endl;
679 return entries_.size();
685 for(
auto& e:entries_)
687 if( e.second && !e.second->isDictionary())
698 for(
auto& e:entries_)
700 if( e.second && e.second->isDictionary())
712 for(
auto oe:orderedEntries_)
714 if(oe) wl.push_back( oe->keyword() );
723 for(
auto oe:orderedEntries_)
725 if( oe && !oe->isDictionary())
727 wl.push_back(oe->keyword());
738 for(
auto& oe:orderedEntries_)
740 if( oe && oe->isDictionary())
742 wl.push_back(oe->keyword());
753 if(
auto ptr = findEntry(name); ptr)
755 return ptr->isDictionary();
765 if(
auto ptr = findEntry(name); ptr)
767 return !ptr->isDictionary();
775 if(!isFileDict() && !readKeyword(is, keyword_, tok))
778 "expected a valid keyword for dictionary but found " << tok <<
endl;
782 if( !readDictionary(is) )
785 "error in reading dictionary " << keyword_ <<
endl;
795 if(! writeDictionary(os, !isFileDict()) )
806 return makeUnique<dictionary>(*
this);
813 auto ptr = makeUnique<dictionary>(*
this);
814 return ptr.release();
822 return makeUnique<dictionary>(this->keyword(), parDict, *
this);
830 auto ptr = makeUnique<dictionary>(this->keyword(), parDict, *
this);
831 return ptr.release();
bool eof() const
Return true if end of input seen.
virtual iOstream & beginBlock(const word &kw)
Write begin block group with a name Increments indentation, adds newline.
List< iEntry * > orderedEntries_
entries in order of insertion
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
virtual uniquePtr< iEntry > clone() const =0
#define fatalExit
Fatal exit.
Token class based on OpenFOAM stream, with some modifications/simplifications to be tailored to our n...
bool read(iIstream &is) override
read from stream
virtual iOstream & endBlock()
Write end block group Decrements indentation, adds newline.
wordList allKeywords() const
return all keywords (non-nullptr) in this dictionary
#define warningInFunction
Report a warning.
iEntry * findEntry(const word &keyword)
find an entry based on keyword return nullptr if not found
virtual word globalName() const
global name of entry, separated with dots
virtual const word & name() const
Return the name of the stream.
dictionary & subDictOrCreate(const word &keyword)
search for a sub-dict with keyword create a new sub-dict if not found and return a ref to it fatalExi...
bool add(const word &keyword, const float &v)
add a float dataEntry
virtual const word & keyword() const
return keyword
virtual bool isDictionary() const
if this is a dictionary
iOstream & endl(iOstream &os)
Add newline and flush stream.
static dictionary nullDict
Input file stream for reading binary or ascii data from a file.
virtual iEntry * clonePtr() const
clone the object
bool containsDataEntry(const word &name) const
check if a data entry exist
wordList dictionaryKeywords() const
return a list of all dictionary (non-null) keywords
virtual dictionary * dictPtr()
pointer to this dictionary
Manages file pathes, manupulate and combines them.
bool containsDictionay(const word &name) const
check if a sub-dictionary exists
Data entry to be used in dictionries.
size_t numEntries() const
return number of entris in this dictionary
Interface class for any input stream
virtual uniquePtr< iEntry > clone() const
clone polymorphic object (here dictionary)
dataEntry * dataEntryPtr(const word &keyword)
pointer to a dataEntry fatalExit if not found/not a dataEntry
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
virtual bool isFileDict() const
if dictionary is file dictionary, return false
virtual dictionary & dict()
ref to this dictionary, if it is a dictionary
bool readDictionary(iIstream &is)
read dictionary from stream - without keyword
bool writeDictionary(iOstream &os, bool withBlock=true) const
write dictionary to stream - with keyword
void putBack(const token &tok)
Put back token Only a single put back is permitted.
size_t numDataEntries() const
return number of non-nullptr dataEntries
dataEntry & dataEntryRef(const word &keyword)
ref to a subdictioanry fatalExit if not found/not a dataEntry
bool write(iOstream &os) const override
write to stream
dictionary * subDictPtr(const word &keyword)
pointer to a subdictionary fatalExit if not found
virtual const word & name() const
Return the name of the stream.
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
bool good() const
Return true if next operation might succeed.
static dataEntry nullDataEntry
bool addPtr(const word &keyword, uniquePtr< iEntry > &etry, bool warning=true)
add a pointer entry (dictionary/dataEntry) replaces this entry with existing one and issue a warning
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
unsigned long long int uint64
Interface calss for data entry and dictionary
dictionary()
cunstructs a null dictionary
int32 lineNumber() const
Const access to the current stream line number.
word wordPath() const
Path in word type.
bool addDict(const word &keyword, const dictionary &dict)
add a dictionary with the specifiedd keyword, if it exists, replace it.
size_t numDictionaries() const
return number of non-nullptr dictionaries
virtual const dictionary & parrentDict() const
const ref to parrent dictionary
Interface class for any output stream.
wordList dataEntryKeywords() const
return a list of all dataEntries (non-nullptr) keywords
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...