1#ifndef _DRAMA2_DEBUGFUTURE_INC
2#define _DRAMA2_DEBUGFUTURE_INC
27 extern bool _futureDebugGlobalLogDetails;
73 class Future :
public std::future<T> {
74 using BaseFuture=std::future<T>;
78 bool _logDetails =
false;
95 _futureDebugGlobalLogDetails =
true;
115 _futureDebugGlobalLogDetails =
false;
126 return _futureDebugGlobalLogDetails;
156 Future(
const std::string &name=
"unnamed",
159 _type =
typeid(
a).name();
166 Future(
const Future&) =
delete;
175 *
this = std::move(
rhs);
192 *((BaseFuture *)(
this)) = std::move(
rhs);
193 if ((_logDetails)||( _futureDebugGlobalLogDetails))
195 std::cerr << fmt::format(
"drama::Future<{0}> \"{1}\" assigned",
196 _type, _name) << std::endl;
220 if ((_logDetails)||( _futureDebugGlobalLogDetails))
222 std::cerr << fmt::format(
"drama::Future<{0}> \"{1}\" get() invoked",
223 _type, _name) << std::endl;
236 if ((_logDetails)||( _futureDebugGlobalLogDetails))
238 std::cerr << fmt::format(
"drama::Future<{0}> \"{1}\" get() threw",
239 _type, _name) << std::endl;
246 if ((_logDetails)||( _futureDebugGlobalLogDetails))
248 std::cerr << fmt::format(
"drama::Future<{0}> \"{1}\" get() returning",
249 _type, _name) << std::endl;
269 if ((_logDetails)||( _futureDebugGlobalLogDetails))
271 std::cerr << fmt::format(
"drama::Future<{0}> \"{1}\" destroyed",
272 _type, _name) << std::endl;
318 class Future<
void> :
public std::future<void> {
319 using BaseFuture = std::future<void>;
322 bool _logDetails =
false;
339 _futureDebugGlobalLogDetails =
true;
359 _futureDebugGlobalLogDetails =
false;
370 return _futureDebugGlobalLogDetails;
405 Future(
const Future&) =
delete;
413 _name = std::move(
rhs._name);
414 _logDetails =
rhs._logDetails;
431 *((BaseFuture *)(
this)) = std::move(
rhs);
432 if ((_logDetails)||( _futureDebugGlobalLogDetails))
434 std::cerr << fmt::format(
"drama::Future<void> \"{0}\" assigned", _name) << std::endl;
440 Future&
operator=(
const Future &) =
delete;
456 if ((_logDetails)||( _futureDebugGlobalLogDetails))
458 std::cerr << fmt::format(
"drama::Future<void> \"{0}\" get() invoked", _name) << std::endl;
466 ((BaseFuture *)(
this))->
get();
470 if ((_logDetails)||( _futureDebugGlobalLogDetails))
472 std::cerr << fmt::format(
"drama::Future<void> \"{0}\" get() threw", _name) << std::endl;
479 if ((_logDetails)||( _futureDebugGlobalLogDetails))
481 std::cerr << fmt::format(
"drama::Future<void> \"{0}\" get() returning", _name) << std::endl;
499 if ((_logDetails)||( _futureDebugGlobalLogDetails))
503 std::cerr << fmt::format(
"drama::Future<void> \"{0}\" destroyed - but is still valid (which could be a problem)!!", _name) << std::endl;
507 std::cerr << fmt::format(
"drama::Future<void> \"%\" destroyed - was not valid (which is ok).", _name) << std::endl;
void get()
Get value of future.
Definition debugfuture.hh:482
static void GlobalLogOff()
Turn logging off - global.
Definition debugfuture.hh:385
static bool GetGlobalLogState()
Return the state of the global logging flag.
Definition debugfuture.hh:396
Future & operator=(const Future &)=delete
Assignment operator (non-move) - deleted.
void LogOn()
Turn logging on.
Definition debugfuture.hh:357
Future(const Future &)=delete
Copy constructor = deleted.
void LogOff()
Turn logging off.
Definition debugfuture.hh:374
void SetName(const std::string &newName)
Set the name of this object - as used in logging messages.
Definition debugfuture.hh:413
static void GlobalLogOn()
Turn logging on - global.
Definition debugfuture.hh:365
Future(const std::string &name="unnamed", bool logOn=false) noexcept
Construct a drama::Future<void> object.
Definition debugfuture.hh:427
~Future()
Destructor.
Definition debugfuture.hh:525
Future & operator=(Future &&rhs) noexcept
Move assignment operator.
Definition debugfuture.hh:439
Future & operator=(BaseFuture &&rhs) noexcept
Move assignment operator - source std::future<void>
Definition debugfuture.hh:457
bool GetLogState() const
Return the state of the object specific logging flag.
Definition debugfuture.hh:406
Future(const std::string &name="unnamed", bool logOn=false) noexcept
Construct a drama::Future object.
Definition debugfuture.hh:183
void LogOff()
Turn logging off.
Definition debugfuture.hh:130
static void GlobalLogOff()
Turn logging off - global.
Definition debugfuture.hh:141
T get()
Get value of future.
Definition debugfuture.hh:246
bool GetLogState() const
Return the state of the object specific logging flag.
Definition debugfuture.hh:162
Future & operator=(BaseFuture &&rhs) noexcept
Move assignment operator - source std::future<T>
Definition debugfuture.hh:218
static bool GetGlobalLogState()
Return the state of the global logging flag.
Definition debugfuture.hh:152
static void GlobalLogOn()
Turn logging on - global.
Definition debugfuture.hh:121
void LogOn()
Turn logging on.
Definition debugfuture.hh:113
~Future()
Destructor.
Definition debugfuture.hh:295
Future & operator=(Future &&rhs) noexcept
Move assignment operator.
Definition debugfuture.hh:201
Future & operator=(const Future &)=delete
Assignment operator (non-move) - deleted.
Future(const Future &)=delete
Copy constructor = deleted.
void SetName(const std::string &newName)
Set the name of this object - as used in logging messages.
Definition debugfuture.hh:169
A class which wraps a std::future<T> and provides debugging output to stderr.
Definition debugfuture.hh:100
DRAMA 2 main include file.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1339
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:99