Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
command-impl-clone-builder.hpp
Go to the documentation of this file.
1/*
2 COMMAND-IMPL-CLONE-BUILDER.hpp - Cloning command implementation without disclosing concrete type
3
4 Copyright (C)
5 2009, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
37#ifndef CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
38#define CONTROL_COMMAND_IMPL_CLONE_BUILDER_H
39
42#include "lib/opaque-holder.hpp"
43#include "lib/nocopy.hpp"
44
45
46namespace steam {
47namespace control {
48
51
52
53 namespace impl { // Helper: type erased context for creating command clones
54
56 {
57 virtual ~CloneContext() {}
58
59 virtual UndoMutation const& getUndoFunc() { NOTREACHED(); }
60 virtual PClo const& getClosure() { NOTREACHED(); }
61 virtual bool isValid() { return false; }
62 };
63
65 : public CloneContext
66 {
69
70 virtual UndoMutation const& getUndoFunc() { return newUndoFunctor_; }
71 virtual PClo const& getClosure() { return newClosure_; }
72 virtual bool isValid() { return true; }
73
74
80 template<typename ARG>
81 ARG&
83 {
85
86 return static_cast<ARG&> (*newClosure_);
87 }
88
89
90 public:
91
92 template<typename ARG>
94 , TypedAllocationManager& allocator
95 )
96 : newClosure_(allocator.create<ARG> (origArgHolder))
97 , newUndoFunctor_(downcast<ARG>().getMementoWiring())
98 { }
99 };
100
101 }//(End) impl namespace
102
103
104
105
106
116 {
118
121
122 public:
126
127
137 template<typename ARG>
138 void
140 {
141 REQUIRE (!newContext_->isValid(), "Lifecycle-Error");
142
144 }
145
146
147
149 UndoMutation const&
151 {
152 REQUIRE (newContext_->isValid());
153 return newContext_->getUndoFunc();
154 }
155
156
159 PClo const&
161 {
162 REQUIRE (newContext_->isValid());
163 return newContext_->getClosure();
164 }
165 };
166
167
168
169
170
171}} // namespace steam::control
172#endif
Buffer to place and maintain an object instance privately within another object.
Foundation for a custom allocation manager, tracking the created objects by smart-ptrs.
Visitor to support creating a CommandImpl clone.
InPlaceBuffer< impl::CloneContext, sizeof(impl::ClonedContext)> ContextHolder
UndoMutation const & clonedUndoMutation()
after visitation: use pre-built bits to provide a cloned UndoFunctor
void buildCloneContext(ARG const &origArgHolder)
to be executed from within the specifically typed context of a concrete command StorageHolder; alloca...
PClo const & clonedClosuere()
after visitation: provide cloned StorageHolder, but already stripped down to the generic usage type
Specialised version of the command Mutation functor, used to implement the UNDO functionality.
ClonedContext(ARG const &origArgHolder, TypedAllocationManager &allocator)
ARG & downcast()
helper for accessing the new cloned closure through the specific concrete type.
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Core of a Steam-Layer command: functor containing the operation to be executed.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
std::shared_ptr< CmdClosure > PClo
Steam-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Helper allowing type erasure while holding the actual object inline.
Abstract foundation for building custom allocation managers.
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition util.hpp:514