Lumiera  0.pre.03
»edit your freedom«
argument-erasure.hpp
Go to the documentation of this file.
1 /*
2  ARGUMENT-ERASURE.hpp - helper for passing on a dynamic typed argument tuple
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 
31 #ifndef CONTROL_ARGUMENT_ERASURE_H
32 #define CONTROL_ARGUMENT_ERASURE_H
33 
34 #include "lib/error.hpp"
35 
36 
37 namespace lumiera {
38 namespace error {
39  LUMIERA_ERROR_DECLARE (INVALID_ARGUMENTS);
40  LUMIERA_ERROR_DECLARE (UNBOUND_ARGUMENTS);
41 }}
42 
43 namespace steam {
44 namespace control {
45  namespace err = lumiera::error;
46 
47 
58  struct Arguments;
59 
60  template<typename TUP>
62 
63 
64  struct Arguments
65  {
66  virtual ~Arguments() {}
67 
68  template<typename TUP>
69  TUP const&
70  get()
71  {
72  TypedArguments<TUP>* dest = dynamic_cast<TypedArguments<TUP>*> (this);
73  if (not dest)
74  throw err::Invalid{"Wrong type or number of arguments"
75  , LERR_(INVALID_ARGUMENTS)};
76  return dest->args_;
77  }
78  };
79 
80 
81  template<typename TUP>
82  struct TypedArguments
83  : Arguments
84  {
85  TUP const& args_;
86 
87  TypedArguments (TUP const& a)
88  : args_(a)
89  { }
90  };
91 
92 
93 
94 }} // namespace steam::control
95 #endif
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
Steam-Layer implementation namespace root.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Lumiera error handling (C++ interface).
Lumiera public interface.
Definition: advice.cpp:113