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 "Git.h"
34#include <string>
35#include <limits.h>
36#include <type_traits>
37namespace drama {
44 namespace gitarg {
45
56 enum class Flags {
57 NoFlagSet=0,
74 };
84 constexpr Flags operator|(Flags f1, Flags f2) {
85 return Flags(unsigned(f1)|unsigned(f2));
86 }
100 inline bool IsFlagSet(const Flags f1, const Flags f2) {
101 if ((unsigned int)(f1) & (unsigned int)(f2))
102 return true;
103 else
104 return false;
105 }
106
107 /*
108 * This method invokes the drama::Task static equivalent, but
109 * catches the exception and provides a more precise message.
110 */
111 inline void ___CheckLockTaken(
112 const std::string & func,
113 const std::string & file,
114 const int lineNum) {
115
116 try
117 {
118 drama::Task::CheckLockTaken(__func__, __FILE__, __LINE__);
119 }
120 catch (const drama::Exception &e)
121 {
122 if (e.dramaStatus() == DRAMA2__LOCK_ERR)
123 {
125 "Programming error - the program invoked a gitarg::Get() method (or constructor) without having taken the DRAMA lock. Please copy stack trace above to support.",
126 DRAMA2__LOCK_ERR, true);
128 throw;
129
130 }
131
132 }
133 /* Method for internal use only, used to add Enum value possibilities to
134 * an exception.
135 *
136 * @param flags Which GIT Flags apply. Interested in if "Upper",
137 * "Lower" and/or "Abbrev" are set.
138 * @param strings A pointer to a array of pointer to char, which
139 * is a character array to be passed to
140 * DCF(GitArgGetS). This array contains the
141 * list of strings to be accepted with a
142 * terminating null.
143 * @param except The exception to add the enum values too.
144 */
145 extern void __AddEnumPossiblities(const Flags flags,
146 const char **strings,
163 class EnumLookupClass {
164 public:
173 virtual unsigned int GetMaxValue() const = 0;
189 virtual const char ** GetStringArray() const = 0;
192 virtual ~EnumLookupClass() {}
193 };
194
222 template <typename LookupClass, typename EnumType> class Enum {
223 private:
224 EnumType _value; // The underlying value and the only memory used by the class.
225 LookupClass lookupObject; // allows us to invoke the methods of this class.
226
227 /*
228 * Set the value of the object from an int. If out of range,
229 * set to GetMaxValue + 1 (the invalid value).
230 */
231 void SetValue(const unsigned int i) {
232 if (i > lookupObject.GetMaxValue())
233 _value = InvalidValue();
234 else
235 _value = (EnumType)i;
236 }
237 /*
238 * Simply return the invalid value converted to int.
239 */
240 EnumType InvalidValue() const {
241 return (EnumType)(lookupObject.GetMaxValue()+1);
242 }
243 protected:
244 public:
253 Enum() {
254 _value = InvalidValue();
255 }
263
301 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
302 Enum(const sds::Id& Id,
303 const std::string & Name,
304 const int Position,
305 const std::string & Default,
307 :_value(InvalidValue()) {
308 Get(Id, Name, Position, Default, flags);
309 }
310
339 Enum(const sds::Id& Id,
340 const std::string & Name="Argument1",
341 const int Position=1,
342 const EnumType Default = static_cast<EnumType>(0),
344 :_value(InvalidValue()) {
345 Get(Id, Name, Position, Default, flags);
346 }
347
348
386 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
387 Enum(
388 drama::thread::TAction *taction,
389 const sds::Id& Id,
390 const std::string & Name,
391 const int Position,
392 const std::string & Default,
394 :_value(InvalidValue()) {
395
397 Get(Id, Name, Position, Default, flags);
398 }
399
400
429 Enum(
431 const sds::Id& Id,
432 const std::string & Name="Argument1",
433 const int Position=1,
434 const EnumType Default = static_cast<EnumType>(0),
436 :_value(InvalidValue()) {
437
439 Get(Id, Name, Position, Default, flags);
440 }
441
477 D2DEPRECATED_EXPLAIN("Replace by overload with enum default instead of string default")
478 void Get(const sds::Id& Id,
479 const std::string & Name,
480 const int Position,
481 const std::string & Default,
483
484 EnumType enumDefault = static_cast<EnumType>(0);
485 if (Default != "")
486 {
488 "drama::gitarg::Enum type - use of Default string invalid, change to non-depreciated Get()/Constructor.");
489 }
491 }
492
520 void Get(const sds::Id& Id,
521 const std::string & Name="Argument1",
522 const int Position=1,
523 const EnumType Default = static_cast<EnumType>(0),
525
526 // We must have the DRAMA lock - otherwise ERS causes problems.
527 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
528
529 char string[100];
530 int index;
532 GitArgGetS((SdsIdType)Id,Name.c_str(),Position,
533 lookupObject.GetStringArray(), "" /* default value must be empty string */,
534 (int)(flags),sizeof(string),string,&index,&status);
535
536 if (status != STATUS__OK)
537 {
539 "Failed to fetch Enumerated Argument from SDS",
540 status);
541 //__AddEnumPossiblities(flags, lookupObject.GetStringArray(), status);
542 except.AddErs();
543 __AddEnumPossiblities(flags, lookupObject.GetStringArray(), &except);
544 throw except;
545 }
546 /* index == -1 means we take the default */
547 if (index == -1)
548 index = static_cast<int>(Default);
549
550 SetValue(static_cast<unsigned>(index));
551 };
554 operator EnumType() const {
555 return _value;
556 }
559 operator std::string() const {
560 if (_value == InvalidValue())
562 "drama::gitarg::Enum value is invalid - was not initialised to a valid enum value.");
563 return lookupObject.GetStringArray()[int(_value)];
564 }
575 Enum& operator=(const EnumType &rhs) {
576 _value = rhs;
577 return *this;
578 }
579
582 virtual ~Enum() {};
583
584 }; // Class Enum;
585
587
615 template <long int MinVal,long int MaxVal, long int DefaultVal=0> class Real {
616 private:
617 // Return the range we need.
618 virtual const double * Range() {
619 static const double range[] = { MinVal, MaxVal };
620 return range;
621 }
622 double _value;
623 public:
629 Real(const double def = (double)DefaultVal) : _value(def) {
630 }
661 Real ( /*Constructor with automatic Get */
662 const sds::Id& Id,
663 const std::string & Name="Argument1",
664 const int Position=1,
665 const double Default = (double)DefaultVal,
666 const Flags flags = Flags::KeepErr) : _value(Default) {
667
669 }
670
701 Real ( /*Constructor with automatic Get */
703 const sds::Id& Id,
704 const std::string & Name="Argument1",
705 const int Position=1,
706 const double Default = (double)DefaultVal,
707 const Flags flags = Flags::KeepErr) : _value(Default) {
708
711 }
712
748 Real ( /*Constructor with automatic Get */
749 const sds::Id& Id,
750 const double Min,
751 const double Max,
752 const std::string & Name="Argument1",
753 const int Position=1,
754 const double Default = (double)DefaultVal,
755 const Flags flags = Flags::KeepErr) : _value(Default) {
756
758 }
759
796 Real ( /*Constructor with automatic Get */
798 const sds::Id& Id,
799 const double Min,
800 const double Max,
801 const std::string & Name="Argument1",
802 const int Position=1,
803 const double Default = (double)DefaultVal,
804 const Flags flags = Flags::KeepErr) : _value(Default) {
805
808 }
809
810
811 virtual ~Real() {}
812
838 virtual void Get( /* Get value from Sds structure */
839 const sds::Id& Id,
840 const std::string & Name="Argument1",
841 const int Position=1,
842 const double Default = (double)(DefaultVal),
843 const Flags flags = Flags::KeepErr) {
844
845 // We must have the DRAMA lock - otherwise ERS causes problems.
846 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
847
848
850 GitArgGetD((SdsIdType)Id,Name.c_str(),
851 Position,Range(),Default,
852 (int)(flags),&_value,&status);
853
854 if (status != STATUS__OK)
855 {
857 "Failed to fetch real number Argument from SDS",
858 status);
859
860 except.AddErs();
861 throw except;
862 }
863 }
864
896 virtual void Get( /* Get value from Sds structure */
897 const sds::Id& Id,
898 const double Min,
899 const double Max,
900 const std::string & Name="Argument1",
901 const int Position=1,
902 const double Default = (double)(DefaultVal),
903 const Flags flags = Flags::KeepErr) {
904
905 // We must have the DRAMA lock - otherwise ERS causes problems.
906 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
907
908
909 const double range[] = { Min, Max };
910
912 GitArgGetD((SdsIdType)Id,Name.c_str(),
914 (int)(flags),&_value,&status);
915
916 if (status != STATUS__OK)
917 {
919 "Failed to fetch real number Argument from SDS",
920 status);
921
922 except.AddErs();
923 throw except;
924 }
925 }
926
929 operator double() const {
930 return (_value);
931 }
932 }; // Class Real.
933
958 template <long int MinVal=LONG_MIN,
959 long int MaxVal=LONG_MAX,
960 long int DefaultVal=0> class Int {
961 private:
962 // Return the range we need.
963 virtual const long int * Range() {
964 static const long int range[] = { MinVal, MaxVal };
965 return range;
966 }
967 long _value;
968 public:
974 Int(const long def = DefaultVal) : _value(def) { }
975
1005 Int ( /*Constructor with automatic Get */
1006 const sds::Id& Id,
1007 const std::string & Name = "Argument1",
1008 const int Position=1,
1009 const long Default = DefaultVal,
1010 const Flags flags = Flags::KeepErr) : _value(Default) {
1011
1013 }
1014
1044 Int ( /*Constructor with automatic Get */
1046 const sds::Id& Id,
1047 const std::string & Name = "Argument1",
1048 const int Position=1,
1049 const long Default = DefaultVal,
1050 const Flags flags = Flags::KeepErr) : _value(Default) {
1051
1054 }
1055
1091 Int ( /*Constructor with automatic Get */
1092 const sds::Id& Id,
1093 const long Min,
1094 const long Max,
1095 const std::string & Name = "Argument1",
1096 const int Position=1,
1097 const long Default = DefaultVal,
1098 const Flags flags = Flags::KeepErr) : _value(Default) {
1099
1101 }
1102
1134 Int ( /*Constructor with automatic Get */
1136 const sds::Id& Id,
1137 const long Min,
1138 const long Max,
1139 const std::string & Name = "Argument1",
1140 const int Position=1,
1141 const long Default = DefaultVal,
1142 const Flags flags = Flags::KeepErr) : _value(Default) {
1143
1146 }
1147
1148
1149
1150 virtual ~Int() {}
1176 virtual void Get( /* Get value from Sds structure */
1177 const sds::Id& Id,
1178 const std::string & Name="Argument1",
1179 const int Position=1,
1180 const long int Default = DefaultVal,
1181 const Flags flags = Flags::KeepErr) {
1182
1183 // We must have the DRAMA lock - otherwise ERS causes problems.
1184 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1185
1186
1188 GitArgGetI((SdsIdType)Id,Name.c_str(),Position,Range(),Default,
1189 (int)(flags),&_value,&status);
1190
1191 if (status != STATUS__OK)
1192 {
1194 "Failed to fetch integer Argument from SDS",
1195 status);
1196
1197 except.AddErs();
1198 throw except;
1199 }
1200
1201 }
1202
1234 virtual void Get( /* Get value from Sds structure */
1235 const sds::Id& Id,
1236 const long Min,
1237 const long Max,
1238 const std::string & Name="Argument1",
1239 const int Position=1,
1240 const long int Default = DefaultVal,
1241 const Flags flags = Flags::KeepErr) {
1242
1243 // We must have the DRAMA lock - otherwise ERS causes problems.
1244 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1245
1246 const long range[] = { Min, Max };
1247
1248
1251 (int)(flags),&_value,&status);
1252
1253 if (status != STATUS__OK)
1254 {
1256 "Failed to fetch integer Argument from SDS",
1257 status);
1258
1259 except.AddErs();
1260 throw except;
1262
1263 }
1264
1266 operator long int() const {
1267 return (_value);
1268 }
1269
1270
1271 }; // class Int.
1272
1286 class String : public std::string {
1287 using std::string::string; // Inherit constructors.
1288 private:
1289 // Enough space for conversion of doubles/long ints.
1290 static const unsigned _DefaultStringLength = 100;
1291
1292 void RawGet (const sds::Id& Id, const std::string &Name,
1293 int Position, const std::string &Default,
1295
1296 public:
1325 String( const sds::Id& Id,
1326 const std::string &Name = "Argument1",
1327 const int Position = 1,
1328 const std::string &Default = "",
1329 const Flags flags = Flags::KeepErr) {
1330 this->Get(Id, Name, Position, Default, flags);
1331 }
1332
1362 String(
1364 const sds::Id& Id,
1365 const std::string &Name = "Argument1",
1366 const int Position = 1,
1367 const std::string &Default = "",
1368 const Flags flags = Flags::KeepErr) {
1369
1371 this->Get(Id, Name, Position, Default, flags);
1372 }
1376 String(const String&) = default;
1377
1378 String(String&&) = default;
1383 /*
1384 * From:
1385 * http://codexpert.ro/blog/2013/08/26/inherited-constructors-in-cpp11/
1386 * If in the derived class you add a new specific constructor
1387 * after you use the using directive, you lost the possibility
1388 * of using the default constructor (even though it is in the
1389 * base class). So, if it is needed a specific constructor, you
1390 * need to add a default one, even one using that no-parameter
1391 * base constructor:
1392 */
1393 String() {
1394 }
1421 * Implementation of this method is in gitarg.cpp.
1422 */
1423 virtual void Get (const sds::Id& Id,
1424 const std::string &Name = "Argument1",
1425 const int Position = 1,
1426 const std::string &Default = "",
1427 const Flags flags = Flags::KeepErr);
1428
1434 String operator=(const std::string &str) {
1435 this->std::string::operator=(str);
1436 return *this;
1437 }
1443 String operator=(const String &str) {
1444 this->std::string::operator=(str);
1445 return *this;
1446 }
1452 String operator=(const char *s) {
1453 this->std::string::operator=(s);
1454 return *this;
1455 }
1462 String& operator=(char c) {
1463 this->std::string::operator=(c);
1464 return *this;
1465 }
1466
1467
1468 }; /* String */
1469
1492 class Bool {
1493 private:
1494 bool _value;
1495 static const GitLogStrType lookupTable[];
1496 protected:
1509 virtual const GitLogStrType * Lookup() {
1510 return lookupTable;
1511 }
1512 public:
1517 Bool(bool initVal=false) : _value(initVal) { }
1518
1553 Bool ( /*Constructor with automatic Get */
1554 const sds::Id& Id,
1555 const std::string &Name="Argument1",
1556 const int Position=1,
1557 const bool Default = false,
1559 {
1561 }
1562
1597 Bool ( /*Constructor with automatic Get */
1599 const sds::Id& Id,
1600 const std::string &Name="Argument1",
1601 const int Position=1,
1602 const bool Default = false,
1604 {
1607 }
1608
1611 virtual ~Bool() {}; /* Destructor for inheritors */
1636 virtual void Get( /* Get value from Sds structure */
1637 const sds::Id& Id,
1638 const std::string &Name="Argument1",
1639 const int Position=1,
1640 const bool Default = false,
1642
1643 // We must have the DRAMA lock - otherwise ERS causes problems.
1644 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
1645
1646
1647 long int actValue = 0;
1650 (int)(flags),&actValue,&status);
1651
1652 if (status != STATUS__OK)
1653 {
1655 "Failed to fetch boolean Argument from SDS",
1656 status);
1657 except.AddErs();
1658 throw except;
1659 }
1660
1661 _value = actValue ? true : false;
1662 };
1665 operator bool() const {
1666 return _value;
1667 };
1673 Bool operator=(const bool src) {
1674 _value = src;
1675 return *this;
1676 }
1677
1678
1679 }; // class Bool
1680
1681
1694 class Id : public sds::Id {
1695 private:
1696 bool _readFromFile = false; // Was this read from a file.
1697 bool _defaultUsed = false; // Was this read from the default.
1698 std::string _actualName; // Actual name of file or structure.
1699
1700 void UseDefaultIfReq(const std::string &name,
1701 int position,
1702 const std::string &fileName,
1703 Flags flags,
1705 const std::string &mess);
1706
1707 public:
1712 Id() : sds::Id() { }
1713
1714
1770 Id(
1771 const sds::Id& Id,
1772 const std::string &Name="Argument1",
1773 const int Position=1,
1774 const std::string Default = "",
1775 const Flags flags = Flags::KeepErr)
1776 {
1778 }
1779
1780
1781
1837 Id(
1839 const sds::Id& Id,
1840 const std::string &Name="Argument1",
1841 const int Position=1,
1842 const std::string Default = "",
1843 const Flags flags = Flags::KeepErr)
1844 {
1847 }
1848
1851 virtual ~Id();
1852
1904 virtual void Get( /* Get value from Sds structure */
1905 const sds::Id& Id,
1906 const std::string &Name="Argument1",
1907 const int Position=1,
1908 const std::string Default = "",
1909 const Flags flags = (Flags::KeepErr));
1910
1911
1920 virtual std::string ActualName() const;
1925 virtual bool WasReadFromFile() const;
1926
1932 virtual bool WasReadFromDefault() const;
1933
1934
1935 }; // class Id
1936
1937
1946 class Filename : public String {
1947 //String::String; // Inherit constructors.
1948 public:
1982 Filename( const sds::Id& Id,
1983 const std::string &Name = "Argument1",
1984 const int Position = 1,
1985 const std::string &Default = "",
1986 const Flags flags = Flags::KeepErr) {
1987 this->Get(Id, Name, Position, Default, flags);
1988 }
1989
2024 Filename(
2026 const sds::Id& Id,
2027 const std::string &Name = "Argument1",
2028 const int Position = 1,
2029 const std::string &Default = "",
2030 const Flags flags = Flags::KeepErr) {
2031
2032
2034 this->Get(Id, Name, Position, Default, flags);
2035 }
2036
2037
2041 /*
2042 * From:
2043 * http://codexpert.ro/blog/2013/08/26/inherited-constructors-in-cpp11/
2044 * If in the derived class you add a new specific constructor
2045 * after you use the using directive, you lost the possibility
2046 * of using the default constructor (even though it is in the
2047 * base class). So, if it is needed a specific constructor, you
2048 * need to add a default one, even one using that no-parameter
2049 * base constructor:
2050 */
2052 }
2053
2054
2086 virtual void Get (const sds::Id& Id,
2087 const std::string &Name = "Argument1",
2088 const int Position = 1,
2089 const std::string &Default = "",
2090 const Flags flags = Flags::KeepErr);
2091
2092
2093 }; // class Filename
2094
2095
2096
2103 struct ArgFlagVal {
2104 std::string name;
2105 unsigned flag;
2106 };
2113 using ArgFlagValVector = std::vector<ArgFlagVal>;
2114
2115
2116
2117 /*
2118 * Internal method only.
2119 *
2120 * Used by ArgFlags::Get() to get a given argument as a string, converting
2121 * it to upper case if requested.
2122 *
2123 * Returns the value of the string (converted to upper case if
2124 * requested) or an empty string if the value does not exist. Does
2125 * not throw an exception if the value does not exist.
2126 *
2127 * @param Id The SDS structure to read the flags from
2128 * @param pos Position of the argument to read.
2129 * @param toUpper Do we convert the result to upper case. If
2130 * false, leave as found.
2131 *
2132 * @return The value found. If no value was found, return an empty
2133 * string (does not throw for no value found!)
2134 */
2135 extern std::string _GetString(const sds::Id& Id, unsigned pos, bool toUpper);
2136
2137
2138
2139
2161 template<class ContainerType,
2162 /*
2163 * This complicated bit of code is about ensuring that only containers containing
2164 * a sub-class of "ArgFlagVal" are considered when trying to determine if
2165 * this template function is a valid specialization to use.
2166 *
2167 * A relevant reference is SFINAE ("Substitution Failure Is Not An Error")
2168 * E.g. http://en.cppreference.com/w/cpp/language/sfinae
2169 *
2170 * The problem we are tying to solve is that without this, any type
2171 * could trigger this specialization. Compilation
2172 * would then fail late with a poor error message.
2173 *
2174 * std::enable_if is being used to this template is only used when the
2175 * ContainerType value is a sub-class of ArgFlagVal. The following
2176 * references will help explain this:
2177 * http://www.cplusplus.com/reference/type_traits/enable_if/?kw=enable_if
2178 * http://www.boost.org/doc/libs/1_45_0/libs/utility/enable_if.html
2179 *
2180 * In addition, the use of "typename ContainerType::value_type" is to ensure
2181 * we refer to the actual type of the ContainerType template argument.
2182 * This should also trigger a failure if the container does not have a
2183 * value_type member. Here typename can be used to declare that a
2184 * dependent name is a type.
2185 */
2186 typename std::enable_if<std::is_base_of<ArgFlagVal,
2187 typename ContainerType::value_type>::value>::type* = nullptr>
2188
2189
2190 class ArgFlags {
2191 const ContainerType _validFlags; // Container with set of valid flags
2192 const bool _ignoreCase; // Do we ignore case?
2193 unsigned _theValue = 0; // The mask of flag values.
2194
2195 public:
2210 ArgFlags(const ContainerType &validFlagVals, bool ignoreCase=true) :
2211 _validFlags(validFlagVals), _ignoreCase(ignoreCase) {
2212 }
2242 const sds::Id& Id,
2243 const unsigned First = 1,
2244 const unsigned Last = 0,
2245 const bool FailOnInvalid = true,
2246 const bool IgnoreCase=true) :
2247 _validFlags(validFlagVals), _ignoreCase(IgnoreCase) {
2249 }
2275 unsigned Get(const sds::Id& Id,
2276 const unsigned First = 1,
2277 unsigned Last = 0,
2278 const bool FailOnInvalid = true) {
2279
2280 _theValue = 0; // Clear the value on entry.
2281
2282 if (Last == 0) Last = UINT_MAX;
2283
2284 /*
2285 * Validate arguments.
2286 */
2287 if (First < 1)
2288 {
2290 "ArgFlags First argument position value of % is less then min of 1",
2291 First);
2292 }
2293 if (Last < First)
2294 {
2296 "ArgFlags Last argument position value of % is less then First of %",
2297 Last, First);
2298
2299 }
2300 /*
2301 * If no argument was supplied, then just return 0.
2303 if (!Id) return 0;
2304 /*
2305 * Work through arguments.
2306 */
2307 for (unsigned arg = First; arg < Last ; arg++)
2308 {
2309 /*
2310 * Use this static method to get the actual string
2311 * value - not dependent on the template so
2312 * more efficient compilation.
2313 */
2314 auto thisVal = _GetString(Id, arg, _ignoreCase);
2315
2316 /*
2317 * If this is a null value, we are done.
2318 */
2319 if (thisVal == "")
2320 return _theValue;
2321
2322 /*
2323 * Work through the possible values. If we find
2324 * it, add the relevant flag value to the set of
2325 * values.
2326 */
2327 bool found = false;
2328 for (auto & flag : _validFlags)
2329 {
2330 if (flag.name == thisVal)
2331 {
2332 _theValue |= flag.flag;
2333 found = true;
2334 break;
2335 }
2336 }
2337 if ((!found)&&(FailOnInvalid))
2338 {
2339 //DramaTHROW_S(DRAMA2__GITARG_INVALID_FLAGVAL,
2340 // "Argument value at position %, %, is not an acceptable flag value",
2341 // arg, thisVal);
2342
2343
2346
2347 except.FmtWrite("Argument value at position %, \"%\", is not an acceptable flag value",
2348 arg, thisVal);
2349 except.AddErs();
2350 AddFlagPossiblities(&except);
2351 throw except;
2352
2353
2354 }
2355
2356 }
2357
2358 return _theValue;
2359
2360 }
2370 unsigned GetVal() const {
2371 return _theValue;
2372 }
2380 bool IsSet(unsigned flags) const {
2381 return ((_theValue & flags) == flags);
2382 }
2383 private:
2384 /* Add Flat value possibilities to an exception.
2385 *
2386 * @param except The exception to add the enum values too.
2387 */
2388 void AddFlagPossiblities(drama::Exception *except) {
2389 // We must have the DRAMA lock - otherwise ERS causes problems.
2390 gitarg::___CheckLockTaken(__func__, __FILE__, __LINE__);
2391 std::ostringstream s;
2392
2393 (*except) << "\n Accepted flags are:\n";
2394 s << " ";
2395 for (auto & flag : _validFlags)
2396 {
2397 s << flag.name << ", ";
2398 }
2399 auto str = s.str();
2400 // Remove the trailing ", "
2401 str.pop_back();
2402 str.pop_back();
2403 (*except) << str << '\n';
2404
2405 if (_ignoreCase)
2406 {
2407 (*except) << " Case is ignored.";
2408 }
2409 }
2410
2411 }; // class Flags
2412
2413
2414
2415 } // namespace gitarg
2416
2417} // namespace drama
2418
2419#endif /* define DRAMA2_GITARG_INC */
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:162
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:2302
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:2268
ArgFlags(const ContainerType &validFlagVals, bool ignoreCase=true)
Constructor.
Definition gitarg.hh:2237
bool IsSet(unsigned flags) const
Determines whether the specified flags are set.
Definition gitarg.hh:2407
unsigned GetVal() const
Return the flags value - the mask of set bits.
Definition gitarg.hh:2397
This class is used to check for the existence of one or more flags in an SDS structure.
Definition gitarg.hh:2217
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:1624
Bool operator=(const bool src)
Assign a bool to this gitarg::Bool item.
Definition gitarg.hh:1700
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:1580
virtual const GitLogStrType * Lookup()
Return a pointer to an array of enum strings equivalents.
Definition gitarg.hh:1536
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:1663
virtual ~Bool()
Destructor.
Definition gitarg.hh:1638
Bool(bool initVal=false)
Simple constructor with a default value of false.
Definition gitarg.hh:1544
A class which reads Boolean values from SDS argument structures.
Definition gitarg.hh:1519
virtual ~EnumLookupClass()
Destructor.
Definition gitarg.hh:219
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:190
virtual ~Enum()
Destructor.
Definition gitarg.hh:609
Enum(EnumType InitialValue)
Constructor with initial value supplied.
Definition gitarg.hh:289
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:456
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:505
Enum & operator=(const EnumType &rhs)
Allow an item of the underlying EnumType to be assigned to this object.
Definition gitarg.hh:602
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:366
Enum()
Default constructor for the object.
Definition gitarg.hh:280
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:547
A class which reads Enumerated values from a SDS argument structures.
Definition gitarg.hh:249
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:2051
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:2009
Filename()
Default constructor.
Definition gitarg.hh:2078
A class which reads a file name from an SDS Command argument structures.
Definition gitarg.hh:1973
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:1797
virtual ~Id()
Destructor.
Id()
Default constructor.
Definition gitarg.hh:1739
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:1864
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:1721
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:1032
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:1261
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:1203
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:1071
Int(const long def=DefaultVal)
Simple constructor with a default value specified.
Definition gitarg.hh:1001
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:1118
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:1161
A class which reads integer values from an SDS argument structure.
Definition gitarg.hh:987
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:728
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:923
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:688
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:823
Real(const double def=(double) DefaultVal)
Simple constructor with a default value specified.
Definition gitarg.hh:656
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:865
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:775
A class which reads real values from an SDS argument structure.
Definition gitarg.hh:642
String operator=(const std::string &str)
Assign a std::string to this gitarg::String.
Definition gitarg.hh:1461
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:1389
String(const String &)=default
Copy constructor Default is sufficent.
String()
Default constructor.
Definition gitarg.hh:1420
String operator=(const String &str)
Assign a const std::string to this gitarg::String.
Definition gitarg.hh:1470
String & operator=(char c)
Set this gitarg::String to a string containing a single character.
Definition gitarg.hh:1489
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:1352
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:1479
A class which reads a string item from an SDS structure.
Definition gitarg.hh:1313
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:562
A class which implements a DRAMA Action with runs a thread.
Definition threadaction.hh:199
DRAMA 2 main include file.
#define DramaTHROW_S(status_, format_,...)
Throw a Drama exception with safe string formatting.
Definition exception.hh:108
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:87
Flags
The various flags used in GIT operations.
Definition gitarg.hh:83
@ 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.
constexpr Flags operator|(Flags f1, Flags f2)
Operator to allow Flags values to be or-ed.
Definition gitarg.hh:111
std::vector< ArgFlagVal > ArgFlagValVector
Declare a vector for ArgFlagVal items.
Definition gitarg.hh:2140
bool IsFlagSet(const Flags f1, const Flags f2)
Operator to allow determination of if a Flag enum value set.
Definition gitarg.hh:127
@ Default
System default type.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1327
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
Type used to specify arg/flag relationships to ArgFlags class.
Definition gitarg.hh:2130
DRAMA 2 include file - Code common to DRAMA 2 features supporting threading.