OpendTect-6_4  6.4
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Member Functions | List of all members
od_stream Class Reference

OD base class for stream read/write. More...

Inheritance diagram for od_stream:
[legend]

Public Types

enum  Ref { Abs, Rel, End }
 
typedef od_stream_Count Count
 
typedef od_stream_Pos Pos
 

Public Member Functions

virtual ~od_stream ()
 
bool isOK () const
 eof is not OK More...
 
bool isBad () const
 eof is not Bad More...
 
uiString errMsg () const
 see also below. More...
 
bool forRead () const
 
bool forWrite () const
 
Pos position () const
 
void setPosition (Pos, Ref r=Abs)
 
Pos endPosition () const
 
const char * fileName () const
 
void setFileName (const char *)
 
StreamDatastreamData ()
 
const StreamDatastreamData () const
 
void setNoClose (bool yn=true)
 
void releaseStream (StreamData &)
 
void close ()
 
void addErrMsgTo (BufferString &) const
 
void addErrMsgTo (uiString &) const
 

Static Public Member Functions

static od_streamcreate (const char *, bool forread, BufferString &errmsg)
 returns null on failure, never a bad stream More...
 
static od_streamcreate (const char *, bool forread, uiString &errmsg)
 returns null on failure, never a bad stream More...
 
static const char * sStdIO ()
 pass this as filename to get cin or cout More...
 
static const char * sStdErr ()
 pass this as filename to get cerr More...
 

Protected Member Functions

 od_stream ()
 
 od_stream (const char *, bool, bool editmode=false)
 
 od_stream (const FilePath &, bool, bool editmode=false)
 
 od_stream (std::ostream *)
 
 od_stream (std::ostream &)
 
 od_stream (std::istream *)
 
 od_stream (std::istream &)
 
 od_stream (const od_stream &)
 
od_streamoperator= (const od_stream &)
 

Protected Attributes

StreamDatasd_
 
bool mine_
 
bool noclose_
 
uiString errmsg_
 

Static Private Member Functions

static uiString tr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 
static uiString legacyTr (const char *text, const char *disambiguation=0, int pluralnr=-1)
 

Detailed Description

OD base class for stream read/write.

If the stream is owner of the std stream, then it will close it automatically when it goes out of scope (or is deleted). That means: except when you construct it with a std::[io]stream& . With that construction the od_stream is merely an adaptor. In all cases, the close() function is called automatically on destruction, but you can do it 'earlier' if you want.

As a result, copying a stream will transfer the stream to the copy, if the od_stream is owner. So unlike StreamData, you will then not have 2 od_streams pointing to the same std stream. In this way you can for example return an od_stream from a function.

Note the usage of the stream checking functions. There are only two left:

The difference is with end-of-file when reading. eof will not give you isBad(), but it will make the stream !isOK(). There is no difference for write.

Therefore, rule of thumb is: use isOK() for loop control, isBad() as a return value. If you know that the file should contain more data than the last read, then isOK() will be your choice anyway.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
Abs 
Rel 
End 

Constructor & Destructor Documentation

virtual od_stream::~od_stream ( )
virtual
od_stream::od_stream ( )
protected
od_stream::od_stream ( const char *  ,
bool  ,
bool  editmode = false 
)
protected
od_stream::od_stream ( const FilePath ,
bool  ,
bool  editmode = false 
)
protected
od_stream::od_stream ( std::ostream *  )
protected
od_stream::od_stream ( std::ostream &  )
protected
od_stream::od_stream ( std::istream *  )
protected
od_stream::od_stream ( std::istream &  )
protected
od_stream::od_stream ( const od_stream )
protected

Member Function Documentation

void od_stream::addErrMsgTo ( BufferString ) const
void od_stream::addErrMsgTo ( uiString ) const
void od_stream::close ( )
static od_stream* od_stream::create ( const char *  ,
bool  forread,
BufferString errmsg 
)
static

returns null on failure, never a bad stream

static od_stream* od_stream::create ( const char *  ,
bool  forread,
uiString errmsg 
)
static

returns null on failure, never a bad stream

Pos od_stream::endPosition ( ) const
uiString od_stream::errMsg ( ) const

see also below.

const char* od_stream::fileName ( ) const
bool od_stream::forRead ( ) const
bool od_stream::forWrite ( ) const
bool od_stream::isBad ( ) const

eof is not Bad

bool od_stream::isOK ( ) const

eof is not OK

static uiString od_stream::legacyTr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate
od_stream& od_stream::operator= ( const od_stream )
protected
Pos od_stream::position ( ) const
void od_stream::releaseStream ( StreamData )
void od_stream::setFileName ( const char *  )
void od_stream::setNoClose ( bool  yn = true)
inline
void od_stream::setPosition ( Pos  ,
Ref  r = Abs 
)
static const char* od_stream::sStdErr ( )
static

pass this as filename to get cerr

static const char* od_stream::sStdIO ( )
static

pass this as filename to get cin or cout

StreamData& od_stream::streamData ( )
inline
const StreamData& od_stream::streamData ( ) const
inline
static uiString od_stream::tr ( const char *  text,
const char *  disambiguation = 0,
int  pluralnr = -1 
)
inlinestaticprivate

Member Data Documentation

uiString od_stream::errmsg_
mutableprotected
bool od_stream::mine_
protected
bool od_stream::noclose_
protected
StreamData& od_stream::sd_
protected

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019