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)
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_SIGNATURE_H
38 #define CONTROL_COMMAND_SIGNATURE_H
39 
40 #include "lib/meta/function.hpp"
41 #include "lib/meta/typelist.hpp"
44 
45 #include <functional>
46 
47 
48 
49 namespace lumiera {
50 namespace error {
51  LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS);
52  LUMIERA_ERROR_DECLARE (MISSING_MEMENTO);
53 }}
54 
55 namespace steam {
56 namespace control {
57 
58  using std::function;
59 
61  using lib::meta::_Fun;
62  using lib::meta::Types;
63  using lib::meta::Append;
65 
66 
74  template<typename SIG, typename MEM>
76  {
77  using Args = typename _Fun<SIG>::Args;
78  using ArgList = typename Args::List;
79  using ExtendedArglist = typename Append<ArgList, MEM>::List;
80  using ExtendedArgs = typename Types<ExtendedArglist>::Seq;
81 
82  public:
83  using OperateSig = typename BuildFunType<void, Args>::Sig;
84  using CaptureSig = typename BuildFunType<MEM, Args>::Sig;
85  using UndoOp_Sig = typename BuildFunType<void, ExtendedArgs>::Sig;
86  using CmdArgs = Args;
87  using Memento = MEM;
88  };
89 
90 
91 
92 
107  template<typename SIG>
109  {
110  // preparation: dissect the function signature into arguments and result
111  using Args = typename _Fun<SIG>::Args;
112  using Ret = typename _Fun<SIG>::Ret;
113 
115  template<typename RET, typename ARG>
116  struct Case
117  {
118  using Memento = RET;
119 
120  using ExtendedArglist = typename Append<ARG, Memento>::List;
121  using ExtendedArgs = typename Types<ExtendedArglist>::Seq;
122 
123  using OperateSig = typename BuildFunType<void, ARG>::Sig;
124  using CaptureSig = typename BuildFunType<Ret,ARG>::Sig;
125  using UndoOp_Sig = typename BuildFunType<void, ExtendedArgs>::Sig;
126  };
128  template<typename ARG>
129  struct Case<void,ARG>
130  {
131  using Args = typename ARG::List;
132 
133  using Memento = typename SplitLast<Args>::Type;
134  using OperationArglist = typename SplitLast<Args>::List;
135  using OperationArgs = typename Types<OperationArglist>::Seq;
136 
137  using OperateSig = typename BuildFunType<void, OperationArgs>::Sig;
138  using CaptureSig = typename BuildFunType<Ret,OperationArgs>::Sig;
139  using UndoOp_Sig = typename BuildFunType<void, ARG>::Sig;
140  };
141 
142  public:
143  using CaptureSig = typename Case<Ret,Args>::CaptureSig;
144  using UndoOp_Sig = typename Case<Ret,Args>::UndoOp_Sig;
145  using OperateSig = typename Case<Ret,Args>::OperateSig;
146  using Memento = typename Case<Ret,Args>::Memento;
147  };
148 
149 
150 
151 }} // namespace steam::control
152 #endif
Build function types from given Argument types.
Definition: function.hpp:341
A template metaprogramming technique for manipulating collections of types.
Helper for uniform access to function signature types.
Definition: function.hpp:99
Some basic facilities for manipulating type sequences.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:62
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:104
Metaprogramming helper for building Command function signatures.
Type analysis helper template.
Metaprogramming: Helpers for manipulating lists-of-types.