OTest2
A C++ testing framework
stateregistry.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 <stateregistry.h>
21 
22 #include <assert.h>
23 #include <map>
24 
25 #include <utils.h>
26 
27 namespace OTest2 {
28 
29 struct StateRegistry::Impl {
30  public:
31  StateRegistry* owner;
32 
33  typedef std::map<std::string, StatePtr> States;
34  States states;
35 
36  /* -- avoid copying */
37  Impl(
38  const Impl&) = delete;
39  Impl& operator =(
40  const Impl&) = delete;
41 
42  explicit Impl(
43  StateRegistry* owner_);
44  ~Impl();
45 };
46 
47 StateRegistry::Impl::Impl(
48  StateRegistry* owner_) :
49  owner(owner_),
50  states() {
51 
52 }
53 
54 StateRegistry::Impl::~Impl() {
55 
56 }
57 
59  pimpl(new Impl(this)) {
60 
61 }
62 
64  odelete(pimpl);
65 }
66 
68  const std::string& name_,
69  StatePtr state_) {
70  assert(!name_.empty() && state_ != nullptr);
71  pimpl->states.insert(Impl::States::value_type(name_, state_));
72 }
73 
75  const std::string& name_) const {
76  assert(!name_.empty());
77  auto iter_(pimpl->states.find(name_));
78  if(iter_ != pimpl->states.end())
79  return (*iter_).second;
80  else
81  return StatePtr();
82 }
83 
84 } /* namespace OTest2 */
OTest2::StateRegistry::operator=
StateRegistry & operator=(const StateRegistry &)=delete
utils.h
OTest2::StateRegistry::~StateRegistry
~StateRegistry()
Dtor.
Definition: stateregistry.cpp:63
OTest2::StateRegistry::registerState
void registerState(const std::string &name_, StatePtr state_)
Register new state.
Definition: stateregistry.cpp:67
OTest2
Definition: assertbean.h:25
OTest2::StateRegistry::StateRegistry
StateRegistry()
Ctor.
Definition: stateregistry.cpp:58
OTest2::StatePtr
std::shared_ptr< State > StatePtr
Pointer to test state objects.
Definition: stateptr.h:27
OTest2::StateRegistry::getState
StatePtr getState(const std::string &name_) const
Get state with specified name_.
Definition: stateregistry.cpp:74
stateregistry.h
OTest2::odelete
void odelete(T_ *&object_)
Delete a pointer and set it invalid.
Definition: utils.h:34