Lumiera  0.pre.03
»edit your freedom«
command-signature.hpp
Go to the documentation of this file.
1 /*
2  COMMAND-SIGNATURE.hpp - deriving suitable command function signatures
3 
4  Copyright (C) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
46 #ifndef CONTROL_COMMAND_SIGNATURE_H
47 #define CONTROL_COMMAND_SIGNATURE_H
48 
49 #include "lib/meta/function.hpp"
50 #include "lib/meta/typelist.hpp"
53 
54 #include <functional>
55 
56 
57 
58 namespace lumiera {
59 namespace error {
60  LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS);
61  LUMIERA_ERROR_DECLARE (MISSING_MEMENTO);
62 }}
63 
64 namespace steam {
65 namespace control {
66 
67  using std::function;
68 
70  using lib::meta::_Fun;
71  using lib::meta::Types;
72  using lib::meta::Append;
74 
75 
83  template<typename SIG, typename MEM>
85  {
86  using Args = typename _Fun<SIG>::Args;
87  using ArgList = typename Args::List;
88  using ExtendedArglist = typename Append<ArgList, MEM>::List;
89  using ExtendedArgs = typename Types<ExtendedArglist>::Seq;
90 
91  public:
92  using OperateSig = typename BuildFunType<void, Args>::Sig;
93  using CaptureSig = typename BuildFunType<MEM, Args>::Sig;
94  using UndoOp_Sig = typename BuildFunType<void, ExtendedArgs>::Sig;
95  using CmdArgs = Args;
96  using Memento = MEM;
97  };
98 
99 
100 
101 
116  template<typename SIG>
118  {
119  // preparation: dissect the function signature into arguments and result
120  using Args = typename _Fun<SIG>::Args;
121  using Ret = typename _Fun<SIG>::Ret;
122 
124  template<typename RET, typename ARG>
125  struct Case
126  {
127  using Memento = RET;
128 
129  using ExtendedArglist = typename Append<ARG, Memento>::List;
130  using ExtendedArgs = typename Types<ExtendedArglist>::Seq;
131 
132  using OperateSig = typename BuildFunType<void, ARG>::Sig;
133  using CaptureSig = typename BuildFunType<Ret,ARG>::Sig;
134  using UndoOp_Sig = typename BuildFunType<void, ExtendedArgs>::Sig;
135  };
137  template<typename ARG>
138  struct Case<void,ARG>
139  {
140  using Args = typename ARG::List;
141 
142  using Memento = typename SplitLast<Args>::Type;
143  using OperationArglist = typename SplitLast<Args>::List;
144  using OperationArgs = typename Types<OperationArglist>::Seq;
145 
146  using OperateSig = typename BuildFunType<void, OperationArgs>::Sig;
147  using CaptureSig = typename BuildFunType<Ret,OperationArgs>::Sig;
148  using UndoOp_Sig = typename BuildFunType<void, ARG>::Sig;
149  };
150 
151  public:
152  using CaptureSig = typename Case<Ret,Args>::CaptureSig;
153  using UndoOp_Sig = typename Case<Ret,Args>::UndoOp_Sig;
154  using OperateSig = typename Case<Ret,Args>::OperateSig;
155  using Memento = typename Case<Ret,Args>::Memento;
156  };
157 
158 
159 
160 }} // namespace steam::control
161 #endif
Build function types from given Argument types.
Definition: function.hpp:350
A template metaprogramming technique for manipulating collections of types.
Helper for uniform access to function signature types.
Definition: function.hpp:108
Some basic facilities for manipulating type sequences.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
Steam-Layer implementation namespace root.
Case1: defining the Undo-Capture function.
Metaprogramming tools for transforming functor types.
append lists-of-types
access the last list element
Lumiera public interface.
Definition: advice.cpp:113
Metaprogramming helper for building Command function signatures.
Type analysis helper template.
Metaprogramming: Helpers for manipulating lists-of-types.