Leonardus
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
SOF Class Reference

Semantic Object File. More...

#include <sof.h>

+ Inheritance diagram for SOF:
+ Collaboration diagram for SOF:

Classes

struct  SOFData
 Semantic Object File - data member class. More...
 

Public Member Functions

 SOF (const std::string &p_name, const std::string &p_mode)
 Ctor from a name.
 
 SOF (const SOF &p_other)
 Copy ctor.
 
 ~SOF () override
 Dtor.
 
 SOF (SOF &&)=delete
 
SOF & operator= (const SOF &)=delete
 
SOF & operator= (SOF &&)=delete
 
std::string getFName () const
 Returns the file name.
 
std::string getFMode () const
 Returns the file mode.
 
SOF * dup () const override
 Creates a new instance as copy following the red book definition.
 
std::string opequal () const override
 String representation of object for operators '=', 'cvs' and 'stack'.
 
std::string opequalequal () const override
 String representation for operators '==' and 'pstack'.
 
OTCode ot () const override
 Returns an OTCode.
 
std::string type () const override
 Returns a type name.
 
bool equal (const SO *p_other) const override
 Checks if this SO is equal to another SO.
 
bool isOpen () const
 Checks if the file is open.
 
bool readLeonLine (std::string &p_str)
 Our std::getline( istream, string ) version.
 
OpError open ()
 Opens the file.
 
OpError flush ()
 Flushes the file.
 
OpError close (int(*p_fclose)(FILE *)=fclose)
 Closes the file.
 
OpError readline (std::string &p_str, bool &p_eof)
 Reads a line of text from file.
 
OpError readstring (std::string &p_str, bool &p_eof)
 Reads text from file.
 
OpError writestring (const std::string &p_data)
 Writes to file.
 
OpError writestring (std::string_view p_data)
 Writes to file.
 
- Public Member Functions inherited from SO
 SO ()
 Ctor.
 
 SO (bool p_exec)
 Ctor.
 
 SO (const SO &p_other)
 Copy ctor.
 
virtual ~SO ()
 Virtual dtor.
 
 SO (SO &&)=delete
 
SO & operator= (const SO &)=delete
 
SO & operator= (SO &&)=delete
 
bool getExec () const
 Getter for exec_.
 
void setExec (bool p_exec)
 Setter for exec_.
 
virtual size_t getSize () const
 Returns the size of the SO.
 
virtual SO * clone () const
 Creates a new instance as copy with deep cloning.
 
virtual bool gt (OpError &p_ec, const SO *) const
 Greater than.
 
virtual bool ge (OpError &p_ec, const SO *) const
 Greater or equal.
 
- Public Member Functions inherited from Counter< SO >
 Counter (Counter< SO > &&)=delete
 
Counter< SO > & operator= (const Counter< SO > &)=delete
 
Counter< SO > & operator= (Counter< SO > &&)=delete
 

Protected Member Functions

bool invariant () const noexcept override
 Checks class invariants.
 
- Protected Member Functions inherited from Counter< SO >
 Counter ()
 Ctor.
 
 Counter (const Counter< SO > &)
 Copy ctor.
 
 ~Counter ()
 Dtor.
 
- Protected Member Functions inherited from DbC
 ~DbC ()=default
 Protected dtor.
 

Private Attributes

std::shared_ptr< SOFData > f_
 The data.
 

Additional Inherited Members

- Static Public Member Functions inherited from Counter< SO >
static size_t getTotalCounter ()
 Static getter for totaly created objects.
 
static size_t getAliveCounter ()
 Static getter for objects alive.
 
static size_t getWatermarkCounter ()
 Static getter for the object counter watermark.
 

Detailed Description

Semantic Object File.

Invariant
shared pointer is not null.

Constructor & Destructor Documentation

◆ SOF()

SOF::SOF ( const std::string &  p_name,
const std::string &  p_mode 
)
inlineexplicit

Ctor from a name.

Parameters
[in]p_nameThe file name.
[in]p_modeThe file open mode.

Member Function Documentation

◆ close()

OpError SOF::close ( int(*)(FILE *)  p_fclose = fclose)

Closes the file.

Can be called for already closed files.

Parameters
[in]p_fcloseCan be set to a fclose() function for mocking in unit tests.
Returns
OpError ... The error code or success.

◆ dup()

SOF * SOF::dup ( ) const
inlineoverridevirtual

Creates a new instance as copy following the red book definition.

Returns
SO * ... A copy.

Implements SO.

◆ equal()

bool SOF::equal ( const SO *  p_other) const
inlineoverridevirtual

Checks if this SO is equal to another SO.

Equality means:
SOL und SOM are always equal.
For SOD, SOF and SOK, share_ptr<> points to the same object.
For SOA, share_ptr<> points to the same object, but empty arrays are equal nonetheless.
For SOO and SOo the function pointer must be the same.
Otherwise the value must be the same, even for SOS with shared_ptr<>.

Returns
bool ... true if the SO's are of the same type and equal
See also
Will be used directly and unchanged as operator eq
Parameters
[in]p_otherThe object to compare with.

Implements SO.

◆ flush()

OpError SOF::flush ( )

Flushes the file.

Precondition
f_->file_ == nullptr
Returns
OpError ... The error code or success.

◆ invariant()

bool SOF::invariant ( ) const
inlineoverrideprotectedvirtualnoexcept

Checks class invariants.

Returns
bool ... Indicates whether the class invariants are maintained.

Reimplemented from DbC.

◆ isOpen()

bool SOF::isOpen ( ) const
inline

Checks if the file is open.

Precondition
f_->file_ != nullptr
Returns
bool ... true, if the file is open.

◆ open()

OpError SOF::open ( )

Opens the file.

Precondition
f_->file_ == nullptr
Returns
OpError ... The error code or success.

◆ opequal()

std::string SOF::opequal ( ) const
inlineoverridevirtual

String representation of object for operators '=', 'cvs' and 'stack'.

Returns
std::string ... The representation.

Implements SO.

◆ opequalequal()

std::string SOF::opequalequal ( ) const
inlineoverridevirtual

String representation for operators '==' and 'pstack'.

This function attempts to produce a result that resembles the red book syntax
for creating the object.

Returns
std::string ... The representation.

Reimplemented from SO.

◆ ot()

OTCode SOF::ot ( ) const
inlineoverridevirtual

Returns an OTCode.

A "manual" implementation of polymorphism, where C++-polymorphisms fail

Returns
OTCode ... The OTCode of the instance.

Implements SO.

◆ readLeonLine()

bool SOF::readLeonLine ( std::string &  p_str)

Our std::getline( istream, string ) version.

Precondition
f_->file_ != nullptr
Parameters
[out]p_strWill be cleared and filled.
Returns
bool ... Success or not.

◆ readline()

OpError SOF::readline ( std::string &  p_str,
bool &  p_eof 
)

Reads a line of text from file.

Precondition
p_str size <= max_int
Parameters
[in,out]p_strBuffer to write the text to. Limited by its size.
[out]p_eofEOF status of file after the operation.
Returns
OpError ... The error code or success.

◆ readstring()

OpError SOF::readstring ( std::string &  p_str,
bool &  p_eof 
)

Reads text from file.

Precondition
p_str ist not empty
Parameters
[in,out]p_strBuffer to write the text to. Limited by its size.
[out]p_eofEOF status of file after the operation.
Returns
OpError ... The error code or success.

◆ type()

std::string SOF::type ( ) const
inlineoverridevirtual

Returns a type name.

Returns
std::string ... The type name of the instance.

Implements SO.

◆ writestring() [1/2]

OpError SOF::writestring ( const std::string &  p_data)

Writes to file.

Parameters
[in]p_dataText to write.
Returns
OpError ... The error code or success.

◆ writestring() [2/2]

OpError SOF::writestring ( std::string_view  p_data)

Writes to file.

Parameters
[in]p_dataText to write.
Returns
OpError ... The error code or success.

The documentation for this class was generated from the following files: