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#include "Units.h"
12
17namespace Util
18{
24 {
25 protected:
26 constexpr INonCopyable() = default;
27 ~INonCopyable() = default;
28
29 public:
30 INonCopyable(const INonCopyable&) = delete;
32 };
33
39 {
40 protected:
41 constexpr INonMovable() = default;
42 ~INonMovable() = default;
43
44 public:
45 INonMovable(const INonMovable&) = default;
46 INonMovable& operator=(const INonMovable&) = default;
47
50 };
51
56 class ILockable : public INonCopyable
57 {
58 public:
63 static constexpr std::chrono::milliseconds DefaultTimeout = std::chrono::milliseconds(10);
64
65 protected:
66 using MutexType = std::timed_mutex;
67 using LockType = std::unique_lock<MutexType>;
68
69 ILockable() = default;
70 ~ILockable() = default;
71
80 [[nodiscard]] LockType AcquireLock(const std::chrono::milliseconds Timeout = DefaultTimeout) const;
81
82 private:
84 };
85
86 class TimeoutException;
87 template <typename> class SynchronizedPointer;
88
94 {
95 // Every SynchronizedPointer<...> should be friend to allow SynchronizedPointers to derived classes
96 template <typename>
97 friend class SynchronizedPointer;
98
99 protected:
102
103 private:
112 void AcquireLock(const std::chrono::milliseconds Timeout) const
113 {
114 using namespace std::chrono_literals;
115
116 // In order to compensate for spurious failures by retrying
117 // (see https://en.cppreference.com/w/cpp/thread/timed_mutex/try_lock_for)
118 constexpr int NumTries = 2;
119
120 if (OwnerID != std::this_thread::get_id())
121 {
122 if (Timeout == 0ms)
123 LockMutex.lock();
124 else
125 {
126 bool Success = false;
127 auto TimeoutPerTry = Timeout / NumTries;
128 for (auto i = NumTries; i > 0 && !Success; --i)
129 Success = LockMutex.try_lock_for(TimeoutPerTry);
130
131 if (!Success)
132 throw TimeoutException("Timeout occurred while trying to lock a mutex.");
133 }
134
135 OwnerID = std::this_thread::get_id();
136 }
137
138 ++OwnedCount;
139 }
140
145 void ReleaseLock() const
146 {
147 if (!OwnedCount || OwnerID != std::this_thread::get_id())
148 return;
149
150 --OwnedCount;
151 if (!OwnedCount)
152 {
153 OwnerID = std::thread::id();
154 LockMutex.unlock();
155 }
156 }
157
158 mutable std::timed_mutex LockMutex;
159 mutable std::atomic<std::thread::id> OwnerID;
160 mutable std::atomic<size_t> OwnedCount;
161 };
162
169 template <typename T>
171 {
172 template <typename>
174
175 public:
179 SynchronizedPointer() noexcept : LockableObject(nullptr) {}
180
190 const std::chrono::milliseconds Timeout = ILockable::DefaultTimeout)
191 : LockableObject(LockableObject) { if (LockableObject) LockableObject->AcquireLock(Timeout); }
192
198 SynchronizedPointer(SynchronizedPointer&& Other) noexcept : LockableObject(Other.LockableObject) { Other.LockableObject = nullptr; }
199
207 {
209 Other.LockableObject = nullptr;
210
211 return *this;
212 }
213
221 template <typename U>
223 {
224 if (!Other.LockableObject)
225 LockableObject = nullptr;
226 else
227 {
228 LockableObject = dynamic_cast<T*>(Other.LockableObject);
229 if (!LockableObject)
231
232 Other.LockableObject = nullptr;
233 }
234 }
235
237
242 auto get() const noexcept { return LockableObject; }
243
244 bool operator==(const T* rhs) const noexcept { return LockableObject == rhs; }
245 bool operator!=(const T* rhs) const noexcept { return LockableObject != rhs; }
246 bool operator==(const SynchronizedPointer& rhs) const noexcept { return LockableObject == rhs.get(); }
247 bool operator!=(const SynchronizedPointer& rhs) const noexcept { return LockableObject != rhs.get(); }
248 explicit operator bool() const noexcept { return LockableObject != nullptr; }
249
250 auto operator->() const noexcept { return LockableObject; }
251 auto& operator*() const noexcept { return *LockableObject; }
252
253 private:
258 };
259
266 {
267 public:
270
280 bool Wait(const std::chrono::milliseconds Timeout = std::chrono::milliseconds(0));
281
282 void Notify();
283 void Ignore();
284
285 private:
288 std::atomic<bool> MutexCanBeDestroyed;
289
290 std::mutex Mutex;
291 std::condition_variable ConditionVariable;
292 };
293
297 template <typename T, typename... ListTs>
298 struct is_contained_in : std::disjunction<std::is_same<T, ListTs>...> {};
299
303 template <typename T, typename... ListTs>
304 inline constexpr bool is_contained_in_v = is_contained_in<T, ListTs...>::value;
305
312 template <typename CallableT>
314
318 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
319 struct member_fn_ptr_traits<ReturnT (ObjectT::*)(ArgumentTs...) const>
320 {
321 using return_type = ReturnT;
322 using instance_type = ObjectT;
323 using argument_types = std::tuple<ArgumentTs...>;
324 };
325
329 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
330 struct member_fn_ptr_traits<ReturnT(ObjectT::*)(ArgumentTs...) noexcept>
331 {
332 using return_type = ReturnT;
333 using instance_type = ObjectT;
334 using argument_types = std::tuple<ArgumentTs...>;
335 };
336
340 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
341 struct member_fn_ptr_traits<ReturnT(ObjectT::*)(ArgumentTs...) const noexcept>
342 {
343 using return_type = ReturnT;
344 using instance_type = ObjectT;
345 using argument_types = std::tuple<ArgumentTs...>;
346 };
347
351 template <typename ReturnT, typename ObjectT, typename... ArgumentTs>
352 struct member_fn_ptr_traits<ReturnT (ObjectT::*)(ArgumentTs...)>
353 {
354 using return_type = ReturnT;
355 using instance_type = ObjectT;
356 using argument_types = std::tuple<ArgumentTs...>;
357 };
358
362 template <typename CallableT>
364
368 template <typename CallableT>
370
374 template <typename CallableT>
376
380 template <typename TupleT>
382
386 template <typename FirstElementT, typename... ElementTs>
387 struct remove_first_from_tuple<std::tuple<FirstElementT, ElementTs...>> { using type = std::tuple<ElementTs...>; };
388
392 template <typename TupleT>
394
395 // Index sequence manipulation to define a starting point
396
402 template <size_t Offset, typename IndexSequence>
404
408 template <size_t Offset, size_t... Indices>
409 struct OffsetIndexSequence<Offset, std::index_sequence<Indices...>>
410 {
414 using type = std::index_sequence<Indices + Offset...>;
415 };
416
420 template <size_t Offset, typename IndexSequence>
422
428 template <size_t From, size_t To>
430 {
431 using type = OffsetIndexSequence_t<From, std::make_index_sequence<To - From>>;
432 };
433
437 template <size_t From, size_t To>
439
447 template <typename ObjectT, typename CallableT>
449 {
451
452 public:
460 constexpr CallableMemberWrapper(ObjectT& Object, const CallableT Callable, ArgumentTs DefaultArgs = {}) noexcept
462
470 template <typename... ArgTs>
471 auto operator()(ArgTs&& ...Args) const
472 {
473 return Invoke(RangeIndexSequence_t<sizeof...(ArgTs), std::tuple_size_v<ArgumentTs>>(), std::forward<ArgTs>(Args)...);
474 }
475
476 private:
477 template <size_t... Indices, typename... ArgTs>
478 auto Invoke(std::integer_sequence<size_t, Indices...>, ArgTs&& ...Args) const
479 {
480 return (Object.*Callable)(std::forward<ArgTs>(Args)..., std::get<Indices>(DefaultArgs)...);
481 }
482
483 ObjectT& Object;
484 const CallableT Callable;
486 };
487
493 template <typename ObjectT, typename CallableT>
495 {
496 public:
504 template <typename... ArgTs>
505 OnDestruction(ObjectT& Object, const CallableT Callable, ArgTs&& ...Args)
506 : CallableWrapper(Object, std::move(Callable), { std::forward<ArgTs>(Args)... }) {}
507
509
510 private:
512 };
513
518 {
519 public:
520 using DataType = unsigned char[];
521
522 private:
523 using DataPtrType = std::unique_ptr<DataType>;
524
525 public:
526 BlobDataType() = default;
527 BlobDataType(const BlobDataType& Other);
528 BlobDataType(BlobDataType&& Other) noexcept;
529
530 BlobDataType& operator=(const BlobDataType& Other);
531 BlobDataType& operator=(BlobDataType&& Other) noexcept;
532
533 void Reserve(size_t Size);
534 void Assign(size_t Size, const DataType Data);
535 void Reset();
536 DataPtrType::element_type* Release() noexcept;
537 auto GetPtr() noexcept { return DataPtr.get(); }
538 auto Size() const noexcept { return DataSize; }
539
540 private:
542 size_t DataSize = 0;
543 };
544
550 {
551 public:
555 enum class Values { Unknown, False, True };
556
557 constexpr OptionalBool() noexcept : Value(Values::Unknown) {}
558 constexpr OptionalBool(Values Value) noexcept : Value(Value) {}
559 constexpr OptionalBool(bool b) noexcept : Value(b ? Values::True : Values::False) {}
560 constexpr OptionalBool(const OptionalBool& Other) noexcept : Value(Other.Value) {}
561
562 constexpr OptionalBool& operator=(Values Value) noexcept { this->Value = Value; return *this; }
563 constexpr OptionalBool& operator=(bool b) noexcept { Value = b ? Values::True : Values::False; return *this; }
564 constexpr OptionalBool& operator=(OptionalBool& Other) noexcept { Value = Other.Value; return *this; }
565
566 constexpr bool operator==(Values Value) const noexcept { return this->Value == Value; }
567 constexpr bool operator!=(Values Value) const noexcept { return this->Value != Value; }
568
569 constexpr operator bool() const noexcept { return Value == Values::True; }
570 constexpr Values Get() const noexcept { return Value; }
571
572 private:
574 };
575
580 {
581 public:
588 template <typename T>
589 static size_t Get() noexcept
590 {
591 static const size_t ID = Make();
592
593 return ID;
594 }
595
596 private:
601 static size_t Make() noexcept;
602 };
603
611 template <typename T>
612 inline void HashCombine(std::size_t& seed, const T& value)
613 {
614 std::hash<T> hasher;
615 seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
616 }
617
622 using seconds = std::chrono::duration<double>;
623 using picoseconds = std::chrono::duration<double, std::pico>;
624
631 constexpr auto ConvertFrequencyWavelength(double Value) noexcept { return DynExp::Units::SpeedOfLight / Value; }
633
638
646 template <typename T>
647 std::ostream& operator<<(std::ostream& stream, const std::chrono::time_point<T>& TimePoint)
648 {
649 const auto ZonedTime = std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::round<std::chrono::seconds>(TimePoint));
650 stream << std::format("{:%T %d.%m.%Y}", ZonedTime);
651
652 return stream;
653 }
654
662 template <typename T>
663 T StrToT(const std::string& String)
664 {
665 std::stringstream ss(String);
666 T Value;
667 ss >> Value;
668
669 if (ss.fail())
670 throw InvalidDataException("String cannot be converted to " + std::string(typeid(T).name()) + ".");
671
672 return Value;
673 }
674
683 template <typename T>
684 std::string ToStr(const T& Value, int Precision = -1)
685 {
686 std::stringstream ss;
687
688 if (Precision >= 0)
689 ss << std::fixed << std::setprecision(Precision);
690
691 ss << Value;
692 return ss.str();
693 }
694
701 template <typename T>
702 std::string ToStr(const std::chrono::time_point<T>& TimePoint)
703 {
704 std::stringstream ss;
705
706 Util::operator<<(ss, TimePoint);
707 return ss.str();
708 }
709
715 inline std::string ToStr(const char Value) { return ToStr(static_cast<int>(Value)); }
716
720 inline std::string ToStr(const uint8_t Value) { return ToStr(static_cast<int>(Value)); }
721
727 inline std::string ToStr(const QString& Str) { return Str.toStdString(); }
728
742 template <typename ToT, typename FromT, std::enable_if_t<
743 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
744 std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>>, int> = 0
745 >
746 inline ToT NumToT(const FromT Value)
747 {
748 return Value;
749 }
750
754 template <typename ToT, typename FromT, std::enable_if_t<
755 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
756 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
757 ((std::is_signed_v<ToT> && std::is_signed_v<FromT>) || (std::is_unsigned_v<ToT> && std::is_unsigned_v<FromT>)), int> = 0
758 >
759 ToT NumToT(const FromT Value)
760 {
761 if (Value < std::numeric_limits<ToT>::lowest() || Value > std::numeric_limits<ToT>::max())
762 throw OutOfRangeException("Cannot convert Value into destiny type since this would cause an underflow or an overflow.");
763
764 return static_cast<ToT>(Value);
765 }
766
770 template <typename ToT, typename FromT, std::enable_if_t<
771 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
772 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
773 std::is_signed_v<ToT> && std::is_unsigned_v<FromT>, int> = 0
774 >
775 ToT NumToT(const FromT Value)
776 {
777 if (Value > static_cast<std::make_unsigned_t<ToT>>(std::numeric_limits<ToT>::max()))
778 throw OverflowException("Cannot convert Value into destiny type since this would cause an overflow.");
779
780 return static_cast<ToT>(Value);
781 }
782
786 template <typename ToT, typename FromT, std::enable_if_t<
787 std::is_integral_v<ToT> && std::is_integral_v<FromT> &&
788 !std::is_same_v<std::remove_cv_t<ToT>, std::remove_cv_t<FromT>> &&
789 std::is_unsigned_v<ToT> && std::is_signed_v<FromT>, int> = 0
790 >
791 ToT NumToT(const FromT Value)
792 {
793 if (Value < 0)
794 throw UnderflowException("Cannot convert Value into destiny type since this would cause an underflow.");
795 if (static_cast<std::make_unsigned_t<FromT>>(Value) > std::numeric_limits<ToT>::max())
796 throw OverflowException("Cannot convert Value into destiny type since this would cause an overflow.");
797
798 return static_cast<ToT>(Value);
799 }
800
804 template <typename ToT, std::enable_if_t<
805 std::is_integral_v<ToT> &&
806 !std::is_same_v<std::remove_cv_t<ToT>, double>, int> = 0
807 >
808 ToT NumToT(const double Value)
809 {
810 const double RoundedValue = std::round(Value);
811
812 if (RoundedValue < static_cast<double>(std::numeric_limits<ToT>::lowest()))
813 throw UnderflowException("Cannot convert Value into double since this would cause an underflow.");
814 if (RoundedValue > static_cast<double>(std::numeric_limits<ToT>::max()))
815 throw OverflowException("Cannot convert Value into double since this would cause an overflow.");
816
817 return static_cast<ToT>(RoundedValue);
818 }
819
826 template <typename T>
827 inline std::string ToUnitStr();
828
832 template <>
834 {
835 return "s";
836 }
837
841 template <>
843 {
844 return "ms";
845 }
846
850 template <>
852 {
853 return "us";
854 }
855
859 template <>
861 {
862 return "ns";
863 }
864
868 template <>
869 inline std::string ToUnitStr<seconds>()
870 {
871 return "s";
872 }
873
877 template <>
878 inline std::string ToUnitStr<picoseconds>()
879 {
880 return "ps";
881 }
883
889 inline std::string TrimTrailingZeros(const std::string& Str) { return Str.substr(0, Str.find('\0')); }
890
895 inline auto CurrentTimeAndDateString() { return ToStr(std::chrono::system_clock::now()); }
896
902 inline auto FilenameFromPath(std::string Path) { return Path.substr(Path.find_last_of("\\") + 1, Path.length() - Path.find_last_of("\\") - 1); }
903
909 inline auto RemoveExtFromPath(std::string Path) { return Path.substr(0, Path.find_last_of(".")); }
910
915 {
916 unsigned int Major{};
917 unsigned int Minor{};
918 unsigned int Patch{};
919 };
920
927 std::strong_ordering operator<=>(const VersionType& lhs, const VersionType& rhs);
928
935 VersionType VersionFromString(std::string_view Str);
936
942 inline std::string ToStr(const VersionType& Version) { return ToStr(Version.Major) + "." + ToStr(Version.Minor) + "." + ToStr(Version.Patch); }
943
953 template <typename... Ts>
954 std::vector<std::tuple<Ts...>> ParseCSV(const std::string& CSVData, const char Delimiter = ';', const size_t SkipLines = 0)
955 {
956 std::vector<std::tuple<Ts...>> ParsedLines;
957 std::istringstream CSVDataStream(CSVData);
958
959 // Ignore header lines
960 for (auto i = SkipLines; i > 0; --i)
961 CSVDataStream.ignore(std::numeric_limits<std::streamsize>::max(), CSVDataStream.widen('\n'));
962
963 // Function to parse one field from a single line
964 const auto GetValue = [Delimiter]<typename T>(std::istringstream& LineStream) {
965 std::string ValueStr;
966 std::getline(LineStream, ValueStr, Delimiter);
967 std::istringstream ValueStream(ValueStr);
968 ValueStream.exceptions(std::istringstream::failbit | std::istringstream::badbit);
969
970 T Value;
971 ValueStream >> Value;
972
973 return Value;
974 };
975
976 // Loop through each line and fill ParsedLines with tuples of column data.
977 std::string Line;
978 while (std::getline(CSVDataStream, Line))
979 {
980 std::istringstream LineStream(Line);
981 LineStream.exceptions(std::istringstream::failbit | std::istringstream::badbit);
982
983 // Braced initialization to ensure correct evaluation order (left to right). Refer to
984 // https://stackoverflow.com/questions/14056000/how-to-avoid-undefined-execution-order-for-the-constructors-when-using-stdmake
985 ParsedLines.push_back({ GetValue.template operator()<Ts>(LineStream)... });
986 }
987
988 return ParsedLines;
989 }
990
997 std::string ExceptionToStr(const std::exception_ptr ExceptionPtr);
998
1004 std::string ToLower(std::string_view Str);
1005
1015 std::vector<std::complex<double>> FFT(const std::vector<std::complex<double>>& Data, bool InverseTransform = false);
1016
1021 class Warning : public ILockable
1022 {
1023 public:
1029 {
1033 WarningData() : ErrorCode(DynExpErrorCodes::NoError), Line(0) {}
1034
1035 WarningData(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1036 const std::source_location Location = std::source_location::current())
1037 : Description(std::move(Description)), ErrorCode(ErrorCode),
1038 Line(Location.line()), Function(Location.function_name()), File(Location.file_name()) {}
1039 WarningData(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1040 const size_t Line = 0, std::string Function = "", std::string File = "")
1041 : Description(std::move(Description)), ErrorCode(ErrorCode),
1042 Line(Line), Function(std::move(Function)), File(std::move(File)) {}
1043
1044 explicit operator bool() const noexcept { return ErrorCode != DynExpErrorCodes::NoError; }
1045
1046 const std::string Description;
1047 const int ErrorCode;
1048 const size_t Line;
1049 const std::string Function;
1050 const std::string File;
1051 };
1052
1056 Warning() : Data(std::make_unique<WarningData>()) {}
1057
1064 Warning(std::string Description, const int ErrorCode = DynExpErrorCodes::GeneralError,
1065 const std::source_location Location = std::source_location::current())
1066 : Data(std::make_unique<WarningData>(std::move(Description), ErrorCode, Location)) {}
1067
1073 : Data(std::make_unique<WarningData>(e.what(), e.ErrorCode, e.Line, e.Function, e.File)) {}
1074
1079 Warning(Warning&& Other) noexcept;
1080
1081 virtual ~Warning() = default;
1082
1083 void Reset();
1084
1085 Warning& operator=(const Exception& e);
1086 Warning& operator=(Warning&& Other) noexcept;
1087
1088 WarningData Get() const;
1089
1090 private:
1094 std::unique_ptr<WarningData> Data;
1095 };
1096
1101 {
1102 LogEntry(std::string Message, ErrorType Type, std::chrono::system_clock::time_point TimePoint)
1103 : Message(std::move(Message)), Type(Type), TimePoint(TimePoint) {}
1104
1105 const std::string Message;
1107 const std::chrono::system_clock::time_point TimePoint;
1108 };
1109
1116 class EventLogger : public ILockable
1117 {
1118 friend EventLogger& EventLog();
1119
1124 EventLogger();
1125
1130 EventLogger(std::string Filename) : EventLogger() { OpenLogFile(Filename); }
1131
1132 public:
1136 ~EventLogger() { CloseLogFileUnsafe(); }
1137
1144
1154 void Log(const std::string& Message, const ErrorType Type = ErrorType::Info,
1155 const size_t Line = 0, const std::string& Function = "", const std::string& File = "", const int ErrorCode = 0
1157 , const std::stacktrace& Trace = {}
1158#endif // DYNEXP_HAS_STACKTRACE
1159 ) noexcept;
1160
1165 void Log(const Exception& E) noexcept;
1166
1171 void Log(const Warning& W) noexcept;
1173
1184 static std::string FormatLog(const std::string& Message, const size_t Line = 0,
1185 const std::string& Function = "", const std::string& Filename = "", const int ErrorCode = 0, const bool PrefixMessage = true);
1186
1199 static std::string FormatLogHTML(const std::string& Message, const ErrorType Type = ErrorType::Info,
1200 const size_t Line = 0, const std::string& Function = "", const std::string& Filename = "", const int ErrorCode = 0
1202 , const std::stacktrace& Trace = {}
1203#endif // DYNEXP_HAS_STACKTRACE
1204 );
1205
1210 void OpenLogFile(std::string Filename);
1211
1215 void CloseLogFile() { auto lock = AcquireLock(LogOperationTimeout); CloseLogFileUnsafe(); }
1216
1221 bool IsOpen() const { auto lock = AcquireLock(LogOperationTimeout); return IsOpenUnsafe(); }
1222
1227 std::string GetLogFilename() const { auto lock = AcquireLock(LogOperationTimeout); return Filename; }
1228
1232 void ClearLog() { auto lock = AcquireLock(LogOperationTimeout); ClearLogUnsafe(); }
1233
1240 std::vector<LogEntry> GetLog(size_t FirstElement = 0) const;
1241
1246 auto GetLogSize() const { auto lock = AcquireLock(LogOperationTimeout); return LogEntries.size(); }
1247
1248 private:
1254 bool IsOpenUnsafe() const { return LogFile.is_open(); }
1255 void CloseLogFileUnsafe();
1256 void ClearLogUnsafe() { LogEntries.clear(); }
1258
1263 static constexpr auto LogOperationTimeout = std::chrono::milliseconds(100);
1264
1265 std::ofstream LogFile;
1266 std::string Filename;
1267
1268 std::vector<LogEntry> LogEntries;
1269 };
1270
1278
1285 template <typename EnumType, std::enable_if_t<
1286 std::is_enum_v<EnumType>, int> = 0
1287 >
1289 {
1290 public:
1294 constexpr FeatureTester() noexcept = default;
1295
1301 template <size_t N>
1302 FeatureTester(const std::array<EnumType, N>& Flags)
1303 {
1304 for (const auto Flag : Flags)
1305 Set(Flag);
1306 }
1307
1314 template <size_t N>
1315 bool Test(const std::array<EnumType, N>& Flags) const
1316 {
1317 for (const auto Flag : Flags)
1318 {
1319 auto Result = Features.test(static_cast<size_t>(Flag));
1320
1321 if (!Result)
1322 false;
1323 }
1324
1325 return true;
1326 }
1327
1333 bool Test(EnumType Flag) const { return Features.test(static_cast<size_t>(Flag)); }
1334
1339 void Set(EnumType Flag) { Features.set(static_cast<size_t>(Flag)); }
1340
1341 private:
1345 std::bitset<static_cast<size_t>(EnumType::NUM_ELEMENTS)> Features;
1346 };
1347
1358 template <
1359 typename CallableT,
1360 std::enable_if_t<std::is_enum_v<return_of_t<CallableT>>, int> = 0
1361 >
1363 {
1364 public:
1366 using CallableType = CallableT;
1367
1375 constexpr StateMachineState(StateEnumType State, CallableT StateFunction, const char* Description = "", const bool IsFinal = false) noexcept
1376 : State(State), StateFunction(StateFunction), Description(Description), Final(IsFinal)
1377 {}
1378
1379 constexpr StateEnumType GetState() const noexcept { return State; }
1380 constexpr auto GetDescription() const noexcept { return Description; }
1381 constexpr bool IsFinal() const noexcept { return Final; }
1382
1391 template <typename... ArgTs>
1392 StateEnumType Invoke(instance_of_t<CallableT>& Instance, ArgTs&&... Args) const
1393 {
1394 return (Instance.*StateFunction)(std::forward<ArgTs>(Args)...);
1395 }
1396
1397 private:
1399 const std::decay_t<CallableT> StateFunction;
1400 const char* Description;
1401
1406 const bool Final;
1407 };
1408
1418 template <typename StateMachineStateT>
1420 {
1421 public:
1422 using StateType = StateMachineStateT;
1423 using StateEnumType = typename StateType::StateEnumType;
1424 using ReplacementListType = std::unordered_map<StateEnumType, StateEnumType>;
1425
1430
1441 StateMachineContext(ReplacementListType&& ReplacementList, const char* Description = "",
1442 std::initializer_list<const StateMachineContext*> BaseContexts = {})
1443 : ReplacementList(std::move(ReplacementList)), Description(Description)
1444 {
1445 for (auto BaseContext : BaseContexts)
1446 if (BaseContext)
1447 this->ReplacementList.insert(BaseContext->ReplacementList.cbegin(), BaseContext->ReplacementList.cend());
1448 }
1449
1454 constexpr auto GetDescription() const noexcept { return Description; }
1455
1463 {
1464 auto AdaptedState = ReplacementList.find(State);
1465
1466 return AdaptedState == ReplacementList.cend() ? State : AdaptedState->second;
1467 }
1468
1469 private:
1475
1476 const char* Description;
1477 };
1478
1491 template <typename StateMachineStateT>
1493 {
1494 public:
1495 using StateType = StateMachineStateT;
1496 using StateEnumType = typename StateType::StateEnumType;
1498
1507 template <typename... StateMachineStateTs>
1508 StateMachine(const StateType& InitialState, const StateMachineStateTs&... States)
1509 : StatesList{ { InitialState.GetState(), &InitialState }, { States.GetState(), &States }... },
1510 CurrentState(&InitialState), CurrentContext(nullptr)
1511 {}
1512
1513 const StateType* GetCurrentState() const noexcept { return CurrentState; }
1514 const ContextType* GetContext() const noexcept { return CurrentContext; }
1515
1522 {
1523 if (CurrentContext)
1524 CurrentState = StatesList.at(CurrentContext.load()->AdaptState(NewState));
1525 else
1526 CurrentState = StatesList.at(NewState);
1527 }
1528
1533 void SetContext(const ContextType* NewContext) { CurrentContext = NewContext; }
1534
1538 void ResetContext() { CurrentContext = nullptr; }
1539
1549 template <typename... ArgTs>
1551 {
1552 if (!CurrentState)
1553 throw InvalidStateException("CurrentState must not be nullptr in order to be invoked.");
1554
1555 if (CurrentState.load()->IsFinal())
1556 CurrentState.load()->Invoke(Instance, std::forward<ArgTs>(Args)...);
1557 else
1558 SetCurrentState(CurrentState.load()->Invoke(Instance, std::forward<ArgTs>(Args)...));
1559 }
1560
1561 private:
1566 const std::unordered_map<StateEnumType, const StateType*> StatesList;
1567
1573 std::atomic<const StateType*> CurrentState;
1574 std::atomic<const ContextType*> CurrentContext;
1576 };
1577}
Provides exception type and error definitions used by DynExp.
Physical units used in DynExp. This file does not depend on further DynExp files and therefore can be...
Data type which manages a binary large object. The reserved memory is freed upon destruction.
Definition Util.h:518
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:542
unsigned char[] DataType
Type of the buffer's data.
Definition Util.h:520
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:523
DataPtrType DataPtr
Pointer to the buffer.
Definition Util.h:541
auto Size() const noexcept
Returns the size of the stored data in bytes.
Definition Util.h:538
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:537
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:449
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:471
argument_of_t< CallableT > ArgumentTs
Definition Util.h:450
constexpr CallableMemberWrapper(ObjectT &Object, const CallableT Callable, ArgumentTs DefaultArgs={}) noexcept
Constructs a CallableMemberWrapper instance.
Definition Util.h:460
ObjectT & Object
Instance of class Callable belongs to. Callable is invoked on this instance.
Definition Util.h:483
auto Invoke(std::integer_sequence< size_t, Indices... >, ArgTs &&...Args) const
Definition Util.h:478
const ArgumentTs DefaultArgs
Default arguments to be passed when invoking operator() with less arguments Callable expects.
Definition Util.h:485
const CallableT Callable
Pointer to class member function to be invoked.
Definition Util.h:484
Logs events like errors and writes them immediately to a HTML file in a human-readable format....
Definition Util.h:1117
bool IsOpenUnsafe() const
Definition Util.h:1254
void CloseLogFile()
Closes the log file on disk and writes terminating HTML tags.
Definition Util.h:1215
EventLogger(std::string Filename)
Constructs the event logger with opening a log file on disk.
Definition Util.h:1130
std::string GetLogFilename() const
Determines the full file path to the currently openend log file.
Definition Util.h:1227
auto GetLogSize() const
Determines the number of entries in the internal event log.
Definition Util.h:1246
std::ofstream LogFile
Stream object to write to the log file on disk.
Definition Util.h:1265
std::string Filename
Filename and path to the log file on disk.
Definition Util.h:1266
~EventLogger()
Destructor closes the log file on disk.
Definition Util.h:1136
void ClearLog()
Clears the internal event log.
Definition Util.h:1232
std::vector< LogEntry > LogEntries
Internally stored log entries.
Definition Util.h:1268
void ClearLogUnsafe()
Definition Util.h:1256
bool IsOpen() const
Determines whether the log file has been openend on disk.
Definition Util.h:1221
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:1289
constexpr FeatureTester() noexcept=default
Constructs a FeatureTester instance with no flags set.
void Set(EnumType Flag)
Sets a flag.
Definition Util.h:1339
bool Test(const std::array< EnumType, N > &Flags) const
Tests whether all of the flags passed as an array are set.
Definition Util.h:1315
std::bitset< static_cast< size_t >(EnumType::NUM_ELEMENTS)> Features
Bitset containing the flags and their states.
Definition Util.h:1345
bool Test(EnumType Flag) const
Tests whether a single flag is set.
Definition Util.h:1333
Interface to allow synchronizing the access to derived classes between different threads by providing...
Definition Util.h:57
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:66
std::unique_lock< MutexType > LockType
Definition Util.h:67
MutexType LockMutex
Internal mutex used for locking.
Definition Util.h:83
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:63
~ILockable()=default
Interface to delete copy constructor and copy assignment operator and thus make derived classes non-c...
Definition Util.h:24
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:39
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:94
std::timed_mutex LockMutex
Internal mutex used for locking.
Definition Util.h:158
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:145
~ISynchronizedPointerLockable()
Object should never be destroyed before completely unlocked.
Definition Util.h:101
std::atomic< size_t > OwnedCount
Counts the lock requests of the current owning thread.
Definition Util.h:160
std::atomic< std::thread::id > OwnerID
ID of the thread which currently owns the internal mutex.
Definition Util.h:159
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:112
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:495
CallableMemberWrapper< ObjectT, CallableT > CallableWrapper
Definition Util.h:511
OnDestruction(ObjectT &Object, const CallableT Callable, ArgTs &&...Args)
Constructs a OnDestruction instance which calls Callable upon destruction of this instance.
Definition Util.h:505
Helper class to communicate flags between different threads based on a condition variable and a mutex...
Definition Util.h:266
std::condition_variable ConditionVariable
Definition Util.h:291
std::atomic< bool > MutexCanBeDestroyed
Definition Util.h:288
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:290
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:550
Values
Possible values. Values::Unknown evaluates to false.
Definition Util.h:555
constexpr OptionalBool(bool b) noexcept
Contructs an instance holding b.
Definition Util.h:559
constexpr OptionalBool(const OptionalBool &Other) noexcept
Contructs a copy of Other.
Definition Util.h:560
constexpr OptionalBool(Values Value) noexcept
Contructs an instance holding Value.
Definition Util.h:558
constexpr bool operator!=(Values Value) const noexcept
Returns false when Value matches stored value, true otherwise.
Definition Util.h:567
constexpr bool operator==(Values Value) const noexcept
Returns true when Value matches stored value, false otherwise.
Definition Util.h:566
constexpr OptionalBool & operator=(Values Value) noexcept
Assigns Value, returns reference to this.
Definition Util.h:562
constexpr OptionalBool() noexcept
Contructs an instance holding Values::Unknown.
Definition Util.h:557
constexpr OptionalBool & operator=(OptionalBool &Other) noexcept
Assigns value of Other, returns reference to this.
Definition Util.h:564
Values Value
Internal value.
Definition Util.h:573
constexpr Values Get() const noexcept
Returns internal value.
Definition Util.h:570
constexpr OptionalBool & operator=(bool b) noexcept
Assigns b, returns reference to this.
Definition Util.h:563
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:1420
typename StateType::StateEnumType StateEnumType
Refer to class StateMachineState.
Definition Util.h:1423
StateEnumType AdaptState(StateEnumType State) const
Checks whether the context contains a replacement entry for the state identified by State and returns...
Definition Util.h:1462
const char * Description
Definition Util.h:1476
std::unordered_map< StateEnumType, StateEnumType > ReplacementListType
Definition Util.h:1424
constexpr auto GetDescription() const noexcept
Returns the context's description.
Definition Util.h:1454
StateMachineStateT StateType
Definition Util.h:1422
ReplacementListType ReplacementList
Within this context, the map's key states are replaced by the corresponding value states....
Definition Util.h:1474
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:1441
State machine state as used by class StateMachine. A state mainly wraps a state function of the membe...
Definition Util.h:1363
const StateEnumType State
Definition Util.h:1398
CallableT CallableType
Definition Util.h:1366
const char * Description
Definition Util.h:1400
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:1392
const bool Final
For final states, it is ensured that the state's state function can delete the state machine....
Definition Util.h:1406
return_of_t< CallableT > StateEnumType
Definition Util.h:1365
constexpr StateEnumType GetState() const noexcept
Returns the state's unique identifier.
Definition Util.h:1379
const std::decay_t< CallableT > StateFunction
Definition Util.h:1399
constexpr auto GetDescription() const noexcept
Returns the state's description.
Definition Util.h:1380
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:1375
constexpr bool IsFinal() const noexcept
Returns whether this is a final state.
Definition Util.h:1381
This class models a state machine. It keeps track of the current state and allows to invoke its assoc...
Definition Util.h:1493
std::atomic< const StateType * > CurrentState
Definition Util.h:1573
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:1550
void SetContext(const ContextType *NewContext)
Sets the current state machine context.
Definition Util.h:1533
StateMachineStateT StateType
Definition Util.h:1495
void ResetContext()
Removes the current state machine context.
Definition Util.h:1538
void SetCurrentState(StateEnumType NewState)
Sets the current state as identified by an element from StateEnumType.
Definition Util.h:1521
StateMachine(const StateType &InitialState, const StateMachineStateTs &... States)
Constructs a state machine assigning possible states to it. Automatically also adds InitialState,...
Definition Util.h:1508
typename StateType::StateEnumType StateEnumType
Refer to class StateMachineState.
Definition Util.h:1496
const StateType * GetCurrentState() const noexcept
Returns a pointer to the current state.
Definition Util.h:1513
std::atomic< const ContextType * > CurrentContext
Definition Util.h:1574
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:1566
const ContextType * GetContext() const noexcept
Returns a pointer to the current context.
Definition Util.h:1514
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Definition Util.h:171
bool operator!=(const T *rhs) const noexcept
Definition Util.h:245
SynchronizedPointer(SynchronizedPointer< U > &&Other)
Moves the LockableObject from a SynchronizedPointer<U> of another type U to a new instance of Synchro...
Definition Util.h:222
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:189
bool operator==(const SynchronizedPointer &rhs) const noexcept
Definition Util.h:246
SynchronizedPointer & operator=(SynchronizedPointer &&Other) noexcept
Move-assigns the LockableObject from another SynchronizedPointer instance Other to this instance....
Definition Util.h:206
SynchronizedPointer() noexcept
Contructs an instance with an empty pointer.
Definition Util.h:179
SynchronizedPointer(SynchronizedPointer &&Other) noexcept
Moves the LockableObject from another SynchronizedPointer instance Other to a new instance....
Definition Util.h:198
auto operator->() const noexcept
Definition Util.h:250
auto & operator*() const noexcept
Definition Util.h:251
bool operator!=(const SynchronizedPointer &rhs) const noexcept
Definition Util.h:247
T * LockableObject
Pointer to the locakable object managed by this class.
Definition Util.h:257
auto get() const noexcept
Returns the managed (locked) object.
Definition Util.h:242
bool operator==(const T *rhs) const noexcept
Definition Util.h:244
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:580
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:589
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:1022
Warning()
Constructs an empty Warning.
Definition Util.h:1056
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:1064
Warning(const Exception &e)
Constructs a Warning retrieving the warning data from an exception e.
Definition Util.h:1072
std::unique_ptr< WarningData > Data
Pointer to warning data. Must never be nullptr.
Definition Util.h:1094
static constexpr double SpeedOfLight
Speed of light in vacuum in m/s.
Definition Units.h:128
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:684
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:369
std::string ToUnitStr< std::chrono::seconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:833
constexpr bool is_contained_in_v
Value type of is_contained_in.
Definition Util.h:304
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:631
std::index_sequence< Indices+Offset... > type
Alias for offset index sequence.
Definition Util.h:414
auto FilenameFromPath(std::string Path)
Extracts the filename from a path.
Definition Util.h:902
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:663
std::string ToUnitStr< picoseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:878
auto CurrentTimeAndDateString()
Returns a human-readable string describing the current time and date in the current time zone.
Definition Util.h:895
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:393
VersionType VersionFromString(std::string_view Str)
Extracts a program version from a string.
Definition Util.cpp:170
unsigned int Major
Definition Util.h:916
typename OffsetIndexSequence< Offset, IndexSequence >::type OffsetIndexSequence_t
Alias for type contained in OffsetIndexSequence.
Definition Util.h:421
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:954
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:363
std::string ToUnitStr()
Returns a string describing the physical unit associated with type T. For example,...
unsigned int Minor
Definition Util.h:917
std::chrono::duration< double, std::pico > picoseconds
Extends std::chrono by a duration data type for picoseconds.
Definition Util.h:623
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:842
std::string ToUnitStr< std::chrono::nanoseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:860
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:622
auto RemoveExtFromPath(std::string Path)
Removes the filename's extension from a path.
Definition Util.h:909
std::string TrimTrailingZeros(const std::string &Str)
Removes trailing zeros ('\0') from a string.
Definition Util.h:889
typename RangeIndexSequence< From, To >::type RangeIndexSequence_t
Alias for type contained in RangeIndexSequence.
Definition Util.h:438
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:746
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:612
unsigned int Patch
Definition Util.h:918
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:375
std::string ToUnitStr< seconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:869
std::string ToUnitStr< std::chrono::microseconds >()
Returns a string describing the physical unit associated with type T. For example,...
Definition Util.h:851
OffsetIndexSequence_t< From, std::make_index_sequence< To - From > > type
Definition Util.h:431
Holds an alias for a std::index_sequence where all indices are shifted by an offset.
Definition Util.h:403
Holds an alias for a std::index_sequence spanning a certain range.
Definition Util.h:430
Data type describing DynExp's program version in the form Major.Minor.Patch.
Definition Util.h:915
Extracts the return value type, the class type the callable is member of, and the argument types of a...
Definition Util.h:313
Removes first type from a tuple of types TupleT.
Definition Util.h:381
#define DYNEXP_HAS_STACKTRACE
Definition stdafx.h:61
Data type of a single entry in DynExp's log.
Definition Util.h:1101
LogEntry(std::string Message, ErrorType Type, std::chrono::system_clock::time_point TimePoint)
Definition Util.h:1102
const std::string Message
String describing the log entry including reasons and consequences of the message.
Definition Util.h:1105
const ErrorType Type
DynExp error code from DynExpErrorCodes::DynExpErrorCodes associated with the log enty
Definition Util.h:1106
const std::chrono::system_clock::time_point TimePoint
Time point associated with the log enty.
Definition Util.h:1107
Data associated with a warning. The class is convertible to bool (true if it describes an error/warni...
Definition Util.h:1029
const std::string Function
Function in source code where the warning occurred.
Definition Util.h:1049
const std::string Description
String describing the reason and consequences of the warning.
Definition Util.h:1046
const std::string File
Source code file where the warning occurred.
Definition Util.h:1050
const size_t Line
Line in source code where the warning occurred.
Definition Util.h:1048
WarningData(std::string Description, const int ErrorCode=DynExpErrorCodes::GeneralError, const size_t Line=0, std::string Function="", std::string File="")
Definition Util.h:1039
WarningData()
Default constructor sets ErrorCode to a non-error code.
Definition Util.h:1033
const int ErrorCode
DynExp error code from DynExpErrorCodes::DynExpErrorCodes
Definition Util.h:1047
WarningData(std::string Description, const int ErrorCode=DynExpErrorCodes::GeneralError, const std::source_location Location=std::source_location::current())
Definition Util.h:1035
Checks whether a type T is contained in a template parameter pack of types ListTs.
Definition Util.h:298