DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
8#pragma once
9
10#include "Exception.h"
11
16namespace Util
17{
23 {
24 protected:
25 constexpr INonCopyable() = default;
26 ~INonCopyable() = default;
27
28 public:
29 INonCopyable(const INonCopyable&) = delete;
31 };
32
38 {
39 protected:
40 constexpr INonMovable() = default;
41 ~INonMovable() = default;
42
43 public:
44 INonMovable(const INonMovable&) = default;
45 INonMovable& operator=(const INonMovable&) = default;
46
49 };
50
55 class ILockable : public INonCopyable
56 {
57 public:
62 static constexpr std::chrono::milliseconds DefaultTimeout = std::chrono::milliseconds(10);
63
64 protected:
65 using MutexType = std::timed_mutex;
66 using LockType = std::unique_lock<MutexType>;
67
68 ILockable() = default;
69 ~ILockable() = default;
70
79 [[nodiscard]] LockType AcquireLock(const std::chrono::milliseconds Timeout = DefaultTimeout) const;
80
81 private:
83 };
84
85 class TimeoutException;
86 template <typename> class SynchronizedPointer;
87
93 {
94 // Every SynchronizedPointer<...> should be friend to allow SynchronizedPointers to derived classes
95 template <typename>
96 friend class SynchronizedPointer;
97
98 protected:
101
102 private:
111 void AcquireLock(const std::chrono::milliseconds Timeout) const
112 {
113 using namespace std::chrono_literals;
114
115 // In order to compensate for spurious failures by retrying
116 // (see https://en.cppreference.com/w/cpp/thread/timed_mutex/try_lock_for)
117 constexpr int NumTries = 2;
118
119 if (OwnerID != std::this_thread::get_id())
120 {
121 if (Timeout == 0ms)
122 LockMutex.lock();
123 else
124 {
125 bool Success = false;
126 auto TimeoutPerTry = Timeout / NumTries;
127 for (auto i = NumTries; i > 0 && !Success; --i)
128 Success = LockMutex.try_lock_for(TimeoutPerTry);
129
130 if (!Success)
131 throw TimeoutException("Timeout occurred while trying to lock a mutex.");
132 }
133
134 OwnerID = std::this_thread::get_id();
135 }
136
137 ++OwnedCount;
138 }
139
144 void ReleaseLock() const
145 {
146 if (!OwnedCount || OwnerID != std::this_thread::get_id())
147 return;
148
149 --OwnedCount;
150 if (!OwnedCount)
151 {
152 OwnerID = std::thread::id();
153 LockMutex.unlock();
154 }
155 }
156
157 mutable std::timed_mutex LockMutex;
158 mutable std::atomic<std::thread::id> OwnerID;
159 mutable std::atomic<size_t> OwnedCount;
160 };
161
168 template <typename T>
170 {
171 template <typename>
173
174 public:
178 SynchronizedPointer() noexcept : LockableObject(nullptr) {}
179
189 const std::chrono::milliseconds Timeout = ILockable::DefaultTimeout)
190 : LockableObject(LockableObject) { if (LockableObject) LockableObject->AcquireLock(Timeout); }
191
197 SynchronizedPointer(SynchronizedPointer&& Other) noexcept : LockableObject(Other.LockableObject) { Other.LockableObject = nullptr; }
198
206 {
208 Other.LockableObject = nullptr;
209
210 return *this;
211 }
212
220 template <typename U>
222 {
223 if (!Other.LockableObject)
224 LockableObject = nullptr;
225 else
226 {
227 LockableObject = dynamic_cast<T*>(Other.LockableObject);
228 if (!LockableObject)
230
231 Other.LockableObject = nullptr;
232 }
233 }
234
236
241 auto get() const noexcept { return LockableObject; }
242
243 bool operator==(const T* rhs) const noexcept { return LockableObject == rhs; }
244 bool operator!=(const T* rhs) const noexcept { return LockableObject != rhs; }
245 bool operator==(const SynchronizedPointer& rhs) const noexcept { return LockableObject == rhs.get(); }
246 bool operator!=(const SynchronizedPointer& rhs) const noexcept { return LockableObject != rhs.get(); }
247 explicit operator bool() const noexcept { return LockableObject != nullptr; }
248
249 auto operator->() const noexcept { return LockableObject; }
250 auto& operator*() const noexcept { return *LockableObject; }
251
252 private:
257 };
258
265 {
266 public:
269
279 bool Wait(const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0));
280
281 void Notify();
282 void Ignore();
283
284 private:
287 std::atomic<bool> MutexCanBeDestroyed;
288
289 std::mutex Mutex;
290 std::condition_variable ConditionVariable;
291 };
292
296 template <typename T, typename... ListTs>
297 struct is_contained_in : std::disjunction<std::is_same<T, ListTs>...> {};
298
302 template <typename T, typename... ListTs>
303 inline constexpr bool is_contained_in_v = is_contained_in<T, ListTs...>::value;
304
311 template <typename CallableT>
313
317 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
318 struct member_fn_ptr_traits<ReturnT (ObjectT::*)(ArgumentTs...) const>
319 {
320 using return_type = ReturnT;
321 using instance_type = ObjectT;
322 using argument_types = std::tuple<ArgumentTs...>;
323 };
324
328 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
329 struct member_fn_ptr_traits<ReturnT(ObjectT::*)(ArgumentTs...) noexcept>
330 {
331 using return_type = ReturnT;
332 using instance_type = ObjectT;
333 using argument_types = std::tuple<ArgumentTs...>;
334 };
335
339 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
340 struct member_fn_ptr_traits<ReturnT(ObjectT::*)(ArgumentTs...) const noexcept>
341 {
342 using return_type = ReturnT;
343 using instance_type = ObjectT;
344 using argument_types = std::tuple<ArgumentTs...>;
345 };
346
350 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
351 struct member_fn_ptr_traits<ReturnT (ObjectT::*)(ArgumentTs...)>
352 {
353 using return_type = ReturnT;
354 using instance_type = ObjectT;
355 using argument_types = std::tuple<ArgumentTs...>;
356 };
357
361 template <typename CallableT>
363
367 template <typename CallableT>
369
373 template <typename CallableT>
375
379 template <typename TupleT>
381
385 template <typename FirstElementT, typename... ElementTs>
386 struct remove_first_from_tuple<std::tuple<FirstElementT, ElementTs...>> { using type = std::tuple<ElementTs...>; };
387
391 template <typename TupleT>
393
394 // Index sequence manipulation to define a starting point
395
401 template <size_t Offset, typename IndexSequence>
403
407 template <size_t Offset, size_t... Indices>
408 struct OffsetIndexSequence<Offset, std::index_sequence<Indices...>>
409 {
413 using type = std::index_sequence<Indices + Offset...>;
414 };
415
419 template <size_t Offset, typename IndexSequence>
421
427 template <size_t From, size_t To>
429 {
430 using type = OffsetIndexSequence_t<From, std::make_index_sequence<To - From>>;
431 };
432
436 template <size_t From, size_t To>
438
446 template <typename ObjectT, typename CallableT>
448 {
450
451 public:
459 constexpr CallableMemberWrapper(ObjectT& Object, const CallableT Callable, ArgumentTs DefaultArgs = {}) noexcept
461
469 template <typename... ArgTs>
470 auto operator()(ArgTs&& ...Args) const
471 {
472 return Invoke(RangeIndexSequence_t<sizeof...(ArgTs), std::tuple_size_v<ArgumentTs>>(), std::forward<ArgTs>(Args)...);
473 }
474
475 private:
476 template <size_t... Indices, typename... ArgTs>
477 auto Invoke(std::integer_sequence<size_t, Indices...>, ArgTs&& ...Args) const
478 {
479 return (Object.*Callable)(std::forward<ArgTs>(Args)..., std::get<Indices>(DefaultArgs)...);
480 }
481
482 ObjectT& Object;
483 const CallableT Callable;
485 };
486
492 template <typename ObjectT, typename CallableT>
494 {
495 public:
503 template <typename... ArgTs>
504 OnDestruction(ObjectT& Object, const CallableT Callable, ArgTs&& ...Args)
505 : CallableWrapper(Object, std::move(Callable), { std::forward<ArgTs>(Args)... }) {}
506
508
509 private:
511 };
512
517 {
518 public:
519 using DataType = unsigned char[];
520
521 private:
522 using DataPtrType = std::unique_ptr<DataType>;
523
524 public:
525 BlobDataType() = default;
526 BlobDataType(const BlobDataType& Other);
527 BlobDataType(BlobDataType&& Other) noexcept;
528
529 BlobDataType& operator=(const BlobDataType& Other);
530 BlobDataType& operator=(BlobDataType&& Other) noexcept;
531
532 void Reserve(size_t Size);
533 void Assign(size_t Size, const DataType Data);
534 void Reset();
535 DataPtrType::element_type* Release() noexcept;
536 auto GetPtr() noexcept { return DataPtr.get(); }
537 auto Size() const noexcept { return DataSize; }
538
539 private:
541 size_t DataSize = 0;
542 };
543
549 {
550 public:
554 enum class Values { Unknown, False, True };
555
556 constexpr OptionalBool() noexcept : Value(Values::Unknown) {}
557 constexpr OptionalBool(Values Value) noexcept : Value(Value) {}
558 constexpr OptionalBool(bool b) noexcept : Value(b ? Values::True : Values::False) {}
559 constexpr OptionalBool(const OptionalBool& Other) noexcept : Value(Other.Value) {}
560
561 constexpr OptionalBool& operator=(Values Value) noexcept { this->Value = Value; return *this; }
562 constexpr OptionalBool& operator=(bool b) noexcept { Value = b ? Values::True : Values::False; return *this; }
563 constexpr OptionalBool& operator=(OptionalBool& Other) noexcept { Value = Other.Value; return *this; }
564
565 constexpr bool operator==(Values Value) const noexcept { return this->Value == Value; }
566 constexpr bool operator!=(Values Value) const noexcept { return this->Value != Value; }
567
568 constexpr operator bool() const noexcept { return Value == Values::True; }
569 constexpr Values Get() const noexcept { return Value; }
570
571 private:
573 };
574
579 {
580 public:
587 template <typename T>
588 static size_t Get() noexcept
589 {
590 static const size_t ID = Make();
591
592 return ID;
593 }
594
595 private:
600 static size_t Make() noexcept;
601 };
602
610 template <typename T>
611 inline void HashCombine(std::size_t& seed, const T& value)
612 {
613 std::hash<T> hasher;
614 seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
615 }
616
621 using seconds = std::chrono::duration<double>;
622 using picoseconds = std::chrono::duration<double, std::pico>;
623
627 static constexpr double SpeedOfLight = (GSL_CONST_MKSA_SPEED_OF_LIGHT);
628
635 constexpr auto ConvertFrequencyWavelength(double Value) noexcept { return SpeedOfLight / Value; }
637
642
650 template <typename T>
651 std::ostream& operator<<(std::ostream& stream, const std::chrono::time_point<T>& TimePoint)
652 {
653 const auto ZonedTime = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::round<std::chrono::seconds>(TimePoint));
654 stream << std::format("{:%T %d.%m.%Y}", ZonedTime);
655
656 return stream;
657 }
658
666 template <typename T>
667 T StrToT(const std::string& String)
668 {
669 std::stringstream ss(String);
670 T Value;
671 ss >> Value;
672
673 if (ss.fail())
674 throw InvalidDataException("String cannot be converted to " + std::string(typeid(T).name()) + ".");
675
676 return Value;
677 }
678
687 template <typename T>
688 std::string ToStr(const T& Value, int Precision = -1)
689 {
690 std::stringstream ss;
691
692 if (Precision >= 0)
693 ss << std::fixed << std::setprecision(Precision);
694
695 ss << Value;
696 return ss.str();
697 }
698
705 template <typename T>
706 std::string ToStr(const std::chrono::time_point<T>& TimePoint)
707 {
708 std::stringstream ss;
709
710 Util::operator<<(ss, TimePoint);
711 return ss.str();
712 }
713
719 inline std::string ToStr(const char Value) { return ToStr(static_cast<int>(Value)); }
720
724 inline std::string ToStr(const uint8_t Value) { return ToStr(static_cast<int>(Value)); }
725
731 inline std::string ToStr(const QString& Str) { return Str.toStdString(); }
732
746 template <typename ToT, typename FromT, std::enable_if_t<
747 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
748 std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>>, int> = 0
749 >
750 inline ToT NumToT(const FromT Value)
751 {
752 return Value;
753 }
754
758 template <typename ToT, typename FromT, std::enable_if_t<
759 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
760 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
761 ((std::is_signed_v<ToT> && std::is_signed_v<FromT>) || (std::is_unsigned_v<ToT> && std::is_unsigned_v<FromT>)), int> = 0
762 >
763 ToT NumToT(const FromT Value)
764 {
765 if (Value < std::numeric_limits<ToT>::lowest() || Value > std::numeric_limits<ToT>::max())
766 throw OutOfRangeException("Cannot convert Value into destiny type since this would cause an underflow or an overflow.");
767
768 return static_cast<ToT>(Value);
769 }
770
774 template <typename ToT, typename FromT, std::enable_if_t<
775 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
776 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
777 std::is_signed_v<ToT> && std::is_unsigned_v<FromT>, int> = 0
778 >
779 ToT NumToT(const FromT Value)
780 {
781 if (Value > static_cast<std::make_unsigned_t<ToT>>(std::numeric_limits<ToT>::max()))
782 throw OverflowException("Cannot convert Value into destiny type since this would cause an overflow.");
783
784 return static_cast<ToT>(Value);
785 }
786
790 template <typename ToT, typename FromT, std::enable_if_t<
791 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
792 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
793 std::is_unsigned_v<ToT> && std::is_signed_v<FromT>, int> = 0
794 >
795 ToT NumToT(const FromT Value)
796 {
797 if (Value < 0)
798 throw UnderflowException("Cannot convert Value into destiny type since this would cause an underflow.");
799 if (static_cast<std::make_unsigned_t<FromT>>(Value) > std::numeric_limits<ToT>::max())
800 throw OverflowException("Cannot convert Value into destiny type since this would cause an overflow.");
801
802 return static_cast<ToT>(Value);
803 }
804
808 template <typename ToT, std::enable_if_t<
809 std::is_integral_v<ToT> &&
810 !std::is_same_v<std::remove_cv_t<ToT>, double>, int> = 0
811 >
812 ToT NumToT(const double Value)
813 {
814 const double RoundedValue = std::round(Value);
815
816 if (RoundedValue < static_cast<double>(std::numeric_limits<ToT>::lowest()))
817 throw UnderflowException("Cannot convert Value into double since this would cause an underflow.");
818 if (RoundedValue > static_cast<double>(std::numeric_limits<ToT>::max()))
819 throw OverflowException("Cannot convert Value into double since this would cause an overflow.");
820
821 return static_cast<ToT>(RoundedValue);
822 }
823
830 template <typename T>
831 inline std::string ToUnitStr();
832
836 template <>
838 {
839 return "s";
840 }
841
845 template <>
847 {
848 return "ms";
849 }
850
854 template <>
856 {
857 return "us";
858 }
859
863 template <>
865 {
866 return "ns";
867 }
868
872 template <>
873 inline std::string ToUnitStr<seconds>()
874 {
875 return "s";
876 }
877
881 template <>
882 inline std::string ToUnitStr<picoseconds>()
883 {
884 return "ps";
885 }
887
893 inline std::string TrimTrailingZeros(const std::string& Str) { return Str.substr(0, Str.find('\0')); }
894
899 inline auto CurrentTimeAndDateString() { return ToStr(std::chrono::system_clock::now()); }
900
906 inline auto FilenameFromPath(std::string Path) { return Path.substr(Path.find_last_of("\\") + 1, Path.length() - Path.find_last_of("\\") - 1); }
907
913 inline auto RemoveExtFromPath(std::string Path) { return Path.substr(0, Path.find_last_of(".")); }
914
919 {
920 unsigned int Major{};
921 unsigned int Minor{};
922 unsigned int Patch{};
923 };
924
931 std::strong_ordering operator<=>(const VersionType& lhs, const VersionType& rhs);
932
939 VersionType VersionFromString(std::string_view Str);
940
946 inline std::string ToStr(const VersionType& Version) { return ToStr(Version.Major) + "." + ToStr(Version.Minor) + "." + ToStr(Version.Patch); }
947
957 template <typename... Ts>
958 std::vector<std::tuple<Ts...>> ParseCSV(const std::string& CSVData, const char Delimiter = ';', const size_t SkipLines = 0)
959 {
960 std::vector<std::tuple<Ts...>> ParsedLines;
961 std::istringstream CSVDataStream(CSVData);
962
963 // Ignore header lines
964 for (auto i = SkipLines; i > 0; --i)
965 CSVDataStream.ignore(std::numeric_limits<std::streamsize>::max(), CSVDataStream.widen('\n'));
966
967 // Function to parse one field from a single line
968 const auto GetValue = [Delimiter]<typename T>(std::istringstream& LineStream) {
969 std::string ValueStr;
970 std::getline(LineStream, ValueStr, Delimiter);
971 std::istringstream ValueStream(ValueStr);
972 ValueStream.exceptions(std::istringstream::failbit | std::istringstream::badbit);
973
974 T Value;
975 ValueStream >> Value;
976
977 return Value;
978 };
979
980 // Loop through each line and fill ParsedLines with tuples of column data.
981 std::string Line;
982 while (std::getline(CSVDataStream, Line))
983 {
984 std::istringstream LineStream(Line);
985 LineStream.exceptions(std::istringstream::failbit | std::istringstream::badbit);
986
987 // Braced initialization to ensure correct evaluation order (left to right). Refer to
988 // https://stackoverflow.com/questions/14056000/how-to-avoid-undefined-execution-order-for-the-constructors-when-using-stdmake
989 ParsedLines.push_back({ GetValue.template operator()<Ts>(LineStream)... });
990 }
991
992 return ParsedLines;
993 }
994
1001 std::string ExceptionToStr(const std::exception_ptr ExceptionPtr);
1002
1008 std::string ToLower(std::string_view Str);
1009
1019 std::vector<std::complex<double>> FFT(const std::vector<std::complex<double>>& Data, bool InverseTransform = false);
1020
1025 class Warning : public ILockable
1026 {
1027 public:
1033 {
1037 WarningData() : ErrorCode(DynExpErrorCodes::NoError), Line(0) {}
1038
1039 WarningData(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1040 const std::source_location Location = std::source_location::current())
1041 : Description(std::move(Description)), ErrorCode(ErrorCode),
1042 Line(Location.line()), Function(Location.function_name()), File(Location.file_name()) {}
1043 WarningData(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1044 const size_t Line = 0, std::string Function = "", std::string File = "")
1045 : Description(std::move(Description)), ErrorCode(ErrorCode),
1046 Line(Line), Function(std::move(Function)), File(std::move(File)) {}
1047
1048 explicit operator bool() const noexcept { return ErrorCode != DynExpErrorCodes::NoError; }
1049
1050 const std::string Description;
1051 const int ErrorCode;
1052 const size_t Line;
1053 const std::string Function;
1054 const std::string File;
1055 };
1056
1060 Warning() : Data(std::make_unique<WarningData>()) {}
1061
1068 Warning(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1069 const std::source_location Location = std::source_location::current())
1070 : Data(std::make_unique<WarningData>(std::move(Description), ErrorCode, Location)) {}
1071
1077 : Data(std::make_unique<WarningData>(e.what(), e.ErrorCode, e.Line, e.Function, e.File)) {}
1078
1083 Warning(Warning&& Other) noexcept;
1084
1085 virtual ~Warning() = default;
1086
1087 void Reset();
1088
1089 Warning& operator=(const Exception& e);
1090 Warning& operator=(Warning&& Other) noexcept;
1091
1092 WarningData Get() const;
1093
1094 private:
1098 std::unique_ptr<WarningData> Data;
1099 };
1100
1105 {
1106 LogEntry(std::string Message, ErrorType Type, std::chrono::system_clock::time_point TimePoint)
1107 : Message(std::move(Message)), Type(Type), TimePoint(TimePoint) {}
1108
1109 const std::string Message;
1111 const std::chrono::system_clock::time_point TimePoint;
1112 };
1113
1120 class EventLogger : public ILockable
1121 {
1122 friend EventLogger& EventLog();
1123
1128 EventLogger();
1129
1134 EventLogger(std::string Filename) : EventLogger() { OpenLogFile(Filename); }
1135
1136 public:
1140 ~EventLogger() { CloseLogFileUnsafe(); }
1141
1148
1158 void Log(const std::string& Message, const ErrorType Type = ErrorType::Info,
1159 const size_t Line = 0, const std::string& Function = "", const std::string& File = "", const int ErrorCode = 0
1161 , const std::stacktrace& Trace = {}
1162#endif // DYNEXP_HAS_STACKTRACE
1163 ) noexcept;
1164
1169 void Log(const Exception& E) noexcept;
1170
1175 void Log(const Warning& W) noexcept;
1177
1188 static std::string FormatLog(const std::string& Message, const size_t Line = 0,
1189 const std::string& Function = "", const std::string& Filename = "", const int ErrorCode = 0, const bool PrefixMessage = true);
1190
1203 static std::string FormatLogHTML(const std::string& Message, const ErrorType Type = ErrorType::Info,
1204 const size_t Line = 0, const std::string& Function = "", const std::string& Filename = "", const int ErrorCode = 0
1206 , const std::stacktrace& Trace = {}
1207#endif // DYNEXP_HAS_STACKTRACE
1208 );
1209
1214 void OpenLogFile(std::string Filename);
1215
1219 void CloseLogFile() { auto lock = AcquireLock(LogOperationTimeout); CloseLogFileUnsafe(); }
1220
1225 bool IsOpen() const { auto lock = AcquireLock(LogOperationTimeout); return IsOpenUnsafe(); }
1226
1231 std::string GetLogFilename() const { auto lock = AcquireLock(LogOperationTimeout); return Filename; }
1232
1236 void ClearLog() { auto lock = AcquireLock(LogOperationTimeout); ClearLogUnsafe(); }
1237
1244 std::vector<LogEntry> GetLog(size_t FirstElement = 0) const;
1245
1250 auto GetLogSize() const { auto lock = AcquireLock(LogOperationTimeout); return LogEntries.size(); }
1251
1252 private:
1258 bool IsOpenUnsafe() const { return LogFile.is_open(); }
1259 void CloseLogFileUnsafe();
1260 void ClearLogUnsafe() { LogEntries.clear(); }
1262
1267 static constexpr auto LogOperationTimeout = std::chrono::milliseconds(100);
1268
1269 std::ofstream LogFile;
1270 std::string Filename;
1271
1272 std::vector<LogEntry> LogEntries;
1273 };
1274
1282
1289 template <typename EnumType, std::enable_if_t<
1290 std::is_enum_v<EnumType>, int> = 0
1291 >
1293 {
1294 public:
1298 constexpr FeatureTester() noexcept = default;
1299
1305 template <size_t N>
1306 FeatureTester(const std::array<EnumType, N>& Flags)
1307 {
1308 for (const auto Flag : Flags)
1309 Set(Flag);
1310 }
1311
1318 template <size_t N>
1319 bool Test(const std::array<EnumType, N>& Flags) const
1320 {
1321 for (const auto Flag : Flags)
1322 {
1323 auto Result = Features.test(static_cast<size_t>(Flag));
1324
1325 if (!Result)
1326 false;
1327 }
1328
1329 return true;
1330 }
1331
1337 bool Test(EnumType Flag) const { return Features.test(static_cast<size_t>(Flag)); }
1338
1343 void Set(EnumType Flag) { Features.set(static_cast<size_t>(Flag)); }
1344
1345 private:
1349 std::bitset<static_cast<size_t>(EnumType::NUM_ELEMENTS)> Features;
1350 };
1351
1362 template <
1363 typename CallableT,
1364 std::enable_if_t<std::is_enum_v<return_of_t<CallableT>>, int> = 0
1365 >
1367 {
1368 public:
1370 using CallableType = CallableT;
1371
1379 constexpr StateMachineState(StateEnumType State, CallableT StateFunction, const char* Description = "", const bool IsFinal = false) noexcept
1380 : State(State), StateFunction(StateFunction), Description(Description), Final(IsFinal)
1381 {}
1382
1383 constexpr StateEnumType GetState() const noexcept { return State; }
1384 constexpr auto GetDescription() const noexcept { return Description; }
1385 constexpr bool IsFinal() const noexcept { return Final; }
1386
1395 template <typename... ArgTs>
1396 StateEnumType Invoke(instance_of_t<CallableT>& Instance, ArgTs&&... Args) const
1397 {
1398 return (Instance.*StateFunction)(std::forward<ArgTs>(Args)...);
1399 }
1400
1401 private:
1403 const std::decay_t<CallableT> StateFunction;
1404 const char* Description;
1405
1410 const bool Final;
1411 };
1412
1422 template <typename StateMachineStateT>
1424 {
1425 public:
1426 using StateType = StateMachineStateT;
1427 using StateEnumType = typename StateType::StateEnumType;
1428 using ReplacementListType = std::unordered_map<StateEnumType, StateEnumType>;
1429
1434
1445 StateMachineContext(ReplacementListType&& ReplacementList, const char* Description = "",
1446 std::initializer_list<const StateMachineContext*> BaseContexts = {})
1447 : ReplacementList(std::move(ReplacementList)), Description(Description)
1448 {
1449 for (auto BaseContext : BaseContexts)
1450 if (BaseContext)
1451 this->ReplacementList.insert(BaseContext->ReplacementList.cbegin(), BaseContext->ReplacementList.cend());
1452 }
1453
1458 constexpr auto GetDescription() const noexcept { return Description; }
1459
1467 {
1468 auto AdaptedState = ReplacementList.find(State);
1469
1470 return AdaptedState == ReplacementList.cend() ? State : AdaptedState->second;
1471 }
1472
1473 private:
1479
1480 const char* Description;
1481 };
1482
1495 template <typename StateMachineStateT>
1497 {
1498 public:
1499 using StateType = StateMachineStateT;
1500 using StateEnumType = typename StateType::StateEnumType;
1502
1511 template <typename... StateMachineStateTs>
1512 StateMachine(const StateType& InitialState, const StateMachineStateTs&... States)
1513 : StatesList{ { InitialState.GetState(), &InitialState }, { States.GetState(), &States }... },
1514 CurrentState(&InitialState), CurrentContext(nullptr)
1515 {}
1516
1517 const StateType* GetCurrentState() const noexcept { return CurrentState; }
1518 const ContextType* GetContext() const noexcept { return CurrentContext; }
1519
1526 {
1527 if (CurrentContext)
1528 CurrentState = StatesList.at(CurrentContext.load()->AdaptState(NewState));
1529 else
1530 CurrentState = StatesList.at(NewState);
1531 }
1532
1537 void SetContext(const ContextType* NewContext) { CurrentContext = NewContext; }
1538
1542 void ResetContext() { CurrentContext = nullptr; }
1543
1553 template <typename... ArgTs>
1555 {
1556 if (!CurrentState)
1557 throw InvalidStateException("CurrentState must not be nullptr in order to be invoked.");
1558
1559 if (CurrentState.load()->IsFinal())
1560 CurrentState.load()->Invoke(Instance, std::forward<ArgTs>(Args)...);
1561 else
1562 SetCurrentState(CurrentState.load()->Invoke(Instance, std::forward<ArgTs>(Args)...));
1563 }
1564
1565 private:
1570 const std::unordered_map<StateEnumType, const StateType*> StatesList;
1571
1577 std::atomic<const StateType*> CurrentState;
1578 std::atomic<const ContextType*> CurrentContext;
1580 };
1581}
Provides exception type and error definitions used by DynExp.
Data type which manages a binary large object. The reserved memory is freed upon destruction.
Definition Util.h:517
void Reserve(size_t Size)
Reserves Size bytes of memory freeing any previously reserved memory.
Definition Util.cpp:118
size_t DataSize
Size of the stored data in bytes.
Definition Util.h:541
unsigned char[] DataType
Type of the buffer's data.
Definition Util.h:519
DataPtrType::element_type * Release() noexcept
Releases ownership of the stored buffer returning a pointer to it and leaving this instance empty.
Definition Util.cpp:143
std::unique_ptr< DataType > DataPtrType
Type of the underlying smart pointer managing the buffer.
Definition Util.h:522
DataPtrType DataPtr
Pointer to the buffer.
Definition Util.h:540
auto Size() const noexcept
Returns the size of the stored data in bytes.
Definition Util.h:537
void Reset()
Frees any reserved memory.
Definition Util.cpp:137
BlobDataType()=default
Constructs an empty object.
auto GetPtr() noexcept
Returns a pointer to the stored buffer.
Definition Util.h:536
void Assign(size_t Size, const DataType Data)
Copies Size bytes from Data to the buffer freeing any previously reserved memory.
Definition Util.cpp:131
BlobDataType & operator=(const BlobDataType &Other)
Copy-assigns data from Other.
Definition Util.cpp:101
Wraps a member function of some object and stores its default arguments. Moving from CallableMemberWr...
Definition Util.h:448
auto operator()(ArgTs &&...Args) const
Invokes the stored member function. If arguments are passed, they are are forwarded instead of the st...
Definition Util.h:470
argument_of_t< CallableT > ArgumentTs
Definition Util.h:449
constexpr CallableMemberWrapper(ObjectT &Object, const CallableT Callable, ArgumentTs DefaultArgs={}) noexcept
Constructs a CallableMemberWrapper instance.
Definition Util.h:459
ObjectT & Object
Instance of class Callable belongs to. Callable is invoked on this instance.
Definition Util.h:482
auto Invoke(std::integer_sequence< size_t, Indices... >, ArgTs &&...Args) const
Definition Util.h:477
const ArgumentTs DefaultArgs
Default arguments to be passed when invoking operator() with less arguments Callable expects.
Definition Util.h:484
const CallableT Callable
Pointer to class member function to be invoked.
Definition Util.h:483
Logs events like errors and writes them immediately to a HTML file in a human-readable format....
Definition Util.h:1121
bool IsOpenUnsafe() const
Definition Util.h:1258
void CloseLogFile()
Closes the log file on disk and writes terminating HTML tags.
Definition Util.h:1219
EventLogger(std::string Filename)
Constructs the event logger with opening a log file on disk.
Definition Util.h:1134
std::string GetLogFilename() const
Determines the full file path to the currently openend log file.
Definition Util.h:1231
auto GetLogSize() const
Determines the number of entries in the internal event log.
Definition Util.h:1250
std::ofstream LogFile
Stream object to write to the log file on disk.
Definition Util.h:1269
std::string Filename
Filename and path to the log file on disk.
Definition Util.h:1270
~EventLogger()
Destructor closes the log file on disk.
Definition Util.h:1140
void ClearLog()
Clears the internal event log.
Definition Util.h:1236
std::vector< LogEntry > LogEntries
Internally stored log entries.
Definition Util.h:1272
void ClearLogUnsafe()
Definition Util.h:1260
bool IsOpen() const
Determines whether the log file has been openend on disk.
Definition Util.h:1225
DynExp exceptions are derived from this class. It contains basic information about the cause of the e...
Definition Exception.h:51
Holds a bitset containing flags to indicate which features a certain instrument/ module etc....
Definition Util.h:1293
constexpr FeatureTester() noexcept=default
Constructs a FeatureTester instance with no flags set.
void Set(EnumType Flag)
Sets a flag.
Definition Util.h:1343
bool Test(const std::array< EnumType, N > &Flags) const
Tests whether all of the flags passed as an array are set.
Definition Util.h:1319
std::bitset< static_cast< size_t >(EnumType::NUM_ELEMENTS)> Features
Bitset containing the flags and their states.
Definition Util.h:1349
bool Test(EnumType Flag) const
Tests whether a single flag is set.
Definition Util.h:1337
Interface to allow synchronizing the access to derived classes between different threads by providing...
Definition Util.h:56
ILockable()=default
LockType AcquireLock(const std::chrono::milliseconds Timeout=DefaultTimeout) const
Locks the internal mutex. Blocks until the mutex is locked or until the timeout duration is exceeded.
Definition Util.cpp:8
std::timed_mutex MutexType
Definition Util.h:65
std::unique_lock< MutexType > LockType
Definition Util.h:66
MutexType LockMutex
Internal mutex used for locking.
Definition Util.h:82
static constexpr std::chrono::milliseconds DefaultTimeout
Duration which is used as a default timeout within all methods of this class if no different duration...
Definition Util.h:62
~ILockable()=default
Interface to delete copy constructor and copy assignment operator and thus make derived classes non-c...
Definition Util.h:23
constexpr INonCopyable()=default
INonCopyable & operator=(const INonCopyable &)=delete
~INonCopyable()=default
INonCopyable(const INonCopyable &)=delete
Interface to delete move constructor and move assignment operator and thus make derived classes non-m...
Definition Util.h:38
INonMovable(const INonMovable &)=default
~INonMovable()=default
INonMovable(INonMovable &&)=delete
INonMovable & operator=(const INonMovable &)=default
constexpr INonMovable()=default
INonMovable & operator=(INonMovable &&)=delete
Interface to allow synchronizing the access to derived classes between different threads by making th...
Definition Util.h:93
std::timed_mutex LockMutex
Internal mutex used for locking.
Definition Util.h:157
void ReleaseLock() const
Releases the internal mutex. Does nothing if the mutex was not locked or if the calling thread is not...
Definition Util.h:144
~ISynchronizedPointerLockable()
Object should never be destroyed before completely unlocked.
Definition Util.h:100
std::atomic< size_t > OwnedCount
Counts the lock requests of the current owning thread.
Definition Util.h:159
std::atomic< std::thread::id > OwnerID
ID of the thread which currently owns the internal mutex.
Definition Util.h:158
void AcquireLock(const std::chrono::milliseconds Timeout) const
Locks the internal mutex. Blocks until the mutex is locked or until the timeout duration is exceeded....
Definition Util.h:111
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition Exception.h:164
An operation cannot be performed currently since the related object is in an invalid state like an er...
Definition Exception.h:151
Holds a CallableMemberWrapper and invokes its callable when being destroyed.
Definition Util.h:494
CallableMemberWrapper< ObjectT, CallableT > CallableWrapper
Definition Util.h:510
OnDestruction(ObjectT &Object, const CallableT Callable, ArgTs &&...Args)
Constructs a OnDestruction instance which calls Callable upon destruction of this instance.
Definition Util.h:504
Helper class to communicate flags between different threads based on a condition variable and a mutex...
Definition Util.h:265
std::condition_variable ConditionVariable
Definition Util.h:290
std::atomic< bool > MutexCanBeDestroyed
Definition Util.h:287
bool Wait(const std::chrono::milliseconds Timeout=std::chrono::milliseconds(0))
Makes current thread wait until it is notified or until given timeout duration is exceeded....
Definition Util.cpp:39
std::mutex Mutex
Definition Util.h:289
void Notify()
Set notification to stop waiting (sets EventOccurred to true).
Definition Util.cpp:69
void Ignore()
Ignore last notification (sets EventOccurred to false).
Definition Util.cpp:79
Data type which stores an optional bool value (unknown, false, true). The type evaluates to bool whil...
Definition Util.h:549
Values
Possible values. Values::Unknown evaluates to false.
Definition Util.h:554
constexpr OptionalBool(bool b) noexcept
Contructs an instance holding b.
Definition Util.h:558
constexpr OptionalBool(const OptionalBool &Other) noexcept
Contructs a copy of Other.
Definition Util.h:559
constexpr OptionalBool(Values Value) noexcept
Contructs an instance holding Value.
Definition Util.h:557
constexpr bool operator!=(Values Value) const noexcept
Returns false when Value matches stored value, true otherwise.
Definition Util.h:566
constexpr bool operator==(Values Value) const noexcept
Returns true when Value matches stored value, false otherwise.
Definition Util.h:565
constexpr OptionalBool & operator=(Values Value) noexcept
Assigns Value, returns reference to this.
Definition Util.h:561
constexpr OptionalBool() noexcept
Contructs an instance holding Values::Unknown.
Definition Util.h:556
constexpr OptionalBool & operator=(OptionalBool &Other) noexcept
Assigns value of Other, returns reference to this.
Definition Util.h:563
Values Value
Internal value.
Definition Util.h:572
constexpr Values Get() const noexcept
Returns internal value.
Definition Util.h:569
constexpr OptionalBool & operator=(bool b) noexcept
Assigns b, returns reference to this.
Definition Util.h:562
Thrown when a numeric operation would result in an overflow (e.g. due to incompatible data types)
Definition Exception.h:200
State machine context as used by class StateMachine. A state machine context holds a map with keys an...
Definition Util.h:1424
typename StateType::StateEnumType StateEnumType
Refer to class StateMachineState.
Definition Util.h:1427
StateEnumType AdaptState(StateEnumType State) const
Checks whether the context contains a replacement entry for the state identified by State and returns...
Definition Util.h:1466
const char * Description
Definition Util.h:1480
std::unordered_map< StateEnumType, StateEnumType > ReplacementListType
Definition Util.h:1428
constexpr auto GetDescription() const noexcept
Returns the context's description.
Definition Util.h:1458
StateMachineStateT StateType
Definition Util.h:1426
ReplacementListType ReplacementList
Within this context, the map's key states are replaced by the corresponding value states....
Definition Util.h:1478
StateMachineContext()=default
Default constructor constructs an empty context not performing any state replacement.
StateMachineContext(ReplacementListType &&ReplacementList, const char *Description="", std::initializer_list< const StateMachineContext * > BaseContexts={})
Constructs a StateMachineContext from a replacement list appending the replacement lists of each cont...
Definition Util.h:1445
State machine state as used by class StateMachine. A state mainly wraps a state function of the membe...
Definition Util.h:1367
const StateEnumType State
Definition Util.h:1402
CallableT CallableType
Definition Util.h:1370
const char * Description
Definition Util.h:1404
StateEnumType Invoke(instance_of_t< CallableT > &Instance, ArgTs &&... Args) const
Invokes the state function associated with this state on an instance of the class the state function ...
Definition Util.h:1396
const bool Final
For final states, it is ensured that the state's state function can delete the state machine....
Definition Util.h:1410
return_of_t< CallableT > StateEnumType
Definition Util.h:1369
constexpr StateEnumType GetState() const noexcept
Returns the state's unique identifier.
Definition Util.h:1383
const std::decay_t< CallableT > StateFunction
Definition Util.h:1403
constexpr auto GetDescription() const noexcept
Returns the state's description.
Definition Util.h:1384
constexpr StateMachineState(StateEnumType State, CallableT StateFunction, const char *Description="", const bool IsFinal=false) noexcept
Constructs a state machine state and assigns fixed parameters to it.
Definition Util.h:1379
constexpr bool IsFinal() const noexcept
Returns whether this is a final state.
Definition Util.h:1385
This class models a state machine. It keeps track of the current state and allows to invoke its assoc...
Definition Util.h:1497
std::atomic< const StateType * > CurrentState
Definition Util.h:1577
void Invoke(instance_of_t< typename StateType::CallableType > &Instance, ArgTs &&... Args)
Invokes the state function associated with the current state machine state on an instance of the clas...
Definition Util.h:1554
void SetContext(const ContextType *NewContext)
Sets the current state machine context.
Definition Util.h:1537
StateMachineStateT StateType
Definition Util.h:1499
void ResetContext()
Removes the current state machine context.
Definition Util.h:1542
void SetCurrentState(StateEnumType NewState)
Sets the current state as identified by an element from StateEnumType.
Definition Util.h:1525
StateMachine(const StateType &InitialState, const StateMachineStateTs &... States)
Constructs a state machine assigning possible states to it. Automatically also adds InitialState,...
Definition Util.h:1512
typename StateType::StateEnumType StateEnumType
Refer to class StateMachineState.
Definition Util.h:1500
const StateType * GetCurrentState() const noexcept
Returns a pointer to the current state.
Definition Util.h:1517
std::atomic< const ContextType * > CurrentContext
Definition Util.h:1578
const std::unordered_map< StateEnumType, const StateType * > StatesList
Map of possible states. All states are uniquely identified by an element from StateEnumType....
Definition Util.h:1570
const ContextType * GetContext() const noexcept
Returns a pointer to the current context.
Definition Util.h:1518
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition Util.h:170
bool operator!=(const T *rhs) const noexcept
Definition Util.h:244
SynchronizedPointer(SynchronizedPointer< U > &&Other)
Moves the LockableObject from a SynchronizedPointer<U> of another type U to a new instance of Synchro...
Definition Util.h:221
SynchronizedPointer(T *const LockableObject, const std::chrono::milliseconds Timeout=ILockable::DefaultTimeout)
Constructs a pointer locking LockableObject. Blocks until LockableObject's mutex is locked or until t...
Definition Util.h:188
bool operator==(const SynchronizedPointer &rhs) const noexcept
Definition Util.h:245
SynchronizedPointer & operator=(SynchronizedPointer &&Other) noexcept
Move-assigns the LockableObject from another SynchronizedPointer instance Other to this instance....
Definition Util.h:205
SynchronizedPointer() noexcept
Contructs an instance with an empty pointer.
Definition Util.h:178
SynchronizedPointer(SynchronizedPointer &&Other) noexcept
Moves the LockableObject from another SynchronizedPointer instance Other to a new instance....
Definition Util.h:197
auto operator->() const noexcept
Definition Util.h:249
auto & operator*() const noexcept
Definition Util.h:250
bool operator!=(const SynchronizedPointer &rhs) const noexcept
Definition Util.h:246
T * LockableObject
Pointer to the locakable object managed by this class.
Definition Util.h:256
auto get() const noexcept
Returns the managed (locked) object.
Definition Util.h:241
bool operator==(const T *rhs) const noexcept
Definition Util.h:243
Thrown when an operation timed out before it could be completed, especially used for locking shared d...
Definition Exception.h:262
Thrown when an attempt was made to convert two incompatible types into each other.
Definition Exception.h:249
Thrown when a numeric operation would result in an underflow (e.g. due to incompatible data types)
Definition Exception.h:188
Collection of static functions to generate a unique ID for data types.
Definition Util.h:579
static size_t Get() noexcept
Generates a unique ID for each template instantiation. The first ID is 1 to allow assigning a special...
Definition Util.h:588
static size_t Make() noexcept
Creates a new ID for each call.
Definition Util.cpp:149
Class to store information about warnings in a thread-safe manner (deriving from ILockable)....
Definition Util.h:1026
Warning()
Constructs an empty Warning.
Definition Util.h:1060
virtual ~Warning()=default
Warning(std::string Description, const int ErrorCode=DynExpErrorCodes::GeneralError, const std::source_location Location=std::source_location::current())
Constructs a Warning from specified information.
Definition Util.h:1068
Warning(const Exception &e)
Constructs a Warning retrieving the warning data from an exception e.
Definition Util.h:1076
std::unique_ptr< WarningData > Data
Pointer to warning data. Must never be nullptr.
Definition Util.h:1098
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
std::string ToStr(const T &Value, int Precision=-1)
Converts a (numeric) value of type T to a std::string using operator<< of std::stringstream.
Definition Util.h:688
typename member_fn_ptr_traits< CallableT >::instance_type instance_of_t
Alias for the class type a member function callable of type CallableT is member of.
Definition Util.h:368
std::string ToUnitStr< std::chrono::seconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:837
constexpr bool is_contained_in_v
Value type of is_contained_in.
Definition Util.h:303
constexpr auto ConvertFrequencyWavelength(double Value) noexcept
Converts the frequency value of an electromagnetic wave in Hz to the corresponding wavelength in m an...
Definition Util.h:635
std::index_sequence< Indices+Offset... > type
Alias for offset index sequence.
Definition Util.h:413
auto FilenameFromPath(std::string Path)
Extracts the filename from a path.
Definition Util.h:906
std::string ExceptionToStr(const std::exception_ptr ExceptionPtr)
Returns the what() information of an exception derived from std::exception and stored in an exception...
Definition Util.cpp:197
T StrToT(const std::string &String)
Converts a std::string to a value of type T using operator<< of std::stringstream.
Definition Util.h:667
std::string ToUnitStr< picoseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:882
auto CurrentTimeAndDateString()
Returns a human-readable string describing the current time and date in the current time zone.
Definition Util.h:899
typename remove_first_from_tuple< TupleT >::type remove_first_from_tuple_t
Alias for a tuple of types where the first type of the input tuple TupleT is removed.
Definition Util.h:392
VersionType VersionFromString(std::string_view Str)
Extracts a program version from a string.
Definition Util.cpp:170
unsigned int Major
Definition Util.h:920
typename OffsetIndexSequence< Offset, IndexSequence >::type OffsetIndexSequence_t
Alias for type contained in OffsetIndexSequence.
Definition Util.h:420
EventLogger & EventLog()
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one...
Definition Util.cpp:517
std::vector< std::tuple< Ts... > > ParseCSV(const std::string &CSVData, const char Delimiter=';', const size_t SkipLines=0)
Parses a string containing comma-separated values (csv) and inserts each row as one tuple containing ...
Definition Util.h:958
typename member_fn_ptr_traits< CallableT >::return_type return_of_t
Alias for the return type of a member function callable of type CallableT.
Definition Util.h:362
std::string ToUnitStr()
Returns a string describing the physical unit associated with type T. For example,...
unsigned int Minor
Definition Util.h:921
std::chrono::duration< double, std::pico > picoseconds
Extends std::chrono by a duration data type for picoseconds.
Definition Util.h:622
static constexpr double SpeedOfLight
Speed of light in vacuum in m/s.
Definition Util.h:627
std::strong_ordering operator<=>(const VersionType &lhs, const VersionType &rhs)
Compares two program version types with each other.
Definition Util.cpp:157
std::string ToUnitStr< std::chrono::milliseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:846
std::string ToUnitStr< std::chrono::nanoseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:864
std::string ToLower(std::string_view Str)
Transforms a string into lower case.
Definition Util.cpp:216
std::chrono::duration< double > seconds
Extends std::chrono by a duration data type for seconds capable of storing fractions of seconds.
Definition Util.h:621
auto RemoveExtFromPath(std::string Path)
Removes the filename's extension from a path.
Definition Util.h:913
std::string TrimTrailingZeros(const std::string &Str)
Removes trailing zeros ('\0') from a string.
Definition Util.h:893
typename RangeIndexSequence< From, To >::type RangeIndexSequence_t
Alias for type contained in RangeIndexSequence.
Definition Util.h:437
ToT NumToT(const FromT Value)
Converts a value of a numeric type to a value of another numeric type checking the conversion for its...
Definition Util.h:750
std::ostream & operator<<(std::ostream &stream, const Exception &e)
Writes a DynExp exception in a user-readable way to a stream.
Definition Exception.cpp:17
void HashCombine(std::size_t &seed, const T &value)
Combines the std::hash seed with the hash of value. Resembles hash_combine() from the Boost library p...
Definition Util.h:611
unsigned int Patch
Definition Util.h:922
ErrorType
DynExp's error types
Definition Exception.h:15
std::vector< std::complex< double > > FFT(const std::vector< std::complex< double > > &Data, bool InverseTransform)
Computes the Fast Fourier Transform (FFT) a vector of complex values.
Definition Util.cpp:228
typename member_fn_ptr_traits< CallableT >::argument_types argument_of_t
Alias for a tuple of argument types the member function callable of type CallableT expects.
Definition Util.h:374
std::string ToUnitStr< seconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:873
std::string ToUnitStr< std::chrono::microseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:855
OffsetIndexSequence_t< From, std::make_index_sequence< To - From > > type
Definition Util.h:430
Holds an alias for a std::index_sequence where all indices are shifted by an offset.
Definition Util.h:402
Holds an alias for a std::index_sequence spanning a certain range.
Definition Util.h:429
Data type describing DynExp's program version in the form Major.Minor.Patch.
Definition Util.h:919
Extracts the return value type, the class type the callable is member of, and the argument types of a...
Definition Util.h:312
Removes first type from a tuple of types TupleT.
Definition Util.h:380
#define DYNEXP_HAS_STACKTRACE
Definition stdafx.h:61
Data type of a single entry in DynExp's log.
Definition Util.h:1105
LogEntry(std::string Message, ErrorType Type, std::chrono::system_clock::time_point TimePoint)
Definition Util.h:1106
const std::string Message
String describing the log entry including reasons and consequences of the message.
Definition Util.h:1109
const ErrorType Type
DynExp error code from DynExpErrorCodes::DynExpErrorCodes associated with the log enty
Definition Util.h:1110
const std::chrono::system_clock::time_point TimePoint
Time point associated with the log enty.
Definition Util.h:1111
Data associated with a warning. The class is convertible to bool (true if it describes an error/warni...
Definition Util.h:1033
const std::string Function
Function in source code where the warning occurred.
Definition Util.h:1053
const std::string Description
String describing the reason and consequences of the warning.
Definition Util.h:1050
const std::string File
Source code file where the warning occurred.
Definition Util.h:1054
const size_t Line
Line in source code where the warning occurred.
Definition Util.h:1052
WarningData(std::string Description, const int ErrorCode=DynExpErrorCodes::GeneralError, const size_t Line=0, std::string Function="", std::string File="")
Definition Util.h:1043
WarningData()
Default constructor sets ErrorCode to a non-error code.
Definition Util.h:1037
const int ErrorCode
DynExp error code from DynExpErrorCodes::DynExpErrorCodes
Definition Util.h:1051
WarningData(std::string Description, const int ErrorCode=DynExpErrorCodes::GeneralError, const std::source_location Location=std::source_location::current())
Definition Util.h:1039
Checks whether a type T is contained in a template parameter pack of types ListTs.
Definition Util.h:297