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
18/*
19 * History:
20 07-Jan-2014 - TJF - Original version
21 30-Sep-2016 - TJF - Add TSafePrintf() function.
22
23 * The above ID is for Doxygen, this one has the format ACMM is looking for.
24 * "@(#) $Id$"
25 */
26
27
28#define DRAMA_ALLOW_CPP_STDLIB // For old include files.
29
30#if defined __clang__
31/*
32 * What versions do we need - unclear 5 maybe?
33 */
34
35#elif defined(__GNUC__) || defined(GNUC)
36
37/*
38 * Check for a valid version of GCC. We need 4.7 or higher.
39 * for GCC C++ Version 2011 support.
40 */
41# if __GNUC__ < 4
42
43# error "GCC Version too old. drama.hh needs GCC 4.7 or newer"
44
45# elif __GNUC__ == 4
46# if __GNUC_MINOR__ < 7
47# error "GCC Version too old. drama.hh needs GCC 4.7 or newer"
48# endif
49
50# endif /* __GNUC__ == 4 */
51
52#endif /* __GNUC__ */
53
54
55#include "drama.h"
56#include "status.h"
57#include "Ers.h"
58#include "drama2_err.h"
59#include <string>
60#include <algorithm>
61#include <tuple>
62//#include <strstream>
66namespace drama {
67
70 extern const char * Drama2Version;
71
74 extern const char * Drama2Date;
75
86 extern void ErsReport(const std::string &mes, StatusType *status);
87
88
89
90
102 extern void ErsFlushStack(StatusType *status);
103
114 extern void ErsAnnulStack(StatusType *status);
115
116
117
118
130 public:
134 ErsContext() {
135 ErsPush();
136 }
139 ~ErsContext() {
140 ErsPop();
142 };
143
155 extern std::string GetSymbolVal(const std::string &name);
162 extern bool GetSymbolExists(const std::string &name);
163
181 /* To understand the way this works, think of an array
182 declared as say "int a[5]". When the template
183 is invoked, it uses 5 in place of S, so we can
184 just return S
185 */
186 template <typename T,unsigned S>
187 inline unsigned ArraySize(const T (&v)[S]) {
188 // Whilst we don't really use v, we must not comment it out, otherwise doxygen complains.
189 // This is a workaround. But it is really meant for tuples, so unclear if will always work.
190 std::ignore = v;
191 return S;
192 }
193
194
212 /* Invokes the drama::CheckLockTaken static method */
213 extern void CheckLockTaken(const std::string func,
214 const std::string &file,
215 const int lineNum) ;
216
217
218
219} // namespace drama
220
221
222#include "drama/util.hh"
223#include "drama/exception.hh"
224
225namespace drama {
226 /*
227 * Somewhat annoyingly, these need to be after we have included
228 * exception.hh, rather then within util.hh where they really
229 * belong. (Since they use DramaTHROW()).
230 */
231
237 void SafePrintf( std::ostream &ostream, const char *str);
238
258 template<typename T, typename... Types>
259 void SafePrintf( std::ostream &ostream,
260 const char * format,
261 const T &value,
262 Types... args) {
263 while (*format)
265 if (*format == '%')
266 {
267 if (*(format + 1) == '%')
268 {
269 ++format;
270 }
271 else
272 {
273 ostream << value;
274 // call even when *s == 0 to detect extra arguments
275 SafePrintf(ostream, format + 1, args...);
276 return;
277 }
278 }
279 ostream << *format++;
280 }
281 DramaTHROW(DRAMA2__INV_SAFE_PRINTF, "extra arguments provided to drama::SafePrintf()");
282 }
283
301 template<typename... Types>
302 void TSafePrintf( std::ostream &ostream,
303 const char * format,
304 Types... args) {
305
306 /*
307 * Our approach is to write the output to a string, via
308 * SafePrintf(), then output that in one operation. Since
309 * std::ostream devices will then do the output in one operation.
310 */
311 std::stringstream sstrm;
313 ostream << sstrm.str();
314
315 }
316
317 /* This is after including exception.hh only because it use SafePrintf()*/
338 template<typename... Types>
339 void ErsReport(StatusType *status, const char *format, Types... args) {
340
341 /*
342 * Our approach is to write the output to a string, via
343 * SafePrintf(), then output that in one operation. Since
344 * std::ostream devices will then do the output in one operation.
345 */
346 std::stringstream sstrm;
348 ErsReport(sstrm.str(), status);
349
350 }
351
352
353
354} // namespace drama
355
356
357#include "drama/task.hh"
358#include "drama/logger.hh"
359#include "drama/request.hh"
361#include "drama/threadaction.hh"
362#include "drama/threaduface.hh"
363#include "drama/path.hh"
364#include "drama/threadmonitor.hh"
365#include "drama/parameter.hh"
366#include "drama/sds.hh"
367#include "drama/parsys.hh"
368#include "drama/gitarg.hh"
369
370
371
372
373#endif
ErsContext()
Create an ErsContext object, increasing the Ers context.
Definition drama.hh:161
~ErsContext()
Destroy an ErsContext object, decrementing the Ers context.
Definition drama.hh:166
A Class used to manage ERS context.
Definition drama.hh:156
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:93
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 formated write to a stream, thread compatible.
Definition drama.hh:329
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:1322
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:214
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.
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
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.