# PhasicFlow: src/phasicFlow/streams/iStream/iOstream.hpp Source File

iOstream.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __iOstream_hpp__
#define __iOstream_hpp__
// based on OpenFOAM stream, with some modifications/simplifications
// to be tailored to our needs
#include "IOstream.hpp"
const inline char* defaultColor = "\033[0m";
const inline char* blackColor = "\033[30m";
const inline char* redColor = "\033[31m";
const inline char* greenColor = "\033[32m";
const inline char* yellowColor = "\033[33m";
const inline char* blueColor = "\033[34m";
const inline char* magentaColor = "\033[35m";
const inline char* cyanColor = "\033[36m";
const inline char* whiteColor = "\033[37m";
const inline char* boldChar = "\033[1m";
namespace pFlow
{
// Forward Declarations
class token;
class iOstream
:
public IOstream
{
protected:
// Protected Data
//- Indentation of the entry from the start of the keyword
static constexpr const unsigned short entryIndentation_ = 16;
//- Number of spaces per indent level
unsigned short indentSize_ = 4;
//- Current indent level
unsigned short indentLevel_ = 0;
public:
// Constructor
explicit iOstream()
{}
//- Copy construct
iOstream(const iOstream&) = default;
//- Destructor
virtual ~iOstream() = default;
// Write Functions
//- Write token to stream or otherwise handle it.
// \return false if the token type was not handled by this method
virtual bool write(const token& tok) = 0;
//- Write character
virtual iOstream& write(const char c) = 0;
//- Write character string
virtual iOstream& write(const char* str) = 0;
//- Write word
virtual iOstream& write(const word& str) = 0;
//- Write std::string surrounded by quotes.
// Optional write without quotes.
virtual iOstream& writeQuoted
(
const word& str,
const bool quoted=true
) = 0;
//- Write int64
virtual iOstream& write(const int64 val) = 0;
//- Write int32
virtual iOstream& write(const int32 val) = 0;
//- Write label
virtual iOstream& write(const label val) = 0;
//- Write uint32
virtual iOstream& write(const uint32 val) = 0;
//- Write uint16
virtual iOstream& write(const uint16 val) = 0;
//- Write float
virtual iOstream& write(const float val) = 0;
//- Write double
virtual iOstream& write(const double val) = 0;
//- Add indentation characters
virtual void indent() = 0;
//- Return indent level
unsigned short indentSize() const
{
return indentSize_;
}
//- Access to indent size
unsigned short& indentSize()
{
return indentSize_;
}
//- Return indent level
unsigned short indentLevel() const
{
return indentLevel_;
}
//- Access to indent level
unsigned short& indentLevel()
{
return indentLevel_;
}
//- Increment the indent level
void incrIndent()
{
++indentLevel_;
}
//- Decrement the indent level
void decrIndent();
//- Write begin block group with a name
// Increments indentation, adds newline.
virtual iOstream& beginBlock(const word& kw);
//- Write begin block group without a name
// Increments indentation, adds newline.
virtual iOstream& beginBlock();
//- Write end block group
// Decrements indentation, adds newline.
virtual iOstream& endBlock();
//- Write begin list "("
virtual iOstream& beginList();
//- Write begin list with keyword "kw ("
virtual iOstream& beginList(const word& kw);
//- Write end list ")"
virtual iOstream& endList();
//- Write begin list "["
virtual iOstream& beginSquare();
//- Write begin list with keyword "kw ["
virtual iOstream& beginSquare(const word& kw);
//- Write end list "]"
virtual iOstream& endSquare();
//- Write end entry (';') followed by newline.
virtual iOstream& endEntry();
//- Write a newLine to stream
virtual iOstream& newLine();
//- Write space to stream
virtual iOstream& space(int32 n=1);
//- Write the keyword followed by an appropriate indentation
virtual iOstream& writeWordKeyword(const word& kw);
//- Write a keyword/value entry.
template<class T>
iOstream& writeWordEntry(const word& key, const T& value)
{
writeWordKeyword(key) << value;
return endEntry();
}
//- Flush stream
virtual void flush() = 0;
//- Add newline and flush stream
virtual void endl() = 0;
//- Get padding character
virtual char fill() const = 0;
//- Set padding character for formatted field up to field width
virtual char fill(const char fillch) = 0;
//- Get width of output field
virtual int width() const = 0;
//- Set width of output field (and return old width)
virtual int width(const int w) = 0;
//- Get precision of output field
virtual int precision() const = 0;
//- Set precision of output field (and return old precision)
virtual int precision(const int p) = 0;
// Member Operators
//- Return a non-const reference to const iOstream
// Needed for write functions where the stream argument is temporary:
// e.g. thing thisThing(OFstream("thingFileName")());
iOstream& operator()() const
{
return const_cast< iOstream&>(*this);
}
};
//- An iOstream manipulator
typedef iOstream& (*iOstreamManip)(iOstream&);
//- operator<< handling for manipulators without arguments
inline iOstream& operator<<(iOstream& os, iOstreamManip f)
{
return f(os);
}
//- operator<< handling for manipulators without arguments
inline iOstream& operator<<(iOstream& os, IOstreamManip f)
{
f(os);
return os;
}
//- Indent stream
inline iOstream& indent(iOstream& os)
{
os.indent();
return os;
}
//- Increment the indent level
inline iOstream& incrIndent(iOstream& os)
{
os.incrIndent();
return os;
}
//- Decrement the indent level
inline iOstream& decrIndent(iOstream& os)
{
os.decrIndent();
return os;
}
//- Flush stream
inline iOstream& flush(iOstream& os)
{
os.flush();
return os;
}
//- Add newline and flush stream
inline iOstream& endl(iOstream& os)
{
os.endl();
return os;
}
//- Write begin block group without a name
// Increments indentation, adds newline.
inline iOstream& beginBlock(iOstream& os)
{
os.beginBlock();
return os;
}
//- Write end block group
// Decrements indentation, adds newline.
inline iOstream& endBlock(iOstream& os)
{
os.endBlock();
return os;
}
//- Write end entry (';') followed by newline.
inline iOstream& endEntry(iOstream& os)
{
os.endEntry();
return os;
}
// overloading for basic types
inline iOstream& operator<<( iOstream& os, const char c)
{
return os.write(c);
}
inline iOstream& operator<<( iOstream& os, const char * buf)
{
return os.write(buf);
}
inline iOstream& operator<<( iOstream& os, const word& w)
{
return os.write(w);
}
inline iOstream& operator<<( iOstream& os, const int64& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const int32& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const int16& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const int8& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const label& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const uint32& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const uint16& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const float& val)
{
return os.write(val);
}
inline iOstream& operator<<( iOstream& os, const double& val)
{
return os.write(val);
}
// Useful aliases for tab and newline characters
constexpr char tab = '\t';
constexpr char nl = '\n';
} // pFlow
#endif
// ************************************************************************* //
pFlow::iOstream::~iOstream
virtual ~iOstream()=default
blackColor
const char * blackColor
Definition: iOstream.hpp:32
pFlow::iOstream::beginBlock
virtual iOstream & beginBlock(const word &kw)
Definition: iOstream.cpp:70
pFlow::iOstream::write
virtual bool write(const token &tok)=0
pFlow::endBlock
iOstream & endBlock(iOstream &os)
Definition: iOstream.hpp:330
pFlow::token
Definition: token.hpp:42
pFlow::iOstream::precision
virtual int precision() const =0
pFlow::tab
constexpr char tab
Definition: iOstream.hpp:408
pFlow::iOstream::endl
virtual void endl()=0
pFlow::iOstream::endBlock
virtual iOstream & endBlock()
Definition: iOstream.cpp:88
pFlow::iOstream::newLine
virtual iOstream & newLine()
Definition: iOstream.cpp:105
pFlow::endEntry
iOstream & endEntry(iOstream &os)
Definition: iOstream.hpp:338
blueColor
const char * blueColor
Definition: iOstream.hpp:36
pFlow::iOstream::indent
virtual void indent()=0
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::iOstream::width
virtual int width() const =0
pFlow::decrIndent
iOstream & decrIndent(iOstream &os)
Definition: iOstream.hpp:296
pFlow::iOstream::indentSize
unsigned short & indentSize()
Definition: iOstream.hpp:143
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::iOstream::indentLevel
unsigned short indentLevel() const
Definition: iOstream.hpp:149
pFlow::flush
iOstream & flush(iOstream &os)
Definition: iOstream.hpp:304
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
boldChar
const char * boldChar
Definition: iOstream.hpp:41
pFlow::iOstream::operator()
iOstream & operator()() const
Definition: iOstream.hpp:255
pFlow::indent
iOstream & indent(iOstream &os)
Definition: iOstream.hpp:282
pFlow::iOstream::indentSize
unsigned short indentSize() const
Definition: iOstream.hpp:137
pFlow
Definition: demComponent.hpp:28
pFlow::IOstreamManip
IOstream &(* IOstreamManip)(IOstream &)
Definition: IOstream.hpp:273
pFlow::iOstream::indentLevel
unsigned short & indentLevel()
Definition: iOstream.hpp:155
cyanColor
const char * cyanColor
Definition: iOstream.hpp:38
pFlow::iOstream::incrIndent
void incrIndent()
Definition: iOstream.hpp:161
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::int16
short int int16
Definition: builtinTypes.hpp:51
pFlow::uint16
unsigned short int uint16
Definition: builtinTypes.hpp:57
pFlow::iOstream::decrIndent
void decrIndent()
Definition: iOstream.cpp:27
pFlow::incrIndent
iOstream & incrIndent(iOstream &os)
Definition: iOstream.hpp:289
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
defaultColor
const char * defaultColor
Definition: iOstream.hpp:31
redColor
const char * redColor
Definition: iOstream.hpp:33
pFlow::iOstream::flush
virtual void flush()=0
pFlow::iOstream::beginSquare
virtual iOstream & beginSquare()
Definition: iOstream.cpp:153
pFlow::iOstream::endEntry
virtual iOstream & endEntry()
Definition: iOstream.cpp:97
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::iOstream::writeQuoted
virtual iOstream & writeQuoted(const word &str, const bool quoted=true)=0
whiteColor
const char * whiteColor
Definition: iOstream.hpp:39
pFlow::iOstream::endSquare
virtual iOstream & endSquare()
Definition: iOstream.cpp:172
IOstream.hpp
magentaColor
const char * magentaColor
Definition: iOstream.hpp:37
pFlow::iOstream::indentSize_
unsigned short indentSize_
Definition: iOstream.hpp:65
pFlow::iOstream::iOstream
iOstream()
Definition: iOstream.hpp:75
pFlow::iOstream::endList
virtual iOstream & endList()
Definition: iOstream.cpp:144
pFlow::beginBlock
iOstream & beginBlock(iOstream &os)
Definition: iOstream.hpp:321
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::iOstream::beginList
virtual iOstream & beginList()
Definition: iOstream.cpp:125
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
yellowColor
const char * yellowColor
Definition: iOstream.hpp:35
pFlow::iOstream::entryIndentation_
static constexpr const unsigned short entryIndentation_
Definition: iOstream.hpp:62
pFlow::iOstream::fill
virtual char fill() const =0
pFlow::iOstream::space
virtual iOstream & space(int32 n=1)
Definition: iOstream.cpp:112
pFlow::nl
constexpr char nl
Definition: iOstream.hpp:409
pFlow::IOstream
Definition: IOstream.hpp:45
pFlow::iOstream
Definition: iOstream.hpp:53
greenColor
const char * greenColor
Definition: iOstream.hpp:34
pFlow::iOstream::writeWordKeyword
virtual iOstream & writeWordKeyword(const word &kw)
Definition: iOstream.cpp:41
pFlow::iOstream::writeWordEntry
iOstream & writeWordEntry(const word &key, const T &value)
Definition: iOstream.hpp:217
pFlow::iOstream::beginBlock
virtual iOstream & beginBlock()
Definition: iOstream.cpp:79
pFlow::iOstreamManip
iOstream &(* iOstreamManip)(iOstream &)
Definition: iOstream.hpp:264
pFlow::iOstream::indentLevel_
unsigned short indentLevel_
Definition: iOstream.hpp:68