Program listing for file kernel/src/utils/SiconosTools/Question.hpp#

 1#ifndef Question_hpp
 2#define Question_hpp
 3
 4#include "SiconosVisitor.hpp"
 5
 6#include <SiconosConfig.h>
 7#include <type_traits>
 8#include <array>
 9
10
11template <class AnswerType>
12struct Question : public SiconosVisitor
13{
14  typedef AnswerType type;
15  type answer;
16
17  Question() : answer(std::array<typename std::remove_reference<AnswerType>::type, 1>()[0])
18  {};
19  Question(AnswerType ref) : answer(ref) {};
20
21};
22
23
24
25template <class GeneralQuestion, class Visitable>
26typename GeneralQuestion::type ask(const Visitable& v)
27{
28  GeneralQuestion t;
29
30  v.accept(t);
31
32  return t.answer;
33
34}
35
36
37template <class GeneralQuestion, class Visitable, class Argument>
38typename GeneralQuestion::type ask(const Visitable& v, const Argument& arg)
39{
40  GeneralQuestion t(arg);
41
42  v.accept(t);
43
44  return t.answer;
45
46}
47
48
49template <class Visitor, class Visitable>
50void apply(const Visitable& v)
51{
52  static Visitor t;
53
54  v.accept(t);
55
56}
57
58
59template <class VisitorWithArgument, class Visitable, class Argument>
60void apply(const Visitable& v, const Argument& arg)
61{
62  VisitorWithArgument t(arg);
63
64  v.accept(t);
65
66}
67
68
69template <class VisitorWith2Arguments, class Visitable, class Argument1, class Argument2>
70void apply(const Visitable& v, const Argument1& arg1, const Argument2& arg2)
71{
72  VisitorWith2Arguments t(arg1, arg2);
73
74  v.accept(t);
75
76}
77
78#endif