Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
special-job-fun.hpp
Go to the documentation of this file.
1/*
2 SPECIAL-JOB-FUN.hpp - a one-time render job to do something special
3
4 Copyright (C)
5 2023, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
37#ifndef VAULT_GEAR_SPECIAL_JOB_FUN_H
38#define VAULT_GEAR_SPECIAL_JOB_FUN_H
39
40
41
42#include "lib/handle.hpp"
45#include "lib/format-string.hpp"
46#include "lib/format-obj.hpp"
47#include "lib/meta/util.hpp"
48
49#include <string>
50#include <memory>
51#include <utility>
52
53
54namespace vault{
55namespace gear {
56 namespace err = lumiera::error;
57
58 using util::_Fmt;
60 using std::move;
61 using std::forward;
62 using std::make_shared;
63
64
69 : public NopJobFunctor
70 {
71 public:
72 virtual uint remainingInvocations() const =0;
73 };
74
75
76
77
82 : protected lib::Handle<SpecialFunPrototype>
83 {
85
86 template<class FUN>
89 {
90 FUN fun_;
93
94 public:
95 explicit
96 SpecialExecutor (FUN theFun)
97 : fun_{move (theFun)}
98 , selfHook_(this)
99 { }
100
103 friend _Handle&
105 {
106 REQUIRE (instance->selfHook_);
107 REQUIRE (instance->remainingInvocations());
108 // expose the self-managing handle
109 return instance->selfHook_;
110 }
111
112
113 uint
115 {
116 return lives_;
117 }
118
119
120 /* === JobFunctor Interface === */
121
122 void
124 {
125 if (not remainingInvocations())
126 throw err::Logic{"invoking deceased SpecialJobFun"
127 ,err::LUMIERA_ERROR_LIFECYCLE};
128 fun_(param);
129
130 if (not --lives_)
132 } // Suicide.
133
134 std::string
135 diagnostic() const override
136 {
137 return _Fmt{"SpecialJob(%d)-%s"}
138 % lives_
139 % util::showHash(size_t(this), 2);
140 }
141 };
142
143
144
145 public:
146 SpecialJobFun() = default;
147
158 template<class FUN, typename =disable_if_self<SpecialJobFun, FUN>>
159 explicit
160 SpecialJobFun (FUN&& someFun)
161 : _Handle{selfAttached (new SpecialExecutor(forward<FUN> (someFun)))}
162 { }
163
164 // standard copy operations acceptable
165
166 explicit
167 operator bool() const
168 {
169 return 0 < remainingInvocations();
170 }
171
172 operator JobClosure&() const
173 {
174 REQUIRE (operator bool());
175 return _Handle::impl();
176 }
177
178 uint
180 {
181 return _Handle::isValid()? _Handle::impl().remainingInvocations()
182 : 0;
183 }
184
185 long
186 use_count() const
187 {
188 return _Handle::smPtr_.use_count();
189 }
190 };
191
192
193}} // namespace vault::gear
194#endif /*VAULT_GEAR_SPECIAL_JOB_FUN_H*/
Generic opaque reference counting handle, for accessing a service and managing its lifecycle.
Definition handle.hpp:64
void close()
deactivate this handle, so it isn't tied any longer to the associated implementation or service objec...
Definition handle.hpp:140
SpecialFunPrototype & impl() const
Definition handle.hpp:149
A front-end for using printf-style formatting.
Interface of the closure for frame rendering jobs.
Definition job.h:244
Stub/Test implementation of the JobFunctor interface for a render job to do nothing at all
Interface: JobFunctor configured to invoke a function a limited number of times.
virtual uint remainingInvocations() const =0
friend _Handle & selfAttached(SpecialExecutor *instance)
void invokeJobOperation(JobParameter param) override
Front-end to configure a special job functor for one-time use.
SpecialJobFun(FUN &&someFun)
Establish a new SpecialJobFun variation directly by wrapping a given functor.
Simple functions to represent objects, for debugging and diagnostics.
Front-end for printf-style string template interpolation.
A generic opaque handle to an implementation entity, including lifecycle management.
unsigned int uint
Definition integral.hpp:29
Simple and lightweight helpers for metaprogramming and type detection.
disable_if< std::is_same< std::remove_cv_t< std::remove_reference_t< extractFirst_t< ARGS... > > >, SELF > > disable_if_self
helper to prevent a template constructor from shadowing inherited copy ctors
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
string showHash(size_t hash, uint showBytes) noexcept
renders the size_t in hex, optionally only trailing bytes
lumiera_jobParameter const & JobParameter
Definition job.h:205
Vault-Layer implementation namespace root.
Generic implementation of a JobFunctor to perform no calculations.
a family of time value like entities and their relationships.