KASKADE 7 development version
get.hh
Go to the documentation of this file.
1#ifndef GET_FROM_TYPE_OR_FUNCTOR_HH_
2#define GET_FROM_TYPE_OR_FUNCTOR_HH_
3
5
6// forward declaration
7namespace Dune
8{
9 template <class,int,int> class FieldMatrix;
10}
11
12namespace Kaskade
13{
15
21 template <class Type, class Source=Type> struct Get;
22
23 template <class Type, class Source>
24 struct Get{
25 Get(){ source_ = nullptr; }
26 explicit Get(Source const& source) : source_(&source){}
27 Get(Get const& get) : source_(get.source_){}
28
29 Get& operator=(Get const& get){ source_ = get.source_; return *this; }
30
31 Type operator()() const
32 {
33 if(source_ != nullptr) return (*source_)();
34 else throw DetailedException(std::string("Source has not been initialized!"),__FILE__,__LINE__);
35 }
36
37 private:
38 Source const* source_;
39 };
40
41 template <class Type>
42 struct Get<Type,Type>{
43 Get(){ type_ = nullptr; }
44 explicit Get(Type const& type) : type_(&type){}
45 Get(Get const& get) : type_(get.type_){}
46
47 Get& operator=(Get const& get){ type_ = get.type_; return *this; }
48
49 Type const& operator()() const
50 {
51 if(type_ != nullptr) return *type_;
52 else throw DetailedException(std::string("Type has not been initialized!"),__FILE__,__LINE__);
53 }
54
55 private:
56 Type const* type_;
57 };
58
59 template <class Scalar, int dim, class Type>
60 struct GetSubType{
61 typedef typename Type::SubType type;
62 };
63
64 template <class Scalar, int dim>
65 struct GetSubType<Scalar,dim,Dune::FieldMatrix<Scalar,dim,dim> >{
66 typedef Dune::FieldMatrix<Scalar,dim-1,dim-1> type;
67 };
68
69} // end of namespace Kaskade
70
71#endif
A wrapper class for conveniently providing exceptions with context information.
Get & operator=(Get const &get)
Definition: get.hh:47
Type const & operator()() const
Definition: get.hh:49
Get(Get const &get)
Definition: get.hh:45
Get(Type const &type)
Definition: get.hh:44
Get object from reference or functor. Is itself a functor.
Definition: get.hh:24
Type operator()() const
Definition: get.hh:31
Get & operator=(Get const &get)
Definition: get.hh:29
Get(Source const &source)
Definition: get.hh:26
Get(Get const &get)
Definition: get.hh:27
Type::SubType type
Definition: get.hh:61