MyraMath
JobGraph.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_JOBGRAPH_JOBGRAPH_H
7 #define MYRAMATH_JOBGRAPH_JOBGRAPH_H
8 
14 #include <myramath/utility/detail/LIBPUBLIC.h>
16 
18 
19 #include <string>
20 #include <stdint.h>
21 
22 namespace myra {
23 
24 // Forward declarations.
25 class Job;
26 class JobGraphBase;
27 class JobGraph;
28 
30 class LIBPUBLIC JobGraphBase
31  {
32  public:
33 
35  virtual JobGraphBase* clone() const = 0;
36 
38  virtual uint64_t n_work() const { return 0; }
39 
41  virtual std::string name() const { return "JobGraph"; }
42 
44  virtual void begins(JobIDs& output) const { throw eprintf("JobGraphBase::begins(JobIDs&) not implemented for %s", this->name().c_str()); }
45 
47  virtual void ends(JobIDs& output) const { throw eprintf("JobGraphBase::ends(JobIDs&) not implemented for %s", this->name().c_str()); }
48 
50  virtual Job* create(JobID j) { throw eprintf("JobGraphBase::create(JobID) not implemented for %s", this->name().c_str()); }
51 
53  virtual std::vector<Job*> create(); // TODO make pure virtual
54 
56  virtual uint64_t size() const { throw eprintf("JobGraphBase::size() not implemented for %s", this->name().c_str()); } // TODO remove
57 
59  virtual ~JobGraphBase();
60 
61  };
62 
64 class LIBPUBLIC JobGraph
65  {
66  public:
67 
68  // -------- Structural routines (ctor,copy,etc) --------------
69 
71  JobGraph();
72 
74  /*explicit*/ JobGraph(const JobGraphBase& that);
75 
77  JobGraph(const JobGraph& that);
78 
80  void swap(JobGraph& that);
81 
83  JobGraph& operator =(JobGraph that);
84 
86  ~JobGraph();
87 
88  // ------ Job presentation API for consumers (execute, traverse, graphviz, etc) --------
89 
91  uint64_t n_work() const;
92 
94  std::string name() const;
95 
97  void begins(JobIDs& output) const;
98 
100  void ends(JobIDs& output) const;
101 
103  Job* create(JobID j) const;
104 
106  std::vector<Job*> create() const;
107 
109  uint64_t size() const;
110 
111  private:
112 
113  // Underlying polymorphic instance, a JobGraphBase.
114  JobGraphBase* base;
115 
116  };
117 
118 } // namespace myra
119 
120 #endif
Abstraction to represent one node of a JobGraph.
Definition: Job.h:25
virtual uint64_t n_work() const
Total "work" over all Job&#39;s of this JobGraph.
Definition: JobGraph.h:38
virtual uint64_t size() const
Returns maximum JobID.
Definition: JobGraph.h:56
Returns a std::runtime_error() whose message has been populated using printf()-style formatting...
virtual std::string name() const
Returns a printable name for this JobGraph, for debugging.
Definition: JobGraph.h:41
virtual Job * create(JobID j)
Constructs the Job corresponding to the given JobID.
Definition: JobGraph.h:50
virtual void begins(JobIDs &output) const
Enumerates the JobIDs of Job&#39;s that have no parents (where execution begins)
Definition: JobGraph.h:44
virtual void ends(JobIDs &output) const
Enumerates the JobIDs of Job&#39;s that have no children (where execution ends)
Definition: JobGraph.h:47
Type erasure class that wraps JobGraphBase, gives it value semantics.
Definition: JobGraph.h:64
Definition: syntax.dox:1
Base/contract class for all other JobGraph&#39;s.
Definition: JobGraph.h:30
Key type used to identify the Job&#39;s of a JobGraph.
Key type used to identify the Job&#39;s of a JobGraph.
Definition: JobID.h:60
std::vector< JobID > JobIDs
Useful typedef.
Definition: JobID.h:118