OTest2
A C++ testing framework
commandstack.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 <commandstack.h>
21 
22 #include <assert.h>
23 #include <vector>
24 
25 #include <command.h>
26 #include <utils.h>
27 
28 namespace OTest2 {
29 
30 struct CommandStack::Impl {
31  public:
32  CommandStack* owner;
33 
34  typedef std::vector<CommandPtr> Stack;
35  Stack stack;
36 
37  /* -- avoid copying */
38  Impl(
39  const Impl&) = delete;
40  Impl& operator =(
41  const Impl&) = delete;
42 
43  explicit Impl(
44  CommandStack* owner_);
45  ~Impl();
46 };
47 
48 CommandStack::Impl::Impl(
49  CommandStack* owner_) :
50  owner(owner_) {
51 
52 }
53 
54 CommandStack::Impl::~Impl() {
55 
56 }
57 
59  pimpl(new Impl(this)) {
60 
61 }
62 
64  odelete(pimpl);
65 }
66 
68  CommandPtr command_) {
69  assert(command_ != nullptr);
70  pimpl->stack.push_back(command_);
71 }
72 
74  CommandPtr command_) {
75  assert(command_ != nullptr);
76  assert(!pimpl->stack.empty());
77  pimpl->stack.back() = command_;
78 }
79 
81  assert(!pimpl->stack.empty());
82  return pimpl->stack.back();
83 }
84 
86  assert(!pimpl->stack.empty());
87  pimpl->stack.pop_back();
88 }
89 
90 bool CommandStack::empty() const {
91  return pimpl->stack.empty();
92 }
93 
94 } /* namespace OTest2 */
OTest2::CommandStack::operator=
CommandStack & operator=(const CommandStack &)=delete
OTest2::CommandStack::popCommand
void popCommand()
Pop a command from the top of the stack.
Definition: commandstack.cpp:85
OTest2::CommandStack::pushCommand
void pushCommand(CommandPtr command_)
Push a command into the stack.
Definition: commandstack.cpp:67
command.h
commandstack.h
utils.h
OTest2::CommandStack::~CommandStack
~CommandStack()
Dtor.
Definition: commandstack.cpp:63
OTest2::CommandStack::empty
bool empty() const
Check whether the stack is empty.
Definition: commandstack.cpp:90
OTest2
Definition: assertbean.h:25
OTest2::CommandStack::CommandStack
CommandStack()
Ctor.
Definition: commandstack.cpp:58
OTest2::CommandStack::replaceCommand
void replaceCommand(CommandPtr command_)
Replace a command at the top of the stack.
Definition: commandstack.cpp:73
OTest2::CommandStack::topCommand
CommandPtr topCommand() const
Get the top command.
Definition: commandstack.cpp:80
OTest2::CommandPtr
std::shared_ptr< Command > CommandPtr
Definition: commandptr.h:27
OTest2::odelete
void odelete(T_ *&object_)
Delete a pointer and set it invalid.
Definition: utils.h:34