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 (OTCode p_restr)
 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_view type () const override
 Returns a type name.
 
size_t getSize () const override
 Returns the size of the SO.
 
size_t dagheight (size_t p_myheight) const override
 DAG Height.
 
OTCode getRestricted () const
 Returns the restriction.
 
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 (SO *p_key) const
 Finds the given key within the whole stack, assuming a stack with dictionaries only.
 
SOp findDict (SO *p_key) const
 Finds the dictionary storing the given key within the whole stack, assuming a stack with dictionaries only.
 
__int128 getI ()
 I from SOK.
 
__float128 getR ()
 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 SOshptr
std::string opequal () const override
 String representation of object for operators '=', 'cvs' and 'stack'.
 
bool equal (const SO *p_other) const override
 Checks if this SO is equal to another SO.
 
 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 ()=default
 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

void * shptr () const override
 Pointer to the shared object.
 
bool invariant () const noexcept override
 Checks class invariants.
 
- Protected Member Functions inherited from SOshptr
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.
 
OTCode restricted_ { OTCode::X }
 Restrict container entries to this type.
 

Additional Inherited Members

- Static Public Member Functions inherited from SOcomposite
static bool otcodeIsComposite (OTCode p_code)
 Checks if an OTCode represents a composite type (A, Ax, D, K).
 
- 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. It can be constructed to hold only a certain object type, which is used to guard the system dictionary stack.

Invariant
inherited from SOcomposite
deque.size <= watermark
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.

◆ dagheight()

size_t SOK::dagheight ( size_t  p_myheigth) const
overridevirtual

DAG Height.

The composite semantic objects can contain other composite semantic objects.
This creates a directed acyclic graph (DAG) of objects.
dagheight() calculates the height of this DAG starting at this.

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

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

Implements SOcomposite.

◆ dup()

SOK * SOK::dup ( ) const
inlineoverridevirtual

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

Returns
SO * ... A copy.

Implements SO.

◆ findDict()

SOp SOK::findDict ( 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().
The ownership of the returned SOP stays within the stack.
We return a SOp instead of a SOD * to reduce coupling.

Precondition
p_key != nullptr
restricted_ == OTCode::D
Parameters
[in]p_keyThe key to search for.
Returns
SOp ... Points to the found dictionary. Returns a null pointer if p_key can't be found.

◆ findValue()

SOp SOK::findValue ( 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
restricted_ == OTCode::D
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 ( )

I from SOK.

Deletes the top object after reading its integer value.
Does not check for stack underflow. Does not check OTCode.

Precondition
stack size > 0
otchecker( OTCode::I )
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 integer from the operand stack.

◆ getR()

__float128 SOK::getR ( )

R from SOK.

Deletes the top object after reading its real value.
Does not check for stack underflow. Does not check OTCode.

Precondition
stack size > 0
otchecker( OTCode::R )
Returns
__float128 ... The float from the operand stack.

◆ getRestricted()

OTCode SOK::getRestricted ( ) const
inline

Returns the restriction.

Returns
OTCode ... The restriction.

◆ 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 object).

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
restricted_ holds
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
restricted_ holds
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
restricted_ holds
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
restricted_ holds
Parameters
[in]p_indexIndex from 0 to size-1. Attention: no range check.
[in]p_sopThe SOK takes ownership of this SO.

◆ shptr()

void * SOK::shptr ( ) const
inlineoverrideprotectedvirtual

Pointer to the shared object.

Returns
void * ... The naked pointer.

Implements SOshptr.

◆ type()

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

Returns a type name.

Returns
std::string_view ... 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.

Member Data Documentation

◆ restricted_

OTCode SOK::restricted_ { OTCode::X }
private

Restrict container entries to this type.

OTCode::X is the value indicating no restriction.


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