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#include <string>
55#include <algorithm>
56#include <tuple>
57#include "DitsFix.h"
58#include "drama.h"
59#include "status.h"
60#include "Ers.h"
61#include "drama2_err.h"
62
63//#include <strstream>
67namespace drama {
68
71 extern const char * Drama2Version;
72
75 extern const char * Drama2Date;
76
87 extern void ErsReport(const std::string &mes, StatusType *status);
88
89
90
91
103 extern void ErsFlushStack(StatusType *status);
104
115 extern void ErsAnnulStack(StatusType *status);
116
117
118
119
131 public:
135 ErsContext() {
136 ErsPush();
137 }
140 ~ErsContext() {
141 ErsPop();
143 };
144
156 extern std::string GetSymbolVal(const std::string &name);
163 extern bool GetSymbolExists(const std::string &name);
164
182 /* To understand the way this works, think of an array
183 declared as say "int a[5]". When the template
184 is invoked, it uses 5 in place of S, so we can
185 just return S
186 */
187 template <typename T,unsigned S>
188 inline unsigned ArraySize(const T (&v)[S]) {
189 // Whilst we don't really use v, we must not comment it out, otherwise doxygen complains.
190 // This is a workaround. But it is really meant for tuples, so unclear if will always work.
191 std::ignore = v;
192 return S;
193 }
194
195
213 /* Invokes the drama::CheckLockTaken static method */
214 extern void CheckLockTaken(const std::string func,
215 const std::string &file,
216 const int lineNum) ;
217
218
219
220} // namespace drama
221
222
223#include "drama/util.hh"
224#include "drama/exception.hh"
225
226namespace drama {
227 /*
228 * Somewhat annoyingly, these need to be after we have included
229 * exception.hh, rather then within util.hh where they really
230 * belong. (Since they use DramaTHROW()).
231 */
232
238 void SafePrintf( std::ostream &ostream, const char *str);
239
259 template<typename T, typename... Types>
260 void SafePrintf( std::ostream &ostream,
261 const char * format,
262 const T &value,
263 Types... args) {
264 while (*format)
266 if (*format == '%')
267 {
268 if (*(format + 1) == '%')
269 {
270 ++format;
271 }
272 else
273 {
274 ostream << value;
275 // call even when *s == 0 to detect extra arguments
276 SafePrintf(ostream, format + 1, args...);
277 return;
278 }
279 }
280 ostream << *format++;
281 }
282 DramaTHROW(DRAMA2__INV_SAFE_PRINTF, "extra arguments provided to drama::SafePrintf()");
283 }
284
302 template<typename... Types>
303 void TSafePrintf( std::ostream &ostream,
304 const char * format,
305 Types... args) {
306
307 /*
308 * Our approach is to write the output to a string, via
309 * SafePrintf(), then output that in one operation. Since
310 * std::ostream devices will then do the output in one operation.
311 */
312 std::stringstream sstrm;
314 ostream << sstrm.str();
315
316 }
317
318 /* This is after including exception.hh only because it use SafePrintf()*/
339 template<typename... Types>
340 void ErsReport(StatusType *status, const char *format, Types... args) {
341
342 /*
343 * Our approach is to write the output to a string, via
344 * SafePrintf(), then output that in one operation. Since
345 * std::ostream devices will then do the output in one operation.
346 */
347 std::stringstream sstrm;
349 ErsReport(sstrm.str(), status);
350
351 }
352
353
354
355} // namespace drama
356
357
358#include "drama/task.hh"
359#include "drama/logger.hh"
360#include "drama/request.hh"
362#include "drama/threadaction.hh"
363#include "drama/threaduface.hh"
364#include "drama/path.hh"
365#include "drama/threadmonitor.hh"
366#include "drama/parameter.hh"
367#include "drama/sds.hh"
368#include "drama/parsys.hh"
369#include "drama/gitarg.hh"
370
371
372
373
374#endif
ErsContext()
Create an ErsContext object, increasing the Ers context.
Definition drama.hh:162
~ErsContext()
Destroy an ErsContext object, decrementing the Ers context.
Definition drama.hh:167
A Class used to manage ERS context.
Definition drama.hh:157
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:87
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:330
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:1327
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:215
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:94
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.