AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
gitarg.hh
Go to the documentation of this file.
1#ifndef DRAMA2_GITARG_INC
2#define DRAMA2_GITARG_INC
20/*
21 * History:
22 04-Jul-2014 - TJF - Original version
23 23-Mar-2018 - TJF - Ensure that in any case where we are throwing but might
24 have ERS reports, that we create the exception the
25 long way and add any ERS reports to the exception.
26
27 * The above ID is for Doxygen, this one has the format ACMM is looking for.
28 * "@(#) $Id$"
29 */
30
31#include "drama.hh"
32#include "drama/thread.hh"
33#include "drama/fmt/format.h"
34#include "Git.h"
35#include <string>
36#include <limits.h>
37#include <type_traits>
38namespace drama {
45 namespace gitarg {
46
57 enum class Flags {
58 NoFlagSet=0,
75 };
85 constexpr Flags operator|(Flags f1, Flags f2) {
86 return Flags(unsigned(f1)|unsigned(f2));
87 }
101 inline bool IsFlagSet(const Flags f1, const Flags f2) {
102 if ((unsigned int)(f1) & (unsigned int)(f2))
103 return true;
104 else
105 return false;
106 }
107
108 /*
109 * This method invokes the drama::Task static equivalent, but
110 * catches the exception and provides a more precise message.
111 */
112 inline void ___CheckLockTaken(
113 const std::string & func,
114 const std::string & file,
115 const int lineNum) {
116
117 try
118 {
119 drama::Task::CheckLockTaken(__func__, __FILE__, __LINE__);
120 }
121 catch (const drama::Exception &e)
122 {
123 if (e.dramaStatus() == DRAMA2__LOCK_ERR)
124 {
126 "Programming error - the program invoked a gitarg::Get() method (or constructor) without having taken the DRAMA lock. Please copy stack trace above to support.",
127 DRAMA2__LOCK_ERR, true);
129 throw;
130
131 }
132
133 }
134 /* Method for internal use only, used to add Enum value possibilities to
135 * an exception.
136 *
137 * @param flags Which GIT Flags apply. Interested in if "Upper",
138 * "Lower" and/or "Abbrev" are set.
139 * @param strings A pointer to a array of pointer to char, which
140 * is a character array to be passed to
141 * DCF(GitArgGetS). This array contains the
142 * list of strings to be accepted with a
143 * terminating null.
144 * @param except The exception to add the enum values too.
145 */
146 extern void __AddEnumPossiblities(const Flags flags,
147 const char **strings,
164 class EnumLookupClass {
165 public:
174 virtual unsigned int GetMaxValue() const = 0;
190 virtual const char ** GetStringArray() const = 0;
193 virtual ~EnumLookupClass() {}
194 };
195
223 template <typename LookupClass, typename EnumType> class Enum {
224 private:
225 EnumType _value; // The underlying value and the only memory used by the class.
226 LookupClass lookupObject; // allows us to invoke the methods of this class.
227
228 /*
229 * Set the value of the object from an int. If out of range,
230 * set to GetMaxValue + 1 (the invalid value).
231 */
232 void SetValue(const unsigned int i) {
233 if (i > lookupObject.GetMaxValue())
234 _value = InvalidValue();
235 else
236 _value = (EnumType)i;
237 }
238 /*
239 * Simply return the invalid value converted to int.
240 */
241 EnumType InvalidValue() const {
242 return (EnumType)(lookupObject.GetMaxValue()+1);
243 }
244 protected:
245 public:
254 Enum() {
255 _value = InvalidValue();
256 }
264
302 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
303 Enum(const sds::Id& Id,
304 const std::string & Name,
305 const int Position,
306 const std::string & Default,
308 :_value(InvalidValue()) {
309 Get(Id, Name, Position, Default, flags);
310 }
311
340 Enum(const sds::Id& Id,
341 const std::string & Name="Argument1",
342 const int Position=1,
343 const EnumType Default = static_cast<EnumType>(0),
345 :_value(InvalidValue()) {
346 Get(Id, Name, Position, Default, flags);
347 }
348
349
387 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
388 Enum(
389 drama::thread::TAction *taction,
390 const sds::Id& Id,
391 const std::string & Name,
392 const int Position,
393 const std::string & Default,
395 :_value(InvalidValue()) {
396
398 Get(Id, Name, Position, Default, flags);
399 }
400
401
430 Enum(
432 const sds::Id& Id,
433 const std::string & Name="Argument1",
434 const int Position=1,
435 const EnumType Default = static_cast<EnumType>(0),
437 :_value(InvalidValue()) {
438
440 Get(Id, Name, Position, Default, flags);
441 }
442
478 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
479 void Get(const sds::Id& Id,
480 const std::string & Name,
481 const int Position,
482 const std::string & Default,
484
485 EnumType enumDefault = static_cast<EnumType>(0);
486 if (Default != "")
487 {
489 "drama::gitarg::Enum type - use of Default string invalid, change to non-deprecated Get()/Constructor.");
490 }
492 }
493
521 void Get(const sds::Id& Id,
522 const std::string & Name="Argument1",
523 const int Position=1,
524 const EnumType Default = static_cast<EnumType>(0),
526
527 // We must have the DRAMA lock - otherwise ERS causes problems.
528 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
529
530 char string[100];
531 int index;
533 GitArgGetS((SdsIdType)Id,Name.c_str(),Position,
534 lookupObject.GetStringArray(), "" /* default value must be empty string */,
535 (int)(flags),sizeof(string),string,&index,&status);
536
537 if (status != STATUS__OK)
538 {
540 "Failed to fetch Enumerated Argument from SDS",
541 status);
542 //__AddEnumPossiblities(flags, lookupObject.GetStringArray(), status);
543 except.AddErs();
544 __AddEnumPossiblities(flags, lookupObject.GetStringArray(), &except);
545 throw except;
546 }
547 /* index == -1 means we take the default */
548 if (index == -1)
549 index = static_cast<int>(Default);
550
551 SetValue(static_cast<unsigned>(index));
552 };
555 operator EnumType() const {
556 return _value;
557 }
560 operator std::string() const {
561 if (_value == InvalidValue())
563 "drama::gitarg::Enum value is invalid - was not initialised to a valid enum value.");
564 return lookupObject.GetStringArray()[int(_value)];
565 }
576 Enum& operator=(const EnumType &rhs) {
577 _value = rhs;
578 return *this;
579 }
580
583 virtual ~Enum() {};
584
585 }; // Class Enum;
586
602 template <typename LookupClass, typename EnumType>
603 auto format_as(const gitarg::Enum<LookupClass, EnumType> &e) { return std::string(e); }
604
605
633 template <long int MinVal,long int MaxVal, long int DefaultVal=0> class Real {
634 private:
635 // Return the range we need.
636 virtual const double * Range() {
637 static const double range[] = { MinVal, MaxVal };
638 return range;
639 }
640 double _value;
641 public:
647 Real(const double def = (double)DefaultVal) : _value(def) {
648 }
679 Real ( /*Constructor with automatic Get */
680 const sds::Id& Id,
681 const std::string & Name="Argument1",
682 const int Position=1,
683 const double Default = (double)DefaultVal,
684 const Flags flags = Flags::KeepErr) : _value(Default) {
685
687 }
688
719 Real ( /*Constructor with automatic Get */
721 const sds::Id& Id,
722 const std::string & Name="Argument1",
723 const int Position=1,
724 const double Default = (double)DefaultVal,
725 const Flags flags = Flags::KeepErr) : _value(Default) {
726
729 }
730
766 Real ( /*Constructor with automatic Get */
767 const sds::Id& Id,
768 const double Min,
769 const double Max,
770 const std::string & Name="Argument1",
771 const int Position=1,
772 const double Default = (double)DefaultVal,
773 const Flags flags = Flags::KeepErr) : _value(Default) {
774
776 }
777
814 Real ( /*Constructor with automatic Get */
816 const sds::Id& Id,
817 const double Min,
818 const double Max,
819 const std::string & Name="Argument1",
820 const int Position=1,
821 const double Default = (double)DefaultVal,
822 const Flags flags = Flags::KeepErr) : _value(Default) {
823
826 }
827
828
829 virtual ~Real() {}
830
856 virtual void Get( /* Get value from Sds structure */
857 const sds::Id& Id,
858 const std::string & Name="Argument1",
859 const int Position=1,
860 const double Default = (double)(DefaultVal),
861 const Flags flags = Flags::KeepErr) {
862
863 // We must have the DRAMA lock - otherwise ERS causes problems.
864 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
865
866
868 GitArgGetD((SdsIdType)Id,Name.c_str(),
869 Position,Range(),Default,
870 (int)(flags),&_value,&status);
871
872 if (status != STATUS__OK)
873 {
875 "Failed to fetch real number Argument from SDS",
876 status);
877
878 except.AddErs();
879 throw except;
880 }
881 }
882
914 virtual void Get( /* Get value from Sds structure */
915 const sds::Id& Id,
916 const double Min,
917 const double Max,
918 const std::string & Name="Argument1",
919 const int Position=1,
920 const double Default = (double)(DefaultVal),
921 const Flags flags = Flags::KeepErr) {
922
923 // We must have the DRAMA lock - otherwise ERS causes problems.
924 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
925
926
927 const double range[] = { Min, Max };
928
930 GitArgGetD((SdsIdType)Id,Name.c_str(),
932 (int)(flags),&_value,&status);
933
934 if (status != STATUS__OK)
935 {
937 "Failed to fetch real number Argument from SDS",
938 status);
939
940 except.AddErs();
941 throw except;
942 }
943 }
944
947 operator double() const {
948 return (_value);
949 }
950 }; // Class Real.
951
968 template <long int MinVal=LONG_MIN,
969 long int MaxVal=LONG_MAX,
970 long int DefaultVal=0>
971 auto format_as(Real<MinVal, MaxVal, DefaultVal> r) { return static_cast<double>(r); }
972
973
997 template <long int MinVal=LONG_MIN,
998 long int MaxVal=LONG_MAX,
999 long int DefaultVal=0> class Int {
1000 private:
1001 // Return the range we need.
1002 virtual const long int * Range() {
1003 static const long int range[] = { MinVal, MaxVal };
1004 return range;
1005 }
1006 long _value;
1007 public:
1013 Int(const long def = DefaultVal) : _value(def) { }
1014
1044 Int ( /*Constructor with automatic Get */
1045 const sds::Id& Id,
1046 const std::string & Name = "Argument1",
1047 const int Position=1,
1048 const long Default = DefaultVal,
1049 const Flags flags = Flags::KeepErr) : _value(Default) {
1050
1052 }
1053
1083 Int ( /*Constructor with automatic Get */
1085 const sds::Id& Id,
1086 const std::string & Name = "Argument1",
1087 const int Position=1,
1088 const long Default = DefaultVal,
1089 const Flags flags = Flags::KeepErr) : _value(Default) {
1090
1093 }
1094
1130 Int ( /*Constructor with automatic Get */
1131 const sds::Id& Id,
1132 const long Min,
1133 const long Max,
1134 const std::string & Name = "Argument1",
1135 const int Position=1,
1136 const long Default = DefaultVal,
1137 const Flags flags = Flags::KeepErr) : _value(Default) {
1138
1140 }
1141
1173 Int ( /*Constructor with automatic Get */
1175 const sds::Id& Id,
1176 const long Min,
1177 const long Max,
1178 const std::string & Name = "Argument1",
1179 const int Position=1,
1180 const long Default = DefaultVal,
1181 const Flags flags = Flags::KeepErr) : _value(Default) {
1182
1185 }
1186
1187
1188
1189 virtual ~Int() {}
1215 virtual void Get( /* Get value from Sds structure */
1216 const sds::Id& Id,
1217 const std::string & Name="Argument1",
1218 const int Position=1,
1219 const long int Default = DefaultVal,
1220 const Flags flags = Flags::KeepErr) {
1221
1222 // We must have the DRAMA lock - otherwise ERS causes problems.
1223 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1224
1225
1227 GitArgGetI((SdsIdType)Id,Name.c_str(),Position,Range(),Default,
1228 (int)(flags),&_value,&status);
1229
1230 if (status != STATUS__OK)
1231 {
1233 "Failed to fetch integer Argument from SDS",
1234 status);
1235
1236 except.AddErs();
1237 throw except;
1238 }
1239
1240 }
1241
1273 virtual void Get( /* Get value from Sds structure */
1274 const sds::Id& Id,
1275 const long Min,
1276 const long Max,
1277 const std::string & Name="Argument1",
1278 const int Position=1,
1279 const long int Default = DefaultVal,
1280 const Flags flags = Flags::KeepErr) {
1281
1282 // We must have the DRAMA lock - otherwise ERS causes problems.
1283 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1284
1285 const long range[] = { Min, Max };
1286
1287
1290 (int)(flags),&_value,&status);
1291
1292 if (status != STATUS__OK)
1293 {
1295 "Failed to fetch integer Argument from SDS",
1296 status);
1297
1298 except.AddErs();
1299 throw except;
1301
1302 }
1303
1305 operator long int() const {
1306 return (_value);
1307 }
1308
1309
1310 }; // class Int.
1311
1328 template <long int MinVal=LONG_MIN,
1329 long int MaxVal=LONG_MAX,
1330 long int DefaultVal=0>
1346 class String : public std::string {
1347 using std::string::string; // Inherit constructors.
1348 private:
1349 // Enough space for conversion of doubles/long ints.
1350 static const unsigned _DefaultStringLength = 100;
1351
1352 void RawGet (const sds::Id& Id, const std::string &Name,
1353 int Position, const std::string &Default,
1355
1356 public:
1385 String( const sds::Id& Id,
1386 const std::string &Name = "Argument1",
1387 const int Position = 1,
1388 const std::string &Default = "",
1389 const Flags flags = Flags::KeepErr) {
1390 this->Get(Id, Name, Position, Default, flags);
1391 }
1392
1422 String(
1424 const sds::Id& Id,
1425 const std::string &Name = "Argument1",
1426 const int Position = 1,
1427 const std::string &Default = "",
1428 const Flags flags = Flags::KeepErr) {
1429
1431 this->Get(Id, Name, Position, Default, flags);
1432 }
1436 String(const String&) = default;
1437
1438 String(String&&) = default;
1443 /*
1444 * From:
1445 * http://codexpert.ro/blog/2013/08/26/inherited-constructors-in-cpp11/
1446 * If in the derived class you add a new specific constructor
1447 * after you use the using directive, you lost the possibility
1448 * of using the default constructor (even though it is in the
1449 * base class). So, if it is needed a specific constructor, you
1450 * need to add a default one, even one using that no-parameter
1451 * base constructor:
1452 */
1453 String() {
1454 }
1481 * Implementation of this method is in gitarg.cpp.
1482 */
1483 virtual void Get (const sds::Id& Id,
1484 const std::string &Name = "Argument1",
1485 const int Position = 1,
1486 const std::string &Default = "",
1487 const Flags flags = Flags::KeepErr);
1488
1494 String operator=(const std::string &str) {
1495 this->std::string::operator=(str);
1496 return *this;
1497 }
1503 String operator=(const String &str) {
1504 this->std::string::operator=(str);
1505 return *this;
1506 }
1512 String operator=(const char *s) {
1513 this->std::string::operator=(s);
1514 return *this;
1515 }
1522 String& operator=(char c) {
1523 this->std::string::operator=(c);
1524 return *this;
1525 }
1526
1527
1528 }; /* String */
1529
1542 inline auto format_as(const String &s) { return std::string(s); }
1543
1544
1567 class Bool {
1568 private:
1569 bool _value;
1570 static const GitLogStrType lookupTable[];
1571 protected:
1584 virtual const GitLogStrType * Lookup() {
1585 return lookupTable;
1586 }
1587 public:
1592 Bool(bool initVal=false) : _value(initVal) { }
1593
1628 Bool ( /*Constructor with automatic Get */
1629 const sds::Id& Id,
1630 const std::string &Name="Argument1",
1631 const int Position=1,
1632 const bool Default = false,
1634 {
1636 }
1637
1672 Bool ( /*Constructor with automatic Get */
1674 const sds::Id& Id,
1675 const std::string &Name="Argument1",
1676 const int Position=1,
1677 const bool Default = false,
1679 {
1682 }
1683
1686 virtual ~Bool() {}; /* Destructor for inheritors */
1711 virtual void Get( /* Get value from Sds structure */
1712 const sds::Id& Id,
1713 const std::string &Name="Argument1",
1714 const int Position=1,
1715 const bool Default = false,
1717
1718 // We must have the DRAMA lock - otherwise ERS causes problems.
1719 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1720
1721
1722 long int actValue = 0;
1725 (int)(flags),&actValue,&status);
1726
1727 if (status != STATUS__OK)
1728 {
1730 "Failed to fetch boolean Argument from SDS",
1731 status);
1732 except.AddErs();
1733 throw except;
1734 }
1735
1736 _value = actValue ? true : false;
1737 };
1740 operator bool() const {
1741 return _value;
1742 };
1748 Bool operator=(const bool src) {
1749 _value = src;
1750 return *this;
1751 }
1752
1753
1754 }; // class Bool
1767 inline auto format_as(gitarg::Bool b) { return bool(b); }
1768
1769
1770
1783 class Id : public sds::Id {
1784 private:
1785 bool _readFromFile = false; // Was this read from a file.
1786 bool _defaultUsed = false; // Was this read from the default.
1787 std::string _actualName; // Actual name of file or structure.
1788
1789 void UseDefaultIfReq(const std::string &name,
1790 int position,
1791 const std::string &fileName,
1792 Flags flags,
1794 const std::string &mess);
1795
1796 public:
1801 Id() : sds::Id() { }
1802
1803
1859 Id(
1860 const sds::Id& Id,
1861 const std::string &Name="Argument1",
1862 const int Position=1,
1863 const std::string Default = "",
1864 const Flags flags = Flags::KeepErr)
1865 {
1867 }
1868
1869
1870
1926 Id(
1928 const sds::Id& Id,
1929 const std::string &Name="Argument1",
1930 const int Position=1,
1931 const std::string Default = "",
1932 const Flags flags = Flags::KeepErr)
1933 {
1936 }
1937
1940 virtual ~Id();
1941
1993 virtual void Get( /* Get value from Sds structure */
1994 const sds::Id& Id,
1995 const std::string &Name="Argument1",
1996 const int Position=1,
1997 const std::string Default = "",
1998 const Flags flags = (Flags::KeepErr));
1999
2000
2009 virtual std::string ActualName() const;
2014 virtual bool WasReadFromFile() const;
2015
2021 virtual bool WasReadFromDefault() const;
2022
2023
2024 }; // class Id
2025
2026
2035 class Filename : public String {
2036 //String::String; // Inherit constructors.
2037 public:
2071 Filename( const sds::Id& Id,
2072 const std::string &Name = "Argument1",
2073 const int Position = 1,
2074 const std::string &Default = "",
2075 const Flags flags = Flags::KeepErr) {
2076 this->Get(Id, Name, Position, Default, flags);
2077 }
2078
2113 Filename(
2115 const sds::Id& Id,
2116 const std::string &Name = "Argument1",
2117 const int Position = 1,
2118 const std::string &Default = "",
2119 const Flags flags = Flags::KeepErr) {
2120
2121
2123 this->Get(Id, Name, Position, Default, flags);
2124 }
2125
2126
2130 /*
2131 * From:
2132 * http://codexpert.ro/blog/2013/08/26/inherited-constructors-in-cpp11/
2133 * If in the derived class you add a new specific constructor
2134 * after you use the using directive, you lost the possibility
2135 * of using the default constructor (even though it is in the
2136 * base class). So, if it is needed a specific constructor, you
2137 * need to add a default one, even one using that no-parameter
2138 * base constructor:
2139 */
2141 }
2142
2143
2175 virtual void Get (const sds::Id& Id,
2176 const std::string &Name = "Argument1",
2177 const int Position = 1,
2178 const std::string &Default = "",
2179 const Flags flags = Flags::KeepErr);
2180
2181
2182 }; // class Filename
2183
2196 inline auto format_as(const Filename &f) { return std::string(f); }
2197
2198
2205 struct ArgFlagVal {
2206 std::string name;
2207 unsigned flag;
2208 };
2215 using ArgFlagValVector = std::vector<ArgFlagVal>;
2216
2217
2218
2219 /*
2220 * Internal method only.
2221 *
2222 * Used by ArgFlags::Get() to get a given argument as a string, converting
2223 * it to upper case if requested.
2224 *
2225 * Returns the value of the string (converted to upper case if
2226 * requested) or an empty string if the value does not exist. Does
2227 * not throw an exception if the value does not exist.
2228 *
2229 * @param Id The SDS structure to read the flags from
2230 * @param pos Position of the argument to read.
2231 * @param toUpper Do we convert the result to upper case. If
2232 * false, leave as found.
2233 *
2234 * @return The value found. If no value was found, return an empty
2235 * string (does not throw for no value found!)
2236 */
2237 extern std::string _GetString(const sds::Id& Id, unsigned pos, bool toUpper);
2238
2260 template<class ContainerType,
2261 /*
2262 * This complicated bit of code is about ensuring that only containers containing
2263 * a sub-class of "ArgFlagVal" are considered when trying to determine if
2264 * this template function is a valid specialization to use.
2265 *
2266 * A relevant reference is SFINAE ("Substitution Failure Is Not An Error")
2267 * E.g. http://en.cppreference.com/w/cpp/language/sfinae
2268 *
2269 * The problem we are tying to solve is that without this, any type
2270 * could trigger this specialization. Compilation
2271 * would then fail late with a poor error message.
2272 *
2273 * std::enable_if is being used to this template is only used when the
2274 * ContainerType value is a sub-class of ArgFlagVal. The following
2275 * references will help explain this:
2276 * http://www.cplusplus.com/reference/type_traits/enable_if/?kw=enable_if
2277 * http://www.boost.org/doc/libs/1_45_0/libs/utility/enable_if.html
2278 *
2279 * In addition, the use of "typename ContainerType::value_type" is to ensure
2280 * we refer to the actual type of the ContainerType template argument.
2281 * This should also trigger a failure if the container does not have a
2282 * value_type member. Here typename can be used to declare that a
2283 * dependent name is a type.
2284 */
2285 typename std::enable_if<std::is_base_of<ArgFlagVal,
2286 typename ContainerType::value_type>::value>::type* = nullptr>
2287
2288
2289 class ArgFlags {
2290 const ContainerType _validFlags; // Container with set of valid flags
2291 const bool _ignoreCase; // Do we ignore case?
2292 unsigned _theValue = 0; // The mask of flag values.
2293
2294 public:
2309 ArgFlags(const ContainerType &validFlagVals, bool ignoreCase=true) :
2310 _validFlags(validFlagVals), _ignoreCase(ignoreCase) {
2311 }
2341 const sds::Id& Id,
2342 const unsigned First = 1,
2343 const unsigned Last = 0,
2344 const bool FailOnInvalid = true,
2345 const bool IgnoreCase=true) :
2346 _validFlags(validFlagVals), _ignoreCase(IgnoreCase) {
2348 }
2374 unsigned Get(const sds::Id& Id,
2375 const unsigned First = 1,
2376 unsigned Last = 0,
2377 const bool FailOnInvalid = true) {
2378
2379 _theValue = 0; // Clear the value on entry.
2380
2381 if (Last == 0) Last = UINT_MAX;
2382
2383 /*
2384 * Validate arguments.
2385 */
2386 if (First < 1)
2387 {
2389 "ArgFlags First argument position value of {0} is less then min of 1",
2390 First);
2391 }
2392 if (Last < First)
2393 {
2395 "ArgFlags Last argument position value of {0} is less then First of {1}",
2396 Last, First);
2397
2398 }
2399 /*
2400 * If no argument was supplied, then just return 0.
2402 if (!Id) return 0;
2403 /*
2404 * Work through arguments.
2405 */
2406 for (unsigned arg = First; arg < Last ; arg++)
2407 {
2408 /*
2409 * Use this static method to get the actual string
2410 * value - not dependent on the template so
2411 * more efficient compilation.
2412 */
2413 auto thisVal = _GetString(Id, arg, _ignoreCase);
2414
2415 /*
2416 * If this is a null value, we are done.
2417 */
2418 if (thisVal == "")
2419 return _theValue;
2420
2421 /*
2422 * Work through the possible values. If we find
2423 * it, add the relevant flag value to the set of
2424 * values.
2425 */
2426 bool found = false;
2427 for (auto & flag : _validFlags)
2428 {
2429 if (flag.name == thisVal)
2430 {
2431 _theValue |= flag.flag;
2432 found = true;
2433 break;
2434 }
2435 }
2436 if ((!found)&&(FailOnInvalid))
2437 {
2440
2441 except.FmtWriteF("Argument value at position {0}, \"{1}\", is not an acceptable flag value",
2442 arg, thisVal);
2443 except.AddErs();
2444 AddFlagPossiblities(&except);
2445 throw except;
2446 }
2447
2448 }
2449
2450 return _theValue;
2451
2452 }
2462 unsigned GetVal() const {
2463 return _theValue;
2464 }
2472 bool IsSet(unsigned flags) const {
2473 return ((_theValue & flags) == flags);
2474 }
2475 private:
2476 /* Add Flat value possibilities to an exception.
2477 *
2478 * @param except The exception to add the enum values too.
2479 */
2480 void AddFlagPossiblities(drama::Exception *except) {
2481 // We must have the DRAMA lock - otherwise ERS causes problems.
2482 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
2483 std::ostringstream s;
2484
2485 (*except) << "\n Accepted flags are:\n";
2486 s << " ";
2487 for (auto & flag : _validFlags)
2488 {
2489 s << flag.name << ", ";
2490 }
2491 auto str = s.str();
2492 // Remove the trailing ", "
2493 str.pop_back();
2494 str.pop_back();
2495 (*except) << str << '\n';
2496
2497 if (_ignoreCase)
2498 {
2499 (*except) << " Case is ignored.";
2500 }
2501 }
2502
2503 }; // class ArgFlags
2504
2505
2506
2507 } // namespace gitarg
2508
2509} // namespace drama
2510
2511#endif /* define DRAMA2_GITARG_INC */
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:183
unsigned Get(const sds::Id &Id, const unsigned First=1, unsigned Last=0, const bool FailOnInvalid=true)
Get argument flag value set from an SDS structure.
Definition gitarg.hh:2401
ArgFlags(const ContainerType &validFlagVals, const sds::Id &Id, const unsigned First=1, const unsigned Last=0, const bool FailOnInvalid=true, const bool IgnoreCase=true)
Constructor with the initial value set from an SDS structure.
Definition gitarg.hh:2367
ArgFlags(const ContainerType &validFlagVals, bool ignoreCase=true)
Constructor.
Definition gitarg.hh:2336
bool IsSet(unsigned flags) const
Determines whether the specified flags are set.
Definition gitarg.hh:2499
unsigned GetVal() const
Return the flags value - the mask of set bits.
Definition gitarg.hh:2489
This class is used to check for the existence of one or more flags in an SDS structure.
Definition gitarg.hh:2316
Bool(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const bool Default=false, const Flags flags=(Flags::Upper|Flags::Abbrev|Flags::KeepErr))
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:1699
Bool operator=(const bool src)
Assign a bool to this gitarg::Bool item.
Definition gitarg.hh:1775
Bool(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const bool Default=false, const Flags flags=(Flags::Upper|Flags::Abbrev|Flags::KeepErr))
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:1655
virtual const GitLogStrType * Lookup()
Return a pointer to an array of enum strings equivalents.
Definition gitarg.hh:1611
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const bool Default=false, const Flags flags=(Flags::Upper|Flags::Abbrev|Flags::KeepErr))
Get the value of the object from an SDS struture.
Definition gitarg.hh:1738
virtual ~Bool()
Destructor.
Definition gitarg.hh:1713
Bool(bool initVal=false)
Simple constructor with a default value of false.
Definition gitarg.hh:1619
A class which reads Boolean values from SDS argument structures.
Definition gitarg.hh:1594
virtual ~EnumLookupClass()
Destructor.
Definition gitarg.hh:220
virtual unsigned int GetMaxValue() const =0
This function should return the maximum normal value of the enumerated value.
virtual const char ** GetStringArray() const =0
Return a pointer to an array of enum strings equivalents.
An interface for the lookup class template arguments to drama::gitarg::Enum.
Definition gitarg.hh:191
virtual ~Enum()
Destructor.
Definition gitarg.hh:610
Enum(EnumType InitialValue)
Constructor with initial value supplied.
Definition gitarg.hh:290
Enum(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const EnumType Default=static_cast< EnumType >(0), const Flags flags=Flags::Upper|Flags::Abbrev|Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:457
void Get(const sds::Id &Id, const std::string &Name, const int Position, const std::string &Default, const Flags flags=Flags::Upper|Flags::Abbrev|Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:506
Enum & operator=(const EnumType &rhs)
Allow an item of the underlying EnumType to be assigned to this object.
Definition gitarg.hh:603
Enum(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const EnumType Default=static_cast< EnumType >(0), const Flags flags=Flags::Upper|Flags::Abbrev|Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:367
Enum()
Default constructor for the object.
Definition gitarg.hh:281
void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const EnumType Default=static_cast< EnumType >(0), const Flags flags=Flags::Upper|Flags::Abbrev|Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:548
A class which reads Enumerated values from a SDS argument structures.
Definition gitarg.hh:250
Filename(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gitarg.hh:2140
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Fetch the value of this item from an SDS structure.
Filename(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gitarg.hh:2098
Filename()
Default constructor.
Definition gitarg.hh:2167
A class which reads a file name from an SDS Command argument structures.
Definition gitarg.hh:2062
Id(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure or file.
Definition gitarg.hh:1886
virtual ~Id()
Destructor.
Id()
Default constructor.
Definition gitarg.hh:1828
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string Default="", const Flags flags=(Flags::KeepErr))
Get the value of the object from an SDS structure or file.
virtual bool WasReadFromFile() const
Indicates if the structure was read from a file.
virtual bool WasReadFromDefault() const
Indicates if the structure was read from the default.
Id(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure or file.
Definition gitarg.hh:1953
virtual std::string ActualName() const
Return the actual name of the file or structure.
A class which reads an SDS structure from DRAMA SDS Command argument structures.
Definition gitarg.hh:1810
Int(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const long Default=DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which contructs the value from an item in an SDS structure.
Definition gitarg.hh:1071
virtual void Get(const sds::Id &Id, const long Min, const long Max, const std::string &Name="Argument1", const int Position=1, const long int Default=DefaultVal, const Flags flags=Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:1300
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const long int Default=DefaultVal, const Flags flags=Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:1242
Int(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const long Default=DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which contructs the value from an item in an SDS structure.
Definition gitarg.hh:1110
Int(const long def=DefaultVal)
Simple constructor with a default value specified.
Definition gitarg.hh:1040
Int(const sds::Id &Id, const long Min, const long Max, const std::string &Name="Argument1", const int Position=1, const long Default=DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which contructs the value from an item in an SDS structure.
Definition gitarg.hh:1157
Int(drama::thread::TAction *taction, const sds::Id &Id, const long Min, const long Max, const std::string &Name="Argument1", const int Position=1, const long Default=DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which contructs the value from an item in an SDS structure.
Definition gitarg.hh:1200
A class which reads integer values from an SDS argument structure.
Definition gitarg.hh:1026
Real(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const double Default=(double) DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure, for use in a threaded action...
Definition gitarg.hh:746
virtual void Get(const sds::Id &Id, const double Min, const double Max, const std::string &Name="Argument1", const int Position=1, const double Default=(double)(DefaultVal), const Flags flags=Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:941
Real(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const double Default=(double) DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:706
Real(drama::thread::TAction *taction, const sds::Id &Id, const double Min, const double Max, const std::string &Name="Argument1", const int Position=1, const double Default=(double) DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure, for use in a threaded action...
Definition gitarg.hh:841
Real(const double def=(double) DefaultVal)
Simple constructor with a default value specified.
Definition gitarg.hh:674
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const double Default=(double)(DefaultVal), const Flags flags=Flags::KeepErr)
Get the value of the object from an SDS structure.
Definition gitarg.hh:883
Real(const sds::Id &Id, const double Min, const double Max, const std::string &Name="Argument1", const int Position=1, const double Default=(double) DefaultVal, const Flags flags=Flags::KeepErr)
Constructor which constructs the value from an item in an SDS structure.
Definition gitarg.hh:793
A class which reads real values from an SDS argument structure.
Definition gitarg.hh:660
String operator=(const std::string &str)
Assign a std::string to this gitarg::String.
Definition gitarg.hh:1521
String(drama::thread::TAction *taction, const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gitarg.hh:1449
String(const String &)=default
Copy constructor Default is sufficient.
String()
Default constructor.
Definition gitarg.hh:1480
String operator=(const String &str)
Assign a const std::string to this gitarg::String.
Definition gitarg.hh:1530
String & operator=(char c)
Set this gitarg::String to a string containing a single character.
Definition gitarg.hh:1549
String(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gitarg.hh:1412
virtual void Get(const sds::Id &Id, const std::string &Name="Argument1", const int Position=1, const std::string &Default="", const Flags flags=Flags::KeepErr)
Fetch the value of this item from an SDS structure.
String operator=(const char *s)
Copy contents of a C string into this gitarg::String.
Definition gitarg.hh:1539
A class which reads a string item from an SDS structure.
Definition gitarg.hh:1373
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
A class used by threads to access and enable the DRAMA context of an action or of a particular UFACE ...
Definition thread.hh:598
A class which implements a DRAMA Action with runs a thread.
Definition threadaction.hh:204
DRAMA 2 main include file.
#define DramaTHROW_F(status_, format_,...)
Throw a Drama exception with fmt::format string formatting.
Definition exception.hh:129
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:90
Flags
The various flags used in GIT operations.
Definition gitarg.hh:84
@ Upper
Convert strings to upper case.
@ KeepErr
Keep error status on return - will throw instead of take the default
@ LastBit
Only consider Least significant bit of integer values when treating integers as logical.
@ Abbrev
Allow abbreviations
@ Lower
Convert strings to lower case.
@ KeepValErr
Keep error status on return for value errors, not for no value supplied errors when it will take the ...
@ NoFlagSet
Value indicating no flags set.
auto format_as(const gitarg::Enum< LookupClass, EnumType > &e)
Support formatting a gitarg::Enum as per std::string.
Definition gitarg.hh:630
constexpr Flags operator|(Flags f1, Flags f2)
Operator to allow Flags values to be or-ed.
Definition gitarg.hh:112
std::vector< ArgFlagVal > ArgFlagValVector
Declare a vector for ArgFlagVal items.
Definition gitarg.hh:2242
bool IsFlagSet(const Flags f1, const Flags f2)
Operator to allow determination of if a Flag enum value set.
Definition gitarg.hh:128
@ Default
System default type.
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
Type used to specify arg/flag relationships to ArgFlags class.
Definition gitarg.hh:2232
DRAMA 2 include file - Code common to DRAMA 2 features supporting threading.