1#ifndef _DRAMA2_DEBUGFUTURE_INC
2#define _DRAMA2_DEBUGFUTURE_INC
36 extern bool _futureDebugGlobalLogDetails;
82 class Future :
public std::future<T> {
83 using BaseFuture=std::future<T>;
87 bool _logDetails =
false;
104 _futureDebugGlobalLogDetails =
true;
124 _futureDebugGlobalLogDetails =
false;
135 return _futureDebugGlobalLogDetails;
165 Future(
const std::string &name=
"unnamed",
168 _type =
typeid(
a).name();
175 Future(
const Future&) =
delete;
184 *
this = std::move(
rhs);
201 *((BaseFuture *)(
this)) = std::move(
rhs);
202 if ((_logDetails)||( _futureDebugGlobalLogDetails))
227 if ((_logDetails)||( _futureDebugGlobalLogDetails))
229 "drama::Future<%> \"%\" get() invoked\n",
242 if ((_logDetails)||( _futureDebugGlobalLogDetails))
244 "drama::Future<%> \"%\" get() threw\n",
251 if ((_logDetails)||( _futureDebugGlobalLogDetails))
253 "drama::Future<%> \"%\" get() returning\n",
273 if ((_logDetails)||( _futureDebugGlobalLogDetails))
275 "drama::Future<%> \"%\" destroyed\n",
321 class Future<
void> :
public std::future<void> {
322 using BaseFuture = std::future<void>;
325 bool _logDetails =
false;
342 _futureDebugGlobalLogDetails =
true;
362 _futureDebugGlobalLogDetails =
false;
373 return _futureDebugGlobalLogDetails;
408 Future(
const Future&) =
delete;
416 _name = std::move(
rhs._name);
417 _logDetails =
rhs._logDetails;
434 *((BaseFuture *)(
this)) = std::move(
rhs);
435 if ((_logDetails)||( _futureDebugGlobalLogDetails))
457 if ((_logDetails)||( _futureDebugGlobalLogDetails))
465 ((BaseFuture *)(
this))->
get();
469 if ((_logDetails)||( _futureDebugGlobalLogDetails))
476 if ((_logDetails)||( _futureDebugGlobalLogDetails))
494 if ((_logDetails)||( _futureDebugGlobalLogDetails))
497 drama::TSafePrintf(std::cerr,
"drama::Future<void> \"%\" destroyed - but is still valid (which could be a problem)!!\n", _name);
499 drama::TSafePrintf(std::cerr,
"drama::Future<void> \"%\" destroyed - was not valid (which is ok).\n", _name);
void get()
Get value of future.
Definition debugfuture.hh:483
static void GlobalLogOff()
Turn logging off - global.
Definition debugfuture.hh:388
static bool GetGlobalLogState()
Return the state of the global logging flag.
Definition debugfuture.hh:399
Future & operator=(const Future &)=delete
Assignment operator (non-move) - deleted.
void LogOn()
Turn logging on.
Definition debugfuture.hh:360
Future(const Future &)=delete
Copy constructor = deleted.
void LogOff()
Turn logging off.
Definition debugfuture.hh:377
void SetName(const std::string &newName)
Set the name of this object - as used in logging messages.
Definition debugfuture.hh:416
static void GlobalLogOn()
Turn logging on - global.
Definition debugfuture.hh:368
Future(const std::string &name="unnamed", bool logOn=false) noexcept
Construct a drama::Future<void> object.
Definition debugfuture.hh:430
~Future()
Destructor.
Definition debugfuture.hh:520
Future & operator=(Future &&rhs) noexcept
Move assignment operator.
Definition debugfuture.hh:442
Future & operator=(BaseFuture &&rhs) noexcept
Move assignment operator - source std::future<void>
Definition debugfuture.hh:460
bool GetLogState() const
Return the state of the object specific logging flag.
Definition debugfuture.hh:409
Future(const std::string &name="unnamed", bool logOn=false) noexcept
Construct a drama::Future object.
Definition debugfuture.hh:192
void LogOff()
Turn logging off.
Definition debugfuture.hh:139
static void GlobalLogOff()
Turn logging off - global.
Definition debugfuture.hh:150
T get()
Get value of future.
Definition debugfuture.hh:253
bool GetLogState() const
Return the state of the object specific logging flag.
Definition debugfuture.hh:171
Future & operator=(BaseFuture &&rhs) noexcept
Move assignment operator - source std::future<T>
Definition debugfuture.hh:227
static bool GetGlobalLogState()
Return the state of the global logging flag.
Definition debugfuture.hh:161
static void GlobalLogOn()
Turn logging on - global.
Definition debugfuture.hh:130
void LogOn()
Turn logging on.
Definition debugfuture.hh:122
~Future()
Destructor.
Definition debugfuture.hh:299
Future & operator=(Future &&rhs) noexcept
Move assignment operator.
Definition debugfuture.hh:210
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:178
A class which wraps a std::future<T> and provides debugging output to stderr.
Definition debugfuture.hh:109
DRAMA 2 main include file.
void TSafePrintf(std::ostream &ostream, const char *format, Types... args)
Safe formated write to a stream, thread compatible.
Definition drama.hh:329
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93