AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
drama.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_INC
2#define _DRAMA2_INC
3
14/*
15 * History:
16 07-Jan-2014 - TJF - Original version
17 30-Sep-2016 - TJF - Add TSafePrintf() function.
18
19 */
20
21
22#define DRAMA_ALLOW_CPP_STDLIB // For old include files.
23#define DRAMA2_FMT 202609L // DRAMA Formatting support version.
24
25#if defined __clang__
26/*
27 * What versions do we need - unclear 5 maybe?
28 */
29
30#elif defined(__GNUC__) || defined(GNUC)
31
32/*
33 * Check for a valid version of GCC. We need 4.7 or higher.
34 * for GCC C++ Version 2011 support.
35 */
36# if __GNUC__ < 4
37
38# error "GCC Version too old. drama.hh needs GCC 4.7 or newer"
39
40# elif __GNUC__ == 4
41# if __GNUC_MINOR__ < 7
42# error "GCC Version too old. drama.hh needs GCC 4.7 or newer"
43# endif
44
45# endif /* __GNUC__ == 4 */
46
47#endif /* __GNUC__ */
48
49#include <string>
50#include <algorithm>
51#include <tuple>
52#include "DitsFix.h"
53#include "drama.h"
54#include "status.h"
55#include "Ers.h"
56#include "drama2_err.h"
57/* If we include fmt/format.h whilst processing this file with doxygen, then
58 * the macro RUNNING_DOXYGEN seems to disappear OR the C pre-processor
59 * code of doxygen fails (likely the later due to a claimed failure to close
60 * a quoted string, which is not true)
61 */
62#ifndef RUNNING_DOXYGEN
63#include "drama/fmt/format.h"
64#endif
65#include <string>
66#include <algorithm>
67#include <tuple>
68//#include <strstream>
72namespace drama {
73
76 extern const char * Drama2Version;
77
80 extern const char * Drama2Date;
81
94 extern void ErsReport(const std::string &mes, StatusType *status);
95
113 template<typename... Args>
114 void ErsReportF(StatusType *status, const fmt::format_string<Args...> fmt, Args&&... args) {
115 ErsReport(fmt::vformat(fmt.get(), fmt::make_format_args(args...)), status);
116 }
117
118
119
131 extern void ErsFlushStack(StatusType *status);
132
143 extern void ErsAnnulStack(StatusType *status);
144
155 class ErsContext {
156 public:
160 ErsContext() {
161 ErsPush();
162 }
165 ~ErsContext() {
166 ErsPop();
167 }
168 };
169
181 extern std::string GetSymbolVal(const std::string &name);
188 extern bool GetSymbolExists(const std::string &name);
189
207 /* To understand the way this works, think of an array
208 declared as say "int a[5]". When the template
209 is invoked, it uses 5 in place of S, so we can
210 just return S
211 */
212 template <typename T,unsigned S>
213 inline unsigned ArraySize(const T (&v)[S]) {
214 // Whilst we don't really use v, we must not comment it out, otherwise doxygen complains.
215 // This is a workaround. But it is really meant for tuples, so unclear if will always work.
216 std::ignore = v;
217 return S;
218 }
219
220
238 /* Invokes the drama::CheckLockTaken static method */
239 extern void CheckLockTaken(const std::string func,
240 const std::string &file,
241 const int lineNum) ;
242
243
244
245} // namespace drama
246
247
248#include "drama/util.hh"
249#include "drama/exception.hh"
250
251namespace drama {
252 /*
253 * Somewhat annoyingly, these need to be after we have included
254 * exception.hh, rather then within util.hh where they really
255 * belong. (as they use DramaTHROW()).
256 */
257
272 void SafePrintf( std::ostream &ostream, const char *str);
299 template<typename T, typename... Types>
300#ifndef RUNNING_DOXYGEN
301 D2_FMT_DEPRECATED("Replace use of SafePrintf by fmt::format")
302#endif
303 void SafePrintf( std::ostream &ostream,
304 const char * format,
305 const T &value,
306 Types... args) {
307 while (*format)
308 {
309 if (*format == '%')
310 {
311 if (*(format + 1) == '%')
312 {
313 ++format;
314 }
315 else
316 {
317 ostream << value;
318 // call even when *s == 0 to detect extra arguments
319 SafePrintf(ostream, format + 1, args...);
320 return;
321 }
322 }
323 ostream << *format++;
324 }
325 DramaTHROW(DRAMA2__INV_SAFE_PRINTF, "extra arguments provided to drama::SafePrintf()");
326 }
327
351 template<typename... Types>
352#ifndef RUNNING_DOXYGEN
353 D2_FMT_DEPRECATED("Replace TSafePrintf() by fmt::format")
354#endif
355 void TSafePrintf( std::ostream &ostream,
356 const char * format,
357 Types... args) {
358
359 /*
360 * Our approach is to write the output to a string, via
361 * SafePrintf(), then output that in one operation. Since
362 * std::ostream devices will then do the output in one operation.
363 */
364 std::stringstream sstrm;
366 ostream << sstrm.str();
367
368 }
369
370 /* This is after including exception.hh only because it use SafePrintf()*/
394 template<typename... Types>
395#ifndef RUNNING_DOXYGEN
396 D2_FMT_DEPRECATED("Replace ErsReport() by ErsReportF()")
397#endif
398 void ErsReport(StatusType *status, const char *format, Types... args) {
399 /*
400 * Our approach is to write the output to a string, via
401 * SafePrintf(), then output that in one operation. Since
402 * std::ostream devices will then do the output in one operation.
403 */
404 std::stringstream sstrm;
406 ErsReport(sstrm.str(), status);
407
408 }
409
410
411} // namespace drama
412
413
414#include "drama/task.hh"
415#include "drama/logger.hh"
416#include "drama/request.hh"
418#include "drama/threadaction.hh"
419#include "drama/threaduface.hh"
420#include "drama/path.hh"
421#include "drama/threadmonitor.hh"
422#include "drama/parameter.hh"
423#include "drama/sds.hh"
424#include "drama/parsys.hh"
426
427
428
429
430#endif
ErsContext()
Create an ErsContext object, increasing the Ers context.
Definition drama.hh:187
~ErsContext()
Destroy an ErsContext object, decrementing the Ers context.
Definition drama.hh:192
A Class used to manage ERS context.
Definition drama.hh:182
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:90
DRAMA 2 Exception classes.
DRAMA 2 include file - GIT ARG implementation.
Header file for a DRAMA 2 class which implements Logging.
DRAMA 2 include file - Message Handler class definition.
void TSafePrintf(std::ostream &ostream, const char *format, Types... args)
Safe formatted write to a stream, thread compatible.
Definition drama.hh:382
const char * Drama2Version
The DRAMA 2 ACMM Release version string.
std::string GetSymbolVal(const std::string &name)
Return the value of an environment variable.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1339
void ErsReport(const std::string &mes, StatusType *status)
Report a std::string via ERS.
unsigned ArraySize(const T(&v)[S])
Return the number of elements in an array.
Definition drama.hh:240
bool GetSymbolExists(const std::string &name)
Return true if an environment variable is set.
void ErsAnnulStack(StatusType *status)
Annul the ERS stack of messages.
void SafePrintf(std::ostream &ostream, const char *str)
Safe formatted write to a stream.
void CheckLockTaken(const std::string func, const std::string &file, const int lineNum)
Ensure the current thread has taken the DRAMA task lock.
void ErsFlushStack(StatusType *status)
Report a std::string via ERS.
const char * Drama2Date
The DRAMA 2 build date.
void ErsReportF(StatusType *status, const fmt::format_string< Args... > fmt, Args &&... args)
Report a std::string via ERS, format using fmt::format.
Definition drama.hh:141
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:99
DRAMA 2 include file - Parameter class definition.
DITS parameter system include file - DRAMA 2 interface.
DRAMA 2 include file.
DRAMA 2 include file - Request class definition.
DRAMA 2 include file - Sds class definition.
DRAMA 2 include file - Task class definition.
DRAMA 2 include file - Threaded Action class definition.
DRAMA 2 include file - Threaded monitoring classes.
DRAMA 2 include file - Threaded UFACE class definition.
DRAMA 2 include file - Utility macros, types etc.