blitzdg
an open-source project aiming to implement parallel discontinuous Galerkin (dg) solvers for common partial differential equations systems using blitz++ for array and tensor manipulations and MPI for distributed parallelism.
contextrunner.h
1 
2 // Copyright Joakim Karlsson & Kim Gräsman 2010-2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef IGLOO_CONTEXTRUNNER_H
8 #define IGLOO_CONTEXTRUNNER_H
9 
10 namespace igloo {
11 
12 
14  {
15  BaseContextRunner(const std::string& contextName, const char* fileName, int lineNumber)
16  : contextName_(contextName), fileName_(fileName), lineNumber_(lineNumber) {}
17  virtual ~BaseContextRunner() {}
18  void Run(TestResults& results, TestListener& testListener) const
19  {
20  RunContext(results, testListener);
21  }
22 
23  virtual bool IsContextMarkedAsOnly() const = 0;
24 
25  virtual bool IsMarkedAsSkip() const = 0;
26 
27  const std::string& ContextName() const
28  {
29  return contextName_;
30  }
31 
32  const std::string& FileName() const
33  {
34  return fileName_;
35  }
36 
37  int LineNumber() const
38  {
39  return lineNumber_;
40  }
41 
42  protected:
43  virtual void RunContext(TestResults& results, TestListener& testListener) const = 0;
44 
45  private:
46  std::string contextName_;
47  std::string fileName_;
48  int lineNumber_;
49  };
50 
51  template <typename ContextRegistryType, typename ContextType>
53  {
54  typedef ContextRegistryType ContextToExecute;
55  typedef ContextType ContextToCreate;
56  };
57 
58  template <typename ContextType>
59  struct ContextSelector<void, ContextType>
60  {
61  typedef ContextType ContextToExecute;
62  typedef ContextType ContextToCreate;
63  };
64 
65  template <typename ContextRegistryType, typename ContextType>
67  {
68  public:
69  typedef typename ContextSelector<ContextRegistryType, ContextType>::ContextToExecute CTE;
70  typedef typename ContextSelector<ContextRegistryType, ContextType>::ContextToCreate CTC;
71 
72  ContextRunner(const std::string& contextName, const char* fileName, int lineNumber)
73  : BaseContextRunner(contextName, fileName, lineNumber) {}
74 
75  void InstantiateContext() const
76  {
77  CTC ctc;
78  }
79 
80  virtual bool IsContextMarkedAsOnly() const
81  {
82  return ContextType::IsContextMarkedAsOnly();
83  }
84 
85  virtual bool IsMarkedAsSkip() const
86  {
87  return ContextType::IsMarkedAsSkip();
88  }
89 
90  void RunContext(TestResults& results, TestListener& testListener) const
91  {
92  typedef ContextRegistry<CTE> CR;
93  CR::template Run<CTC>(ContextName(), results, testListener);
94  }
95  };
96 }
97 
98 #endif
Definition: testlistener.h:14
Definition: contextrunner.h:66
Definition: contextrunner.h:52
Definition: contextrunner.h:13
Definition: context.h:13
Definition: contextregistry.h:26
Definition: testresults.h:12