# PhasicFlow: src/phasicFlow/streams/TStream/iTstream.cpp Source File

iTstream.cpp
Go to the documentation of this file.
#include "iTstream.hpp"
#include "error.hpp"
#include "iOstream.hpp"
bool pFlow::iTstream::isLastToken()
{
return currentToken_ == tokenList_.end();
}
void pFlow::iTstream::setFirstToken()
{
currentToken_ = tokenList_.begin();
}
void pFlow::iTstream::validate()
{
for (auto it = tokenList_.begin(); it != tokenList_.end(); )
{
if (!validTokenForStream(*it))
{
it = tokenList_.erase(it);
}
else
{
++it;
}
}
}
pFlow::iTstream::iTstream
(
const word& streamName
)
:
iIstream(),
name_(streamName),
tokenList_(),
currentToken_(tokenList_.begin())
{
setOpened();
setGood();
rewind();
}
pFlow::iTstream::iTstream
(
const word& streamName,
const tokenList& tList
)
:
iIstream(),
name_(streamName),
tokenList_(tList),
currentToken_(tokenList_.begin())
{
setOpened();
setGood();
// check for invalid tokens in the tList
validate();
rewind();
}
pFlow::iTstream::iTstream
(
const word& streamName,
tokenList&& tList
)
:
iIstream(),
name_(streamName),
tokenList_(std::move(tList)),
currentToken_(tokenList_.begin())
{
setOpened();
setGood();
// check for invalid tokens in the tList
validate();
rewind();
}
// copy assignment from tokenList
void pFlow::iTstream::operator=(const tokenList& tList)
{
tokenList_ = tList;
validate();
rewind();
}
// move assignment from tokenList
void pFlow::iTstream::operator=(tokenList&& tList)
{
tokenList_ = std::move(tList);
validate();
rewind();
}
const pFlow::word& pFlow::iTstream::name() const
{
return name_;
}
pFlow::word& pFlow::iTstream::name()
{
return name_;
}
pFlow::iIstream& pFlow::iTstream::read
(
token& t
)
{
// Return the put back token if it exists
if (iIstream::getBack(t))
{
lineNumber_ = t.lineNumber();
setGood();
return *this;
}
if ( !isLastToken() )
{
//t = operator[](tokenIndex_++);
lineNumber_ = t.lineNumber();
t = *currentToken_;
setGood();
currentToken_++;
if( isLastToken() )
{
setEof();
}
}
else
{
if (eof())
{
fatalErrorInFunction <<
"attempt to read beyond EOF \n";
fatalExit;
setBad();
}
else
{
setEof();
}
t.reset();
if (tokenList_.size())
{
t.lineNumber() = tokenList_.back().lineNumber();
}
else
{
t.lineNumber() = lineNumber();
}
}
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
char& c
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(c);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
word& str
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(str);
return *this;
}
pFlow::iIstream& pFlow::iTstream::readString
(
word& str
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(str);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
int64& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
int32& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
int16& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
int8& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
label& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
uint32& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
uint16& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
float& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
pFlow::iIstream& pFlow::iTstream::read
(
double& val
)
{
notImplementedFunction;
fatalExit;
CONSUME_PARAM(val);
return *this;
}
void pFlow::iTstream::rewind()
{
iIstream::resetPutBack();
setFirstToken();
setGood();
}
void pFlow::iTstream::reset()
{
iIstream::resetPutBack();
tokenList_.clear();
setFirstToken();
setGood();
}
const pFlow::tokenList& pFlow::iTstream::tokens()const
{
return tokenList_;
}
size_t pFlow::iTstream::size()const
{
return tokenList_.size();
}
size_t pFlow::iTstream::numTokens()const
{
return tokenList_.size();
}
void pFlow::iTstream::appendTokens
(
const tokenList & tList
)
{
for(auto& t:tList)
{
if(validTokenForStream(t)) tokenList_.push_back(t);
}
rewind();
}
void pFlow::iTstream::appendToken
(
const token& t
)
{
if(validTokenForStream(t)) tokenList_.push_back(t);
rewind();
}
// ************************************************************************* //
pFlow::iTstream::tokens
const tokenList & tokens() const
Definition: iTstream.cpp:323
notImplementedFunction
#define notImplementedFunction
Definition: error.hpp:47
pFlow::List< token >
pFlow::iTstream::isLastToken
bool isLastToken()
Definition: iTstream.cpp:6
iTstream.hpp
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::token
Definition: token.hpp:42
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::iTstream::reset
virtual void reset()
Definition: iTstream.cpp:315
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iTstream::size
size_t size() const
Definition: iTstream.cpp:328
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::iTstream::rewind
virtual void rewind()
Definition: iTstream.cpp:307
pFlow::iTstream::setFirstToken
void setFirstToken()
Definition: iTstream.cpp:11
pFlow::iTstream::operator=
iTstream & operator=(const iTstream &)=default
pFlow::validTokenForStream
bool validTokenForStream(const token tok)
pFlow::token::reset
void reset()
Definition: tokenI.hpp:245
pFlow::iTstream::appendTokens
void appendTokens(const tokenList &tList)
Definition: iTstream.cpp:339
pFlow::int16
short int int16
Definition: builtinTypes.hpp:51
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::iIstream::getBack
bool getBack(token &tok)
Definition: iIstream.cpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::iTstream::tokenList_
tokenList tokenList_
Definition: iTstream.hpp:31
pFlow::iTstream::iTstream
iTstream(const word &streamName)
Definition: iTstream.cpp:32
pFlow::iTstream::name
virtual const word & name() const
Definition: iTstream.cpp:99
pFlow::iTstream::read
virtual iIstream & read(token &t) override
Definition: iTstream.cpp:111
pFlow::iTstream::validate
void validate()
Definition: iTstream.cpp:16
pFlow::iIstream::resetPutBack
void resetPutBack()
Definition: iIstream.hpp:80
pFlow::iTstream::appendToken
void appendToken(const token &t)
Definition: iTstream.cpp:352
pFlow::iTstream::numTokens
size_t numTokens() const
Definition: iTstream.cpp:333
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::iTstream::currentToken_
tokenList::iterator currentToken_
Definition: iTstream.hpp:34
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::iTstream::readString
virtual iIstream & readString(word &str) override
Definition: iTstream.cpp:192
iOstream.hpp
pFlow::token::lineNumber
int32 lineNumber() const
Definition: tokenI.hpp:360
error.hpp