Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
command-op-closure.hpp
Go to the documentation of this file.
1/*
2 COMMAND-OP-CLOSURE.hpp - implementation the closure for a command operation
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
27#ifndef CONTROL_COMMAND_OP_CLOSURE_H
28#define CONTROL_COMMAND_OP_CLOSURE_H
29
30#include "lib/meta/function.hpp"
38#include "lib/format-cout.hpp"
39
40#include <memory>
41#include <functional>
42#include <sstream>
43#include <string>
44
45
46
47
48namespace steam {
49namespace control {
50
51 using lib::meta::_Fun;
52 using lib::meta::Tuple;
55 using lib::meta::Nil;
56
58 using std::function;
59 using std::ostream;
60 using std::string;
61
62
63
64
65
66
68 template
69 < typename TY
70 , class BASE
71 , class TUP
72 , uint idx
73 >
75 : public BASE
76 {
77 TY & element() { return std::get<idx> (*this); }
78 TY const& element() const { return std::get<idx> (*this); }
79
80 public:
81 using BASE::BASE;
82
83
85
87
88 ostream&
89 dump (ostream& output) const
90 {
91 return BASE::dump (output << element() << ',');
92 }
93 };
94
95 template<class TUP, uint n>
96 class ParamAccessor<Nil, TUP, TUP, n>
97 : public TUP
98 {
99 public:
100 ParamAccessor (TUP const& tup)
101 : TUP(tup)
102 { }
103
107 ParamAccessor (ParamAccessor const&) =default;
109
110
112
113 ostream&
114 dump (ostream& output) const
115 {
116 return output;
117 }
118 };
119
120
121
126 template<typename SIG>
128 {
131
133
136
137 public:
139
140
142 : params_(Tuple<Args>())
144 { }
145
146 explicit
148 : params_(args)
150 { }
151
155 OpClosure (OpClosure const&) =default;
156 OpClosure (OpClosure&&) =default;
157
158
159 bool
160 isValid () const
161 {
162 return activated_;
163 }
164
165
174 void
176 {
178 std::apply (unboundFunctor.getFun<SIG>(), paramTuple);
179 }
180
181
182
183 operator string() const
184 {
185 std::ostringstream buff;
186 params_.dump (buff << "OpClosure(" );
187
188 string dumped (buff.str());
189 if (10 < dumped.length())
190 // remove trailing comma...
191 return dumped.substr (0, dumped.length()-1) +")";
192 else
193 return dumped+")";
194 }
195 };
196
197
198
199
200}} // namespace steam::control
201#endif /*CONTROL_COMMAND_OP_CLOSURE_H*/
Implementation helper to bind Steam-Layer commands with arbitrary argument tuples.
Foundation for a custom allocation manager, tracking the created objects by smart-ptrs.
Decorating a tuple type with auxiliary data access operations.
_X_< Head, NextAccessor, TUP, i > Product
type of the product created by this template.
closure to deal with the actual command operation.
OpClosure(OpClosure &&)=default
OpClosure(OpClosure const &)=default
OpClosure & operator=(OpClosure const &)=delete
we deliberately support immutable types as command arguments
BuildTupleAccessor< ParamAccessor, Args > Builder
OpClosure(ArgTuple const &args)
void invoke(CmdFunctor const &unboundFunctor)
Core operation: use the embedded argument tuple for invoking a functor.
ParamAccessor(ParamAccessor const &)=default
Helper for accessing an individual function parameter.
ostream & dump(ostream &output) const
A closure enabling self-contained execution of commands within the SteamDispatcher.
Automatically use custom string conversion in C++ stream output.
Partial function application and building a complete function closure.
Metaprogramming tools for detecting and transforming function types.
unsigned int uint
Definition integral.hpp:29
helpers for fail-safe invocation of comparison operations from generic code.
BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Tuple< TYPES > buildTuple(SRC &&values)
convenience shortcut to build a tuple from some suitable source data.
»Empty« mark
Definition typelist.hpp:82
basic_ostream< char, char_traits< char > > ostream
Steam-Layer implementation namespace root.
Generic wrapper carrying a function object while hiding the actual function signature.
Trait template for uniform access to function signature types.
Definition function.hpp:144
Metaprogramming with tuples-of-types and the std::tuple record.
Specialised adapter to consume a record of GenNode entries to build a tuple.
Abstract foundation for building custom allocation managers.