OTest2
A C++ testing framework
semanticstack.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <semanticstack.h>
21 
22 #include <assert.h>
23 #include <vector>
24 
25 #include <utils.h>
26 
27 namespace OTest2 {
28 
29 struct SemanticStack::Impl {
30  SemanticStack* owner;
31 
32  typedef std::vector<bool> Stack;
33  Stack stack;
34 
35  /* -- avoid copying */
36  Impl(
37  const Impl&) = delete;
38  Impl& operator =(
39  const Impl&) = delete;
40 
41  explicit Impl(
42  SemanticStack* owner_);
43  ~Impl();
44 };
45 
46 SemanticStack::Impl::Impl(
47  SemanticStack* owner_) :
48  owner(owner_) {
49 
50 }
51 
52 SemanticStack::Impl::~Impl() {
53 
54 }
55 
57  pimpl(new Impl(this)) {
58 
59 }
60 
62  odelete(pimpl);
63 }
64 
66  bool value_) {
67  pimpl->stack.push_back(value_);
68 }
69 
70 bool SemanticStack::top() const {
71  assert(!pimpl->stack.empty());
72  return pimpl->stack.back();
73 }
74 
76  bool value_) {
77  assert(!pimpl->stack.empty());
78  pimpl->stack.back() = value_;
79 }
80 
82  assert(!pimpl->stack.empty());
83  pimpl->stack.pop_back();
84 }
85 
87  assert(pimpl->stack.size() >= 2);
88  bool value_(pimpl->stack.back());
89  pimpl->stack.pop_back();
90  pimpl->stack.back() = pimpl->stack.back() && value_;
91 }
92 
94  return pimpl->stack.size() == 1;
95 }
96 
97 } /* namespace OTest2 */
OTest2::SemanticStack::isFinished
bool isFinished() const
Returns true if just one value is in the stack (result of the entire test).
Definition: semanticstack.cpp:93
OTest2::SemanticStack::popAnd
void popAnd()
AND last two values and replace them by the result.
Definition: semanticstack.cpp:86
OTest2::SemanticStack::SemanticStack
SemanticStack()
Ctor.
Definition: semanticstack.cpp:56
utils.h
OTest2::SemanticStack::push
void push(bool value_)
Push a value.
Definition: semanticstack.cpp:65
OTest2::SemanticStack::~SemanticStack
~SemanticStack()
Dtor.
Definition: semanticstack.cpp:61
OTest2::SemanticStack::operator=
SemanticStack & operator=(const SemanticStack &)=delete
semanticstack.h
OTest2
Definition: assertbean.h:25
OTest2::SemanticStack::pop
void pop()
Pop top value.
Definition: semanticstack.cpp:81
OTest2::SemanticStack::setTop
void setTop(bool value_)
Set top value.
Definition: semanticstack.cpp:75
OTest2::odelete
void odelete(T_ *&object_)
Delete a pointer and set it invalid.
Definition: utils.h:34
OTest2::SemanticStack::top
bool top() const
Get top value.
Definition: semanticstack.cpp:70