OpendTect  6.6
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | 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

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

Public Member Functions

virtual ~od_stream ()
 
void addErrMsgTo (BufferString &) const
 
void addErrMsgTo (uiRetVal &) const
 
void addErrMsgTo (uiString &) const
 
void close ()
 
uiString errMsg () const
 see also below. More...
 
const char * fileName () const
 
bool forRead () const
 
bool forWrite () const
 
bool isBad () const
 eof is not Bad More...
 
bool isLocal () const
 
bool isOK () const
 eof is not OK More...
 
Pos position () const
 
void setFileName (const char *)
 
void setNoClose (bool yn=true)
 
void setPosition (Pos, Ref r=Abs)
 
StreamDatastreamData ()
 
const StreamDatastreamData () 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 * sStdErr ()
 pass this as filename to get cerr More...
 
static const char * sStdIO ()
 pass this as filename to get cin or cout More...
 

Protected Member Functions

 od_stream ()
 
 od_stream (const char *, bool, bool editmode=false)
 
 od_stream (const FilePath &, bool, bool editmode=false)
 
 od_stream (const OS::MachineCommand &, const char *workdir, bool editmode=false)
 
 od_stream (std::istream &)
 
 od_stream (std::istream *)
 
 od_stream (std::ostream &)
 
 od_stream (std::ostream *)
 
BufferString noStdStreamPErrMsg () const
 
od_streamoperator= (const od_stream &)=delete
 

Protected Attributes

uiString errmsg_
 
bool mine_ = true
 
bool noclose_ = false
 
StreamData sd_
 

Private Member Functions

bool setFromCommand (const OS::MachineCommand &, const char *workdir, bool editmode)
 

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

◆ Count

typedef od_stream_Count od_stream::Count

◆ Pos

typedef od_stream_Pos od_stream::Pos

Member Enumeration Documentation

◆ Ref

Enumerator
Abs 
Rel 
End 

Constructor & Destructor Documentation

◆ ~od_stream()

virtual od_stream::~od_stream ( )
virtual

◆ od_stream() [1/8]

od_stream::od_stream ( )
protected

◆ od_stream() [2/8]

od_stream::od_stream ( const char *  ,
bool  ,
bool  editmode = false 
)
protected

◆ od_stream() [3/8]

od_stream::od_stream ( const FilePath ,
bool  ,
bool  editmode = false 
)
protected

◆ od_stream() [4/8]

od_stream::od_stream ( const OS::MachineCommand ,
const char *  workdir,
bool  editmode = false 
)
protected

◆ od_stream() [5/8]

od_stream::od_stream ( std::ostream *  )
protected

◆ od_stream() [6/8]

od_stream::od_stream ( std::ostream &  )
protected

◆ od_stream() [7/8]

od_stream::od_stream ( std::istream *  )
protected

◆ od_stream() [8/8]

od_stream::od_stream ( std::istream &  )
protected

Member Function Documentation

◆ addErrMsgTo() [1/3]

void od_stream::addErrMsgTo ( BufferString ) const

◆ addErrMsgTo() [2/3]

void od_stream::addErrMsgTo ( uiRetVal ) const

◆ addErrMsgTo() [3/3]

void od_stream::addErrMsgTo ( uiString ) const

◆ close()

void od_stream::close ( )

◆ create() [1/2]

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

returns null on failure, never a bad stream

◆ create() [2/2]

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

returns null on failure, never a bad stream

◆ errMsg()

uiString od_stream::errMsg ( ) const

see also below.

◆ fileName()

const char* od_stream::fileName ( ) const

◆ forRead()

bool od_stream::forRead ( ) const

◆ forWrite()

bool od_stream::forWrite ( ) const

◆ isBad()

bool od_stream::isBad ( ) const

eof is not Bad

◆ isLocal()

bool od_stream::isLocal ( ) const

◆ isOK()

bool od_stream::isOK ( ) const

eof is not OK

◆ noStdStreamPErrMsg()

BufferString od_stream::noStdStreamPErrMsg ( ) const
protected

◆ operator=()

od_stream& od_stream::operator= ( const od_stream )
protecteddelete

◆ position()

Pos od_stream::position ( ) const

◆ setFileName()

void od_stream::setFileName ( const char *  )

◆ setFromCommand()

bool od_stream::setFromCommand ( const OS::MachineCommand ,
const char *  workdir,
bool  editmode 
)
private

◆ setNoClose()

void od_stream::setNoClose ( bool  yn = true)
inline

◆ setPosition()

void od_stream::setPosition ( Pos  ,
Ref  r = Abs 
)

◆ sStdErr()

static const char* od_stream::sStdErr ( )
static

pass this as filename to get cerr

◆ sStdIO()

static const char* od_stream::sStdIO ( )
static

pass this as filename to get cin or cout

◆ streamData() [1/2]

StreamData& od_stream::streamData ( )
inline

◆ streamData() [2/2]

const StreamData& od_stream::streamData ( ) const
inline

Member Data Documentation

◆ errmsg_

uiString od_stream::errmsg_
mutableprotected

◆ mine_

bool od_stream::mine_ = true
protected

◆ noclose_

bool od_stream::noclose_ = false
protected

◆ sd_

StreamData od_stream::sd_
protected

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