Kryptostack
stack.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <string>
8#include <deque>
9#include "counter.h"
10#include "helper.h"
11#include "so.h"
12
13using namespace std;
14
15
22class Stack : public Counter<Stack> {
23 deque<SOp> q_;
25public:
27 Stack() {}
28
30 ~Stack() {}
31
34 size_t getSize() const { return q_.size(); }
35
39 SOp at( size_t p_pos ) { return q_.at( p_pos ); }
40
43 SOp top() { return q_.back(); }
44
47 void pop() { q_.pop_back(); }
48
53 SOp retval = q_.back();
54 q_.pop_back();
55 return retval;
56 }
57
59 void pop_delete() {
60 SOp x = q_.back();
61 delete x;
62 q_.pop_back();
63 }
64
67 void push( SOp p_s ) { q_.push_back( p_s ); }
68
70 void push2( SOp p_o1, SOp p_o2 ) { q_.push_back( p_o1 ); q_.push_back( p_o2 ); }
71
73 void push3( SOp p_o1, SOp p_o2, SOp p_o3 ) { q_.push_back( p_o1 ); q_.push_back( p_o2 ); q_.push_back( p_o3 ); }
74
76 void push4( SOp p_o1, SOp p_o2, SOp p_o3, SOp p_o4 ) { q_.push_back( p_o1 ); q_.push_back( p_o2 ); q_.push_back( p_o3 ); q_.push_back( p_o4 ); }
77
79 bool underflowcheck( size_t p_g ) const { return q_.size() >= p_g; }
80
84 bool otchecker( const string& p_s );
85
92 bool countto( size_t & p_retval, OTCode p_code );
93
98 SOp find( const SO * p_key ) const;
99
104 __int128 getI();
105
109 size_t getISize_t();
110};
Counter base class.
Definition: counter.h:10
Semantic Object.
Definition: so.h:17
Our own container adapter to build a stack.
Definition: stack.h:22
SOp at(size_t p_pos)
Returns a copy of the SOp at the given position.
Definition: stack.h:39
bool otchecker(const string &p_s)
Checks SO classes on operational stack against a string of given OTCodes.
Definition: stack.cpp:29
Stack()
CTor.
Definition: stack.h:27
__int128 getI()
I from Stack.
Definition: stack.cpp:59
void push4(SOp p_o1, SOp p_o2, SOp p_o3, SOp p_o4)
Pushes the 4 objects onto the Stack and transfers ownership to the Stack.
Definition: stack.h:76
public_accessor size_t getSize() const
Returns the number of objects on the Stack.
Definition: stack.h:34
~Stack()
Dtor.
Definition: stack.h:30
bool countto(size_t &p_retval, OTCode p_code)
Count the objects on the Stack down to but excluding the object from the given type.
Definition: stack.cpp:15
void push3(SOp p_o1, SOp p_o2, SOp p_o3)
Pushes the 3 objects onto the Stack and transfers ownership to the Stack.
Definition: stack.h:73
public_other void pop()
Removes the top most object from Stack, but the referenced SO will not be deleted.
Definition: stack.h:47
size_t getISize_t()
I from Stack as size_t.
Definition: stack.cpp:72
SOp find(const SO *p_key) const
Finds the given key within the whole stack, assuming a stack with dictionaries only.
Definition: stack.cpp:46
bool underflowcheck(size_t p_g) const
Checks Stack against given size.
Definition: stack.h:79
void push2(SOp p_o1, SOp p_o2)
Pushes the 2 objects onto the Stack and transfers ownership to the Stack.
Definition: stack.h:70
SOp top()
Returns a copy of the SOp of the top most position.
Definition: stack.h:43
SOp top_pop()
Returns a copy of the top SOp, removes the SOp from the Stack.
Definition: stack.h:52
deque< SOp > q_
Internally the Stack is a STL deque<SOp>.
Definition: stack.h:23
void push(SOp p_s)
Pushes the object onto the Stack and transfers ownership to the Stack.
Definition: stack.h:67
void pop_delete()
Removes the top most object from Stack, and the referenced SO will be deleted.
Definition: stack.h:59
The class Counter.
#define public_other
other member functions
Definition: helper.h:16
#define public_accessor
accessor functions
Definition: helper.h:14
Miscellaneous definitions and functions.
char OTCode
OTCode - the Object Type Code.
Definition: helper.h:22
Class semantic object.