diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox
index 24eccc96e4..c29ed94562 100644
--- a/doc/dox/whatsnew.dox
+++ b/doc/dox/whatsnew.dox
@@ -27,7 +27,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via BUILD_SHARED_LIBS
, which retires JKQtPlotter_BUILD_STATIC_LIBS
, JKQtPlotter_BUILD_SHARED_LIBS
and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's FetchContent-API
- NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
+ NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
+ NEW add JKQTPExpected datatype
JKQTPlotter:
diff --git a/lib/jkqtcommon.pri b/lib/jkqtcommon.pri
index 590653689c..b89bb32123 100644
--- a/lib/jkqtcommon.pri
+++ b/lib/jkqtcommon.pri
@@ -27,7 +27,10 @@ isEmpty(JKQTP_COMMON_PRI_INCLUDED) {
$$PWD/jkqtcommon/jkqtpenhancedpainter.h \
$$PWD/jkqtcommon/jkqtphighrestimer.h \
$$PWD/jkqtcommon/jkqttools.h \
- $$PWD/jkqtcommon/jkqtpicons.h
+ $$PWD/jkqtcommon/jkqtpicons.h \
+ $$PWD/jkqtcommon/jkqtpcachingtools.h \
+ $$PWD/jkqtcommon/jkqtpconcurrencytools.h \
+ $$PWD/jkqtcommon/jkqtpexpected.h
@@ -41,7 +44,9 @@ isEmpty(JKQTP_COMMON_PRI_INCLUDED) {
$$PWD/jkqtcommon/jkqtpenhancedpainter.cpp \
$$PWD/jkqtcommon/jkqtphighrestimer.cpp \
$$PWD/jkqtcommon/jkqttools.cpp \
- $$PWD/jkqtcommon/jkqtpicons.cpp
+ $$PWD/jkqtcommon/jkqtpicons.cpp \
+ $$PWD/jkqtcommon/jkqtpcachingtools.cpp \
+ $$PWD/jkqtcommon/jkqtpconcurrencytools.cpp
INCLUDEPATH += $$PWD
diff --git a/lib/jkqtcommon/CMakeLists.txt b/lib/jkqtcommon/CMakeLists.txt
index 7e561ccad2..ca7b2e3342 100644
--- a/lib/jkqtcommon/CMakeLists.txt
+++ b/lib/jkqtcommon/CMakeLists.txt
@@ -47,6 +47,7 @@ target_sources(${lib_name} PUBLIC FILE_SET HEADERS TYPE HEADERS
jkqtpgeometrytools.h
jkqtpconcurrencytools.h
jkqtpcachingtools.h
+ jkqtpexpected.h
)
diff --git a/lib/jkqtcommon/jkqtpexpected.h b/lib/jkqtcommon/jkqtpexpected.h
new file mode 100644
index 0000000000..e303d77066
--- /dev/null
+++ b/lib/jkqtcommon/jkqtpexpected.h
@@ -0,0 +1,84 @@
+
+/*
+ Copyright (c) 2008-2024 Jan W. Krieger ()
+
+
+
+ This software is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef JKQTPEXPECTED_H_INCLUDED
+#define JKQTPEXPECTED_H_INCLUDED
+
+#include
+
+
+/** \brief tag type for an unexpected/error result in JKQTPExpected
+ * \ingroup jkqtptools_general
+ *
+ * \see JKQTPExpected, JKQTPUnexpected
+ */
+struct JKQTPExpectedUnexpectedType {};
+/** \brief tag for an unexpected/error result in JKQTPExpected
+ * \ingroup jkqtptools_general
+ *
+ * \see JKQTPExpected, JKQTPExpectedUnexpectedType
+ */
+inline constexpr JKQTPExpectedUnexpectedType JKQTPUnexpected {};
+
+/** \brief an "expected" datatype, which can either represent a function result of type \c T or an error of type \c E
+ * \ingroup jkqtptools_general
+ *
+ * Usage example:
+ * \code
+ * JKQTPExpected toInt(QString s) {
+ * bool ok=false;
+ * int i=s.toInt(&ok);
+ * if (ok) return {i}
+ * else return { JKQTPUnexpected, QString("cannot convert to int") };
+ * }
+ *
+ * auto r=toInt("1.0a");
+ * if (r.hasValue()) qDebug()<<"SUCCESS! i="<
+struct JKQTPExpected {
+ JKQTPExpected()=delete;
+ JKQTPExpected(const T& value_): m_hasValue(true), m_value(value_), m_error() {};
+ JKQTPExpected(const JKQTPExpected& other)=default;
+ JKQTPExpected(JKQTPExpectedUnexpectedType, const E& error_): m_hasValue(false), m_value(), m_error(error_) {};
+
+ const T& value() const {
+ if (m_hasValue) return m_value;
+ throw std::runtime_error("value not available");
+ }
+ const E& error() const {
+ if (!m_hasValue) return m_error;
+ throw std::runtime_error("error not available");
+ }
+ const bool has_value() const { return m_hasValue; }
+ operator bool() const { return m_hasValue; }
+private:
+ const bool m_hasValue;
+ const E m_error;
+ const T m_value;
+};
+
+
+#endif // JKQTPEXPECTED_H_INCLUDED