MyraMath
DeleteJobGraph.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_DELETEJOBGRAPH_H
7 #define MYRAMATH_JOBGRAPH_DELETEJOBGRAPH_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
15 
16 #include <myramath/jobgraph/Job.h>
18 
19 #include <string>
20 #include <stdint.h>
21 
22 namespace myra {
23 
25 template<class Object> class DeleteJobGraph : public JobGraphBase
26  {
27  class DeleteJob;
28  Object* object;
29 
30  public:
31 
33  DeleteJobGraph(Object* in_object)
34  : object(in_object) { }
35 
37  virtual JobGraphBase* clone() const
38  { return new DeleteJobGraph<Object>(object); }
39 
41  virtual ~DeleteJobGraph()
42  { }
43 
44  // --------------------------- Base JobGraph overrides.
45 
47  virtual uint64_t n_work() const
48  { return 1; }
49 
51  virtual std::string name() const
52  { return "DeleteJobGraph"; }
53 
55  virtual void begins(JobIDs& output) const
56  { output.push_back(JobID(0)); }
57 
59  virtual void ends(JobIDs& output) const
60  { output.push_back(JobID(0)); }
61 
63  virtual ::myra::Job* create(JobID id)
64  { return new DeleteJob(this); }
65 
67  virtual std::vector<::myra::Job*> create()
68  { return std::vector<::myra::Job*>(1,new DeleteJob(this)); }
69 
71  virtual uint64_t size() const
72  { return 1; }
73 
74  private:
75 
76  // Implementation detail, calls the Lambda when execute()'d
77  class DeleteJob : public ::myra::Job
78  {
79  private:
80 
81  // Host graph.
82  DeleteJobGraph* host;
83 
84  public:
85 
86  // Constructor, requires underlying Job* j and host graph g.
87  DeleteJob(DeleteJobGraph* in_host)
88  : host(in_host) { }
89 
90  // Returns (0).
91  virtual JobID id() const
92  { return JobID(0); }
93 
94  // Empty set.
95  virtual void parents(JobIDs& output) const
96  { }
97 
98  // Empty set.
99  virtual void children(JobIDs& output) const
100  { }
101 
102  // Returns j->execute()
103  virtual uint64_t execute()
104  { delete host->object; return 1; }
105 
106  // Returns j->name()
107  virtual std::string name() const
108  { return "DeleteJob"; }
109 
110  // Deletes j.
111  virtual ~DeleteJob()
112  { }
113 
114  };
115 
116  };
117 
119 template<class Object>
121  { return JobGraph(DeleteJobGraph<Object>(object)); }
122 
123 } // namespace myra
124 
125 #endif
Encapsulates "delete object;" into a JobGraph of a single Job.
Definition: DeleteJobGraph.h:25
Abstraction to represent one node of a JobGraph.
Definition: Job.h:25
virtual void ends(JobIDs &output) const
Enumerates the JobIDs of Job&#39;s that have no children (where execution ends)
Definition: DeleteJobGraph.h:59
virtual std::vector<::myra::Job * > create()
Constructs all Job&#39;s in an implementation-defined order.
Definition: DeleteJobGraph.h:67
virtual uint64_t n_work() const
Total "work" over all Job&#39;s of this JobGraph.
Definition: DeleteJobGraph.h:47
Abstraction to represent one node of a JobGraph.
virtual ::myra::Job * create(JobID id)
Constructs the Job corresponding to the given JobIDs.
Definition: DeleteJobGraph.h:63
virtual ~DeleteJobGraph()
Frees internal resources.
Definition: DeleteJobGraph.h:41
virtual JobGraphBase * clone() const
Virtual copy constructor.
Definition: DeleteJobGraph.h:37
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
Abstraction for representing a directed acyclic graph of Job&#39;s.
JobGraph make_DeleteJobGraph(Object *object)
Given a heap allocated Object, returns a JobGraph that delete&#39;s it when execute()&#39;d.
Definition: DeleteJobGraph.h:120
DeleteJobGraph(Object *in_object)
Constructor, requires an Object to delete.
Definition: DeleteJobGraph.h:33
virtual uint64_t size() const
Returns maximum JobID.
Definition: DeleteJobGraph.h:71
virtual void begins(JobIDs &output) const
Enumerates the JobIDs of Job&#39;s that have no parents (where execution begins)
Definition: DeleteJobGraph.h:55
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
virtual std::string name() const
Returns a printable name for this JobGraph, for debugging.
Definition: DeleteJobGraph.h:51