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

Semantic Object stacK. More...

#include <sok.h>

+ Inheritance diagram for SOK:
+ Collaboration diagram for SOK:

Classes

struct  SOKDeque
 Semantic Object Stack - deque member class. More...
 

Public Member Functions

 SOK ()
 Ctor.
 
 SOK (const SOcomposite &p_other)
 Ctor from parent class.
 
 SOK (const SOK &p_other)
 Copy ctor.
 
 ~SOK () override
 Dtor.
 
 SOK (SOK &&)=delete
 
SOK & operator= (const SOK &)=delete
 
SOK & operator= (SOK &&)=delete
 
SOK * dup () const override
 Creates a new instance as copy following the red book definition.
 
SOK * clone () const override
 Creates a new instance as copy with deep cloning.
 
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.
 
size_t getSize () const override
 Returns the size of the SO.
 
size_t treeheight (size_t p_myheight) const override
 Tree Height.
 
size_t getWatermark () const
 Returns the maximum size the stack has reached.
 
SOp ncat (size_t p_pos) const
 Returns a copy of the SOp at the given position.
 
SOp peek () const
 Returns a copy of the SOp of the top most position.
 
void putSO (size_t p_index, SOp p_sop)
 Put a single SO into a stack object.
 
SOp pop ()
 Returns a copy of the top SOp, removes the SOp from the SOK.
 
void pop_delete ()
 Removes the top most object from SOK, and the referenced SO will be deleted.
 
void push (SOp p_o1)
 Pushes the object onto the SOK and transfers ownership to the SOK.
 
void push (std::initializer_list< SOp > p_list)
 Pushes n objects onto the SOK and transfers ownership to the SOK.
 
void push_front (SOp p_obj)
 Pushes the object onto the front side of the SOK and transfers ownership to the SOK.
 
bool underflowcheck (size_t p_size) const
 Checks SOK against given size.
 
bool otchecker (std::initializer_list< OTCode > p_list) const
 Checks SO classes on the operand stack against a list of given OTCodes.
 
bool otchecker (OTCode p_code) const
 Checks SO classes on the operand stack against an OTCode.
 
bool otcheckerOr (OTCode p_code1, OTCode p_code2) const
 Checks SO class on the operand stack against two possible OTCodes.
 
bool countto (size_t &p_retval, OTCode p_code) const
 Count the objects on the SOK down to but excluding the object from the given type.
 
SOp findValue (const SO *p_key) const
 Finds the given key within the whole stack, assuming a stack with dictionaries only.
 
SOp findDict (const SO *p_key) const
 Finds the dictionary storing the given key within the whole stack, assuming a stack with dictionaries only.
 
__int128 getI (OpError &p_ec)
 I from SOK.
 
__float128 getR (OpError &p_ec)
 R from SOK.
 
__float128 getIorRasR ()
 I or R from SOK as R Deletes the top object after reading its value.
 
size_t getISize_t (OpError &p_ec)
 I from SOK as size_t.
 
- Public Member Functions inherited from SOcomposite
std::string opequal () const override
 String representation of object for operators '=', 'cvs' and 'stack'.
 
 SO ()
 Ctor.
 
 SO (bool p_exec)
 Ctor.
 
 SO (const SO &p_other)
 Copy ctor.
 
 SO (SO &&)=delete
 
- 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 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< SOKDeque > deque_
 The shared deque.
 

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 stacK.

Our own container adapter to std::deque to build a stack. It's a stack of pointers to SO. The bottom object has position 0. The top most object has position size-1.

Invariant
deque.size <= watermark
deque_ != nullptr
deque_.stldeque_ elements are never null.

Constructor & Destructor Documentation

◆ SOK()

SOK::SOK ( const SOcomposite &  p_other)
inlineexplicit

Ctor from parent class.

Only copies the SOcomposite part; the deque_ is initialized as empty.

Parameters
[in]p_otherParent class object.

Member Function Documentation

◆ clone()

SOK * SOK::clone ( ) const
overridevirtual

Creates a new instance as copy with deep cloning.

Default implementation falls back to dup().
Subclasses must override this if deep cloning is required.

Returns
SO * ... A deep copy.
Postcondition
return value != nullptr
return value maintains invariants

Reimplemented from SO.

◆ countto()

bool SOK::countto ( size_t &  p_retval,
OTCode  p_code 
) const

Count the objects on the SOK down to but excluding the object from the given type.

Implemented without C++ polymorphisms.

Parameters
[out]p_retvalNumber of objects.
[in]p_codeOTCode to find.
Returns
bool ... true if the given OTCode can be found.

◆ dup()

SOK * SOK::dup ( ) const
inlineoverridevirtual

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

Returns
SO * ... A copy.

Implements SO.

◆ equal()

bool SOK::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.

◆ findDict()

SOp SOK::findDict ( const SO *  p_key) const

Finds the dictionary storing the given key within the whole stack, assuming a stack with dictionaries only.

Equality is determined by SO::equal().
We return a SOp instead of a SOD * to reduce coupling.

Parameters
[in]p_keyThe key to search for.
Returns
SOp ... Points to the found dictionary, the ownership stays within the stack. Returns a null pointer if p_key can't be found.
Precondition
p_key != nullptr

◆ findValue()

SOp SOK::findValue ( const SO *  p_key) const

Finds the given key within the whole stack, assuming a stack with dictionaries only.

Equality is determined by SO::equal().

Precondition
p_key != nullptr
Parameters
[in]p_keyThe key to search for.
Returns
SOp ... Points to the found value, the ownership stays within the dictionary. Returns a null pointer if key can't be found.

◆ getI()

__int128 SOK::getI ( OpError &  p_ec)

I from SOK.

Deletes the top object after reading its integer value.
Checks the type of the operand stack object.
Does not check for stack underflow.

Precondition
stack size > 0
Parameters
[out]p_ecSuccess or error code.
Returns
__int128 ... The integer from the operand stack.

◆ getIorRasR()

__float128 SOK::getIorRasR ( )

I or R from SOK as R Deletes the top object after reading its value.


Does not check the type of the operand stack object.
Does not check for stack underflow.

Precondition
stack size > 0
top stack object is an I or a R
Returns
__float128 ... The float from the operand stack.

◆ getISize_t()

size_t SOK::getISize_t ( OpError &  p_ec)

I from SOK as size_t.

Deletes the top object after reading its integer value.
Exits with rangecheck, if the integer from stack can not be converted to size_t.
Checks the type of the operand stack object.
Does not check for stack underflow.

Precondition
stack size > 0
Parameters
[out]p_ecSuccess or error code.
Returns
size_t ... The float from the operand stack.

◆ getR()

__float128 SOK::getR ( OpError &  p_ec)

R from SOK.

Deletes the top object after reading its real value.
Checks the type of the operand stack object.
Does not check for stack underflow.

Precondition
stack size > 0
Parameters
[out]p_ecSuccess or error code.
Returns
__float128 ... The float from the operand stack.

◆ getSize()

size_t SOK::getSize ( ) const
inlineoverridevirtual

Returns the size of the SO.

Default implementation returns 1 (for simple objects).
Override in subclasses to return the actual size (e.g., length of a string, number of elements in a composite).

Reimplemented from SO.

◆ getWatermark()

size_t SOK::getWatermark ( ) const
inline

Returns the maximum size the stack has reached.

Returns
size_t ... The watermark value.

◆ invariant()

bool SOK::invariant ( ) const
inlineoverrideprotectedvirtualnoexcept

Checks class invariants.

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

Reimplemented from DbC.

◆ ncat()

SOp SOK::ncat ( size_t  p_pos) const
inline

Returns a copy of the SOp at the given position.

The SOK keeps ownership of the returned pointer.

Note
ncat is short for 'Non Checking AT'.
Precondition
p_pos < dequesize
Parameters
[in]p_posPosition. There is no range check.
Returns
SO * ... A copy of the pointer at the selected position.

◆ opequalequal()

std::string SOK::opequalequal ( ) const
overridevirtual

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 SOK::ot ( ) const
inlineoverridevirtual

Returns an OTCode.

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

Returns
OTCode ... The OTCode of the instance.

Implements SO.

◆ otchecker() [1/2]

bool SOK::otchecker ( OTCode  p_code) const
inline

Checks SO classes on the operand stack against an OTCode.

Precondition
stack not empty
p_code != OTCode::X
Parameters
[in]p_codeOTCode.
Returns
bool ... true if top element on stack matches the given OTCode.

◆ otchecker() [2/2]

bool SOK::otchecker ( std::initializer_list< OTCode >  p_list) const

Checks SO classes on the operand stack against a list of given OTCodes.

OTCode::X in p_list matches all object types on the stack.

Precondition
stacksize >= length(p_s)
listsize >= 2
Parameters
[in]p_listList of at least 2 OTCodes.
Returns
bool ... true if stack SOs satisfy the given list.

◆ otcheckerOr()

bool SOK::otcheckerOr ( OTCode  p_code1,
OTCode  p_code2 
) const
inline

Checks SO class on the operand stack against two possible OTCodes.

Precondition
stack not empty
p_code1 != OTCode::X
p_code2 != OTCode::X
Parameters
[in]p_code1first OTCode
[in]p_code2second OTCode
Returns
bool ... true if top object has type p_code1 or p_code2

◆ peek()

SOp SOK::peek ( ) const
inline

Returns a copy of the SOp of the top most position.

The SOK keeps ownership.
Calling peek on an empty stack causes undefined behavior.

Precondition
dequesize > 0.
Returns
SO * ... Copy of pointer to top SO.

◆ pop()

SOp SOK::pop ( )
inline

Returns a copy of the top SOp, removes the SOp from the SOK.

The caller takes ownership of the returned pointer.

Precondition
dequesize > 0
Returns
SO * ... The removed pointer.

◆ pop_delete()

void SOK::pop_delete ( )
inline

Removes the top most object from SOK, and the referenced SO will be deleted.

Precondition
dequesize > 0

◆ push() [1/2]

void SOK::push ( SOp  p_o1)

Pushes the object onto the SOK and transfers ownership to the SOK.

The SOK is now responsible for managing the object's lifetime.

Precondition
p_o1 != nullptr
Parameters
[in]p_o1... Pointer to SO.

◆ push() [2/2]

void SOK::push ( std::initializer_list< SOp >  p_list)

Pushes n objects onto the SOK and transfers ownership to the SOK.

Precondition
all p_list pointers != nullptr
Parameters
[in]p_list... Initializer list of pointers to SOs.

◆ push_front()

void SOK::push_front ( SOp  p_obj)

Pushes the object onto the front side of the SOK and transfers ownership to the SOK.

This is a non-stack feature supporting the constructing of a SOK from the operand stack.
The SOK is now responsible for managing the object's lifetime.

Precondition
p_obj != nullptr
Parameters
[in]p_obj... Pointer to SO.

◆ putSO()

void SOK::putSO ( size_t  p_index,
SOp  p_sop 
)
inline

Put a single SO into a stack object.

The existing SOx will be deleted.

Precondition
p_index < stacksize
p_sop != nullptr
Parameters
[in]p_indexIndex from 0 to size-1. Attention: no range check.
[in]p_sopThe SOK takes ownership of this SO.

◆ treeheight()

size_t SOK::treeheight ( size_t  p_myheigth) const
overridevirtual

Tree Height.

The composite semantic objects can contain other composite semantic objects.
This creates a tree of objects. treeheigth() calculates the height of this tree
starting at this.

Loops will be dedected by an heuristics. We stop the recursion if the heigth
exceeds maxtreeheight, a global constant in Leonardus.

Parameters
[in]p_myheigthCall with 0. Used internally for recursion.
Returns
size_t ... The maximum height of the tree of SOcomposite -or- maxtreeheight if there is a loop.

Reimplemented from SOcomposite.

◆ type()

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

Returns a type name.

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

Implements SO.

◆ underflowcheck()

bool SOK::underflowcheck ( size_t  p_size) const
inline

Checks SOK against given size.

Parameters
[in]p_sizeCheck value.
Returns
bool ... true if stack is large enough.

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