From bad4827b34c67360de9b7059575bdfd3d216e51c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 2 Jul 2025 22:18:39 +0200 Subject: [PATCH] Upgrade: Literal can be constexpr Only minor rearrangements necessary to make that possible with C++20 And while at this change (which requires a full rebuild of Lumiera) - simplify the defined comparison operators, as C++20 can infer most variations - also mark various usages of `const char*` either as Literal or CStr Remark: regarding copyright, up to now this is entirely my work, with two major creation steps in 2008 (conception) and in 2017 (introduction of a symbol table) --- src/include/lifecycle.h | 8 +- src/lib/allocator-handle.hpp | 2 +- src/lib/diff/gen-node.hpp | 4 +- src/lib/error.hpp | 21 +-- src/lib/format-string.cpp | 2 +- src/lib/format-string.hpp | 22 +-- src/lib/idi/entry-id.hpp | 4 +- src/lib/lifecycle.cpp | 8 +- src/lib/path-array.hpp | 7 +- src/lib/symbol-impl.cpp | 32 +--- src/lib/symbol.hpp | 168 +++++++++--------- src/lib/test/event-log.cpp | 6 +- src/lib/test/event-log.hpp | 10 +- src/lib/test/test-helper.hpp | 8 +- src/lib/typed-counter.hpp | 2 +- src/lib/util.hpp | 4 +- src/stage/ctrl/actions.hpp | 2 +- src/stage/ctrl/ui-dispatcher.hpp | 2 +- src/stage/gtk-lumiera.cpp | 2 +- src/stage/interact/interaction-director.cpp | 2 +- src/stage/interact/ui-coord-resolver.hpp | 6 +- src/stage/widget/menu-button.cpp | 6 +- src/stage/widget/menu-button.hpp | 2 +- src/stage/workspace/dock-area.cpp | 4 +- src/stage/workspace/dock-area.hpp | 4 +- src/stage/workspace/panel-manager.hpp | 4 +- src/steam/asset/media.cpp | 22 --- src/steam/asset/media.hpp | 4 - src/steam/control/command-invocation.hpp | 2 +- src/steam/control/handling-pattern.cpp | 2 +- src/steam/control/stypemanager.cpp | 2 +- src/steam/control/stypemanager.hpp | 2 +- src/steam/mobject/session/session.cpp | 10 +- src/vault/media-access-facade.hpp | 9 +- .../control/command-instance-manager-test.cpp | 2 +- .../core/steam/control/command-setup-test.cpp | 2 +- .../mobject/session/query-resolver-test.cpp | 2 +- tests/library/item-wrapper-test.cpp | 4 +- tests/library/lazy-init-test.cpp | 2 +- tests/library/life-cycle-test.cpp | 2 +- .../plugin/test-cpp-plugin/example-plugin.cpp | 4 +- tests/stage/gen-node-location-query.hpp | 6 +- tests/stage/test/mock-elm.hpp | 2 +- wiki/thinkPad.ichthyo.mm | 22 ++- 44 files changed, 209 insertions(+), 234 deletions(-) diff --git a/src/include/lifecycle.h b/src/include/lifecycle.h index 3fb127bda..aa9f37206 100644 --- a/src/include/lifecycle.h +++ b/src/include/lifecycle.h @@ -41,11 +41,11 @@ namespace lumiera { using lib::Symbol; //defined in liblumiera.so - extern const char * ON_BASIC_INIT; ///< automatic static init. treated specially to run as soon as possible - extern const char * ON_GLOBAL_INIT; ///< to be triggered in main() @note no magic! - extern const char * ON_GLOBAL_SHUTDOWN; ///< to be triggered at the end of main() @note no magic! + extern CStr ON_BASIC_INIT; ///< automatic static init. treated specially to run as soon as possible + extern CStr ON_GLOBAL_INIT; ///< to be triggered in main() @note no magic! + extern CStr ON_GLOBAL_SHUTDOWN; ///< to be triggered at the end of main() @note no magic! - extern const char * ON_EMERGENCY; ///< activated on shutdown after premature failure of a subsystem + extern CStr ON_EMERGENCY; ///< activated on shutdown after premature failure of a subsystem // client code is free to register and use additional lifecycle events diff --git a/src/lib/allocator-handle.hpp b/src/lib/allocator-handle.hpp index 00c787724..6914dbe3b 100644 --- a/src/lib/allocator-handle.hpp +++ b/src/lib/allocator-handle.hpp @@ -334,7 +334,7 @@ namespace lib { { storage_.erase (pos); // EX_FREE - const char* errID = lumiera_error(); + CStr errID = lumiera_error(); ERROR (memory, "Allocation failed with unknown exception. " "Lumiera errorID=%s", errID?errID:"??"); throw; diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index bb7d088f5..2957d6047 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -269,11 +269,11 @@ namespace diff{ , data(std::forward(val)) { } - GenNode(string const& symbolicID, const char* text) + GenNode(string const& symbolicID, CStr text) : GenNode(symbolicID, string(text)) { } - GenNode(const char* text) + GenNode(CStr text) : GenNode(string(text)) { } diff --git a/src/lib/error.hpp b/src/lib/error.hpp index 8ad0bb0b8..e6d9acb35 100644 --- a/src/lib/error.hpp +++ b/src/lib/error.hpp @@ -39,19 +39,20 @@ #include #include +using CStr = const char*; + #define LERR_(_NAME_) lumiera::error::LUMIERA_ERROR_##_NAME_ namespace lumiera { - - using std::string; - using CStr = const char*; - namespace error { /** error-ID for unspecified exceptions */ LUMIERA_ERROR_DECLARE(EXCEPTION); } + using std::string; + + /** * Interface and Base definition for all Lumiera Exceptions. @@ -266,13 +267,13 @@ namespace lumiera { #define ERROR_LOG_AND_IGNORE(_FLAG_,_OP_DESCR_) \ catch (std::exception& problem) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ WARN (_FLAG_, "%s failed: %s", _OP_DESCR_, problem.what()); \ TRACE (debugging, "Error flag was: %s", errID);\ } \ catch (...) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ ERROR (_FLAG_, "%s failed with unknown exception; " \ "error flag is: %s" \ , _OP_DESCR_, errID?errID:"??"); \ @@ -281,14 +282,14 @@ namespace lumiera { #define ERROR_LOG_AND_RETHROW(_FLAG_,_OP_DESCR_) \ catch (std::exception& problem) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ WARN (_FLAG_, "%s failed: %s", _OP_DESCR_, problem.what()); \ TRACE (debugging, "Error flag was: %s", errID); \ throw; \ } \ catch (...) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ ERROR (_FLAG_, "%s failed with unknown exception; " \ "error flag is: %s" \ , _OP_DESCR_, errID?errID:"??"); \ @@ -304,7 +305,7 @@ namespace lumiera { #define ON_EXCEPTION_RETURN(_VAL_,_OP_DESCR_) \ catch (std::exception& problem) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ WARN (stage, "%s (Handler) failed: %s", \ _OP_DESCR_, problem.what()); \ TRACE (debugging, "Error flag was: %s", errID); \ @@ -312,7 +313,7 @@ namespace lumiera { } \ catch (...) \ { \ - const char* errID = lumiera_error(); \ + CStr errID = lumiera_error(); \ ERROR (stage, "(Handler) %s failed with " \ "unknown exception; error flag is: %s" \ , _OP_DESCR_, errID?errID:"??"); \ diff --git a/src/lib/format-string.cpp b/src/lib/format-string.cpp index 9142bc050..2086e25f9 100644 --- a/src/lib/format-string.cpp +++ b/src/lib/format-string.cpp @@ -76,7 +76,7 @@ namespace util { /** in case the formatting of a (primitive) value fails, * we try to supply an error indicator instead */ void - pushFailsafeReplacement (std::byte* formatter, const char* errorMsg =NULL) + pushFailsafeReplacement (std::byte* formatter, CStr errorMsg =nullptr) try { string placeholder(" friend bool operator != (_Fmt const& fmt, X const& x) { return not (fmt == x); } @@ -299,7 +299,7 @@ namespace util { inline void _clear_errorflag() { - const char* errID = lumiera_error(); + CStr errID = lumiera_error(); TRACE_IF (errID, progress, "Lumiera errorstate '%s' cleared.", errID); } @@ -318,7 +318,7 @@ namespace util { inline string _log_unknown_exception() { - const char* errID = lumiera_error(); + CStr errID = lumiera_error(); if (errID) ERROR (progress, "Unknown error while invoking custom string conversion. Lumiera error flag = %s", errID); else @@ -368,10 +368,10 @@ namespace util { }; template<> - struct _Fmt::Converter + struct _Fmt::Converter { static void - dump (const char* cString, Implementation& impl) + dump (CStr cString, Implementation& impl) { format (cString? cString : BOTTOM_INDICATOR, impl); } @@ -473,7 +473,7 @@ namespace util { } inline bool - operator== (_Fmt const& fmt, const char * const cString) + operator== (_Fmt const& fmt, CStr const cString) { return string(fmt) == string(cString); } @@ -485,7 +485,7 @@ namespace util { } inline bool - operator== (const char * const cString, _Fmt const& fmt) + operator== (CStr const cString, _Fmt const& fmt) { return fmt == cString; } diff --git a/src/lib/idi/entry-id.hpp b/src/lib/idi/entry-id.hpp index 701770129..281e92775 100644 --- a/src/lib/idi/entry-id.hpp +++ b/src/lib/idi/entry-id.hpp @@ -234,7 +234,7 @@ namespace idi { : BareEntryID (util::sanitise(symbolID), getTypeHash()) { } explicit - EntryID (const char* symbolID) + EntryID (CStr symbolID) : BareEntryID (util::sanitise(symbolID), getTypeHash()) { } @@ -296,7 +296,7 @@ namespace idi { RandID (string const& symbolID) : BareEntryID{util::sanitise (symbolID)} { } - RandID (const char* symbolID) + RandID (CStr symbolID) : BareEntryID{util::sanitise (symbolID)} { } RandID (Symbol const& internalSymbol) diff --git a/src/lib/lifecycle.cpp b/src/lib/lifecycle.cpp index 899130122..f7c92513f 100644 --- a/src/lib/lifecycle.cpp +++ b/src/lib/lifecycle.cpp @@ -76,11 +76,11 @@ namespace lumiera { - const char * ON_BASIC_INIT ("ON_BASIC_INIT"); - const char * ON_GLOBAL_INIT ("ON_GLOBAL_INIT"); - const char * ON_GLOBAL_SHUTDOWN ("ON_GLOBAL_SHUTDOWN"); + CStr ON_BASIC_INIT ("ON_BASIC_INIT"); + CStr ON_GLOBAL_INIT ("ON_GLOBAL_INIT"); + CStr ON_GLOBAL_SHUTDOWN ("ON_GLOBAL_SHUTDOWN"); - const char * ON_EMERGENCY ("ON_EMERGENCY"); + CStr ON_EMERGENCY ("ON_EMERGENCY"); } // namespace lumiera diff --git a/src/lib/path-array.hpp b/src/lib/path-array.hpp index 41c030288..2d13f54ea 100644 --- a/src/lib/path-array.hpp +++ b/src/lib/path-array.hpp @@ -226,7 +226,6 @@ namespace lib { { static_assert (0 < chunk_size, "PathArray chunk_size must be nonempty"); - using CcP = const char*; using LiteralArray = std::array; LiteralArray elms_; @@ -245,8 +244,8 @@ namespace lib { PathArray (IndexSeq ,IndexSeq ,ARGS&& ...args) - : elms_{pickInit (forward(args)...) ...} - , tail_{pickArg (forward(args)...) ...} + : elms_{pickInit (forward(args)...) ...} + , tail_{pickArg (forward(args)...) ...} { this->normalise(); } @@ -492,7 +491,7 @@ namespace lib { normalise() { if (size() == 0) return; - const char* fill = Symbol::EMPTY; + CStr fill = Symbol::EMPTY; Literal* end = elms_.end(); Literal* pos = elms_.begin(); diff --git a/src/lib/symbol-impl.cpp b/src/lib/symbol-impl.cpp index 21bdc3b2b..8585f34ca 100644 --- a/src/lib/symbol-impl.cpp +++ b/src/lib/symbol-impl.cpp @@ -2,7 +2,7 @@ Symbol(impl) - helpers for working with literal string IDs Copyright (C) - 2009, Hermann Vosseler + 2009,2017 Hermann Vosseler   **Lumiera** is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the @@ -12,15 +12,10 @@ * *****************************************************************/ /** @file symbol-impl.cpp - ** Collection of helpers for working with the lib::Symbol. - ** - ** @todo currently as of 9/09 this is more of a placeholder. - ** And maybe a location for collecting small bits of implementation, - ** which could be usable later for real Symbol and Literal datatypes. - ** - ** lib::Symbol - ** control::CommandRegistry for usage example of the hash function. - ** + ** Implementation functionality to support definition of lib::Symbol. + ** @see lib::Symbol + ** @see control::CommandRegistry for usage example of the hash function. + ** @see symbol-table.hpp for the implementation of _interned strings_ */ @@ -45,7 +40,6 @@ namespace lib { const size_t STRING_MAX_RELEVANT = LUMIERA_IDSTRING_MAX_RELEVANT; - namespace { // global symbol table SymbolTable& @@ -54,12 +48,6 @@ namespace lib { static SymbolTable theSymbolTable; return theSymbolTable; // Meyer's Singleton } - - inline int - strNcmp (CStr a, CStr b, size_t len) - { - return a == b ? 0 : std::strncmp (a?a:"", b?b:"", len); - } } @@ -87,14 +75,6 @@ namespace lib { - /** equality on Literal and Symbol values is defined - * based on the content, not the address. */ - bool - Literal::operator== (CStr charPtr) const - { - return 0 == strNcmp (this->str_, charPtr, STRING_MAX_RELEVANT); - } - /** generate hash value based on the Literal's contents. * This function is intended to be picked up by ADL, and should be usable @@ -107,7 +87,7 @@ namespace lib { if (literal) { size_t cnt = 1; - const char *pos = literal; + CStr pos = literal; for ( ; cnt <= STRING_MAX_RELEVANT and *pos ; ++cnt, ++pos ) hash_combine (hash, *pos); } diff --git a/src/lib/symbol.hpp b/src/lib/symbol.hpp index 09ebda790..d6c3504ed 100644 --- a/src/lib/symbol.hpp +++ b/src/lib/symbol.hpp @@ -2,7 +2,7 @@ SYMBOL.hpp - symbolic constant datatype Copyright (C) - 2008, Hermann Vosseler + 2008,2017 Hermann Vosseler   **Lumiera** is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the @@ -16,21 +16,22 @@ ** Instead of working just with pointers, which could represent pretty much anything, ** it is prudent to express the meaning at interfaces and for variables and members explicitly. ** - ** On concept level, while a string is just some sequence of characters and nothing can be said - ** about mutability or lifetime, a Literal on the contrary is meant to be _static._ It is fixed - ** and assumed to exist literally as is during the whole lifetime of the execution. The concept - ** of a Symbol is related, yet slightly different: it is meant to be a distinguishable fixed, - ** unique token. _Identical sequence_ of characters means we have exactly the _same Symbol._ + ** On conceptual level, while a **string** is just some sequence of characters and nothing can be + ** said about its mutability or lifetime, a **Literal** is explicitly meant to be _static._ It is + ** a fixed sequence of characters placed in a stable memory location and assumed to exist during + ** the whole lifetime of the execution. The concept of a **Symbol** is slightly different: it is + ** meant to be a distinguishable, fixed, unique token. An _Identical sequence_ of characters means + ** we have _exactly the same Symbol_. ** ** These concepts can be fused by treating Symbol as a specialisation of Literal, additionally ** maintaining an automatically populated, static [symbol table](\ref symbol-table.hpp), and ** we close the circle by allowing Symbol instances to be created from strings at runtime. ** - ** @remark this started on occasion 11/2008, just with a typedef to mark assumption on interfaces - ** for rules based configuration in the Steam-Layer. Over time, conversions, comparison and - ** hashcode implementation were added. It turned out that the most smooth integration in - ** coding practice is achieved when allowing transparent conversion for Literal, but not - ** for Symbol or std::string. + ** @remark this abstraction was first used occasionally 11/2008, at that time just as a typedef + ** to mark assumption on the new interfaces for rules based configuration in the Steam-Layer. + ** Over time, conversions, comparison and hashcode implementation were added. It turned out + ** that the most smooth integration in coding practice is achieved when allowing transparent + ** conversion between Literal ⟷ CStr, but not for Symbol or std::string. ** @todo 9/2017 consider this mostly as settled, but might require some finishing touches ** - maybe improve interoperation of Symbol and std::string ** - investigate performance of the automatic symbol table @@ -64,7 +65,7 @@ cStr (std::string const& rendered) namespace lib { - /** inline string literal + /** Inline string literal. * This is a _marker type_ to indicate that * - the string was given literally * - storage is _somewhere_, not managed by Literal, @@ -75,37 +76,38 @@ namespace lib { */ class Literal { - CStr str_; - + CStr str_; + public: - /** empty string by default */ - Literal() noexcept; - - Literal (const char* literal) noexcept - : str_(literal) - { } - - Literal (Literal const&) noexcept = default; - Literal& operator= (Literal const&) noexcept = default; - - operator CStr() const { return str_; } - const char* c() const { return str_; } - - bool - empty() const - { - return not str_ or 0 == std::strlen(str_); - } - - bool operator== (CStr cString) const; + /** empty string by default */ + constexpr Literal() noexcept; + + constexpr Literal (CStr literal) noexcept + : str_(literal) + { } + + constexpr Literal (Literal const&) noexcept = default; + constexpr Literal& operator= (Literal const&) noexcept = default; + + constexpr operator CStr() const { return str_; } + constexpr const char* c() const { return str_; } + + constexpr bool + empty() const + { + return not str_ or 0 == std::strlen(str_); + } + + constexpr bool operator== (CStr cString) const; + constexpr size_t length() const; protected: - /** Assignment generally prohibited */ - Literal& operator= (CStr newStr) noexcept - { - str_ = newStr; - return *this; - } + /** Assignment generally prohibited */ + Literal& operator= (CStr newStr) noexcept + { + str_ = newStr; + return *this; + } }; @@ -140,31 +142,50 @@ namespace lib { Symbol (Literal const& base, CStr ext) : Symbol{base, std::string(ext)} { } - - Symbol (Symbol const&) = default; - Symbol (Symbol &&) = default; - - Symbol& operator= (Symbol const&) = default; - Symbol& operator= (Symbol &&) = default; - - explicit operator bool() const { return not empty(); } - bool empty() const { return *this == BOTTOM.c() or *this == EMPTY.c(); } - - size_t - length() const - { - return std::strlen(c()); - } + + Symbol (Symbol const&) = default; + Symbol (Symbol &&) = default; + + Symbol& operator= (Symbol const&) = default; + Symbol& operator= (Symbol &&) = default; + + explicit operator bool() const { return not empty(); } + bool empty() const { return *this == BOTTOM.c() or *this == EMPTY.c(); } }; + /** @note storage guaranteed to exist */ + constexpr inline Literal::Literal() noexcept : str_(Symbol::EMPTY) { } + + namespace{ + constexpr inline int + strNcmp (CStr a, CStr b, size_t len) + { + return a == b ? 0 : std::strncmp (a?a:"", b?b:"", len); + } + } + /** safety guard: maximum number of chars to process. * For comparisons, hash calculations etc., when dealing * with raw char ptrs (typically literal values) */ extern const size_t STRING_MAX_RELEVANT; - /** @note storage guaranteed to exist */ - inline Literal::Literal() noexcept : str_(Symbol::EMPTY) { } + /** equality on Literal and Symbol values is defined + * based on the content, not the address. */ + constexpr inline bool + Literal::operator== (CStr charPtr) const + { + return 0 == strNcmp (this->str_, charPtr, STRING_MAX_RELEVANT); + } + + constexpr inline size_t + Literal::length() const + { + return std::strlen(c()); + } + + + /* ===== to be picked up by ADL ===== */ @@ -175,35 +196,16 @@ namespace lib { /* === equality comparisons === */ - inline bool operator== (Literal const& s1, Literal const& s2) { return s1.operator== (s2.c()); } - inline bool operator== (Symbol const& s1, Symbol const& s2) { return s1.c() == s2.c(); } ///< @note comparison of symbol table entries + constexpr inline bool operator== (Literal const& s1, Literal const& s2) { return s1.operator== (s2.c()); } + constexpr inline bool operator== (Symbol const& s1, Symbol const& s2) { return s1.c() == s2.c(); } ///< @note comparison of symbol table entries /* === mixed comparisons === */ - inline bool operator== (CStr s1, Literal s2) { return s2.operator== (s1); } - inline bool operator== (Symbol s1, CStr s2) { return s1.operator== (s2); } - inline bool operator== (CStr s1, Symbol s2) { return s2.operator== (s1); } - inline bool operator== (Literal s1, Symbol s2) { return s1.operator== (s2.c()); } - inline bool operator== (Symbol s1, Literal s2) { return s2.operator== (s1.c()); } - inline bool operator== (Literal s1, std::string s2) { return s1.operator== (s2.c_str()); } - inline bool operator== (std::string s1, Literal s2) { return s2.operator== (s1.c_str()); } - inline bool operator== (Symbol s1, std::string s2) { return s1.operator== (s2.c_str()); } - inline bool operator== (std::string s1, Symbol s2) { return s2.operator== (s1.c_str()); } - - /* === negations === */ - - inline bool operator!= (Literal const& s1, Literal const& s2) { return not s1.operator== (s2.c()); } - inline bool operator!= (Symbol const& s1, Symbol const& s2) { return not (s1.c() == s2.c()); } - inline bool operator!= (Literal s1, CStr s2) { return not s1.operator== (s2); } - inline bool operator!= (CStr s1, Literal s2) { return not s2.operator== (s1); } - inline bool operator!= (Symbol s1, CStr s2) { return not s1.operator== (s2); } - inline bool operator!= (CStr s1, Symbol s2) { return not s2.operator== (s1); } - inline bool operator!= (Literal s1, Symbol s2) { return not s1.operator== (s2.c()); } - inline bool operator!= (Symbol s1, Literal s2) { return not s2.operator== (s1.c()); } - inline bool operator!= (Literal s1, std::string s2) { return not s1.operator== (s2.c_str()); } - inline bool operator!= (std::string s1, Literal s2) { return not s2.operator== (s1.c_str()); } - inline bool operator!= (Symbol s1, std::string s2) { return not s1.operator== (s2.c_str()); } - inline bool operator!= (std::string s1, Symbol s2) { return not s2.operator== (s1.c_str()); } + constexpr inline bool operator== (CStr s1, Literal s2) { return s2.operator== (s1); } + constexpr inline bool operator== (Symbol s1, CStr s2) { return s1.operator== (s2); } + constexpr inline bool operator== (Literal s1, Symbol s2) { return s1.operator== (s2.c()); } + constexpr inline bool operator== (Literal s1, std::string const& s2) { return s1.operator== (s2.c_str()); } + constexpr inline bool operator== (Symbol s1, std::string const& s2) { return s1.operator== (s2.c_str()); } diff --git a/src/lib/test/event-log.cpp b/src/lib/test/event-log.cpp index 28a49b523..cc5a16680 100644 --- a/src/lib/test/event-log.cpp +++ b/src/lib/test/event-log.cpp @@ -588,7 +588,7 @@ namespace test{ } EventMatch& - EventMatch::on (const char* targetID) + EventMatch::on (CStr targetID) { refineSerach (solution_, matchAttribute("this",targetID)); evaluateQuery ("match-this(\""+string(targetID)+"\")"); @@ -663,7 +663,7 @@ namespace test{ } EventLog& - EventLog::clear (const char* alteredLogID) + EventLog::clear (CStr alteredLogID) { return clear (string{alteredLogID}); } @@ -700,7 +700,7 @@ namespace test{ } EventLog& - EventLog::call (const char* target, const char* function, ArgSeq&& args) + EventLog::call (CStr target, CStr function, ArgSeq&& args) { return call (string(target), string(function), std::forward(args)); } diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index a25be10a8..4c0761917 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -238,7 +238,7 @@ namespace test{ EventMatch& attrib (string key, string valueMatch); EventMatch& id (string classifier); EventMatch& on (string targetID); - EventMatch& on (const char* targetID); + EventMatch& on (CStr targetID); template EventMatch& on (const X *const targetObj) @@ -298,7 +298,7 @@ namespace test{ EventLog (string logID); explicit - EventLog (const char* logID) + EventLog (CStr logID) : EventLog(string(logID)) { } @@ -331,7 +331,7 @@ namespace test{ /** purge log contents while retaining just the original Header-ID */ EventLog& clear(); EventLog& clear (string alteredLogID); - EventLog& clear (const char* alteredLogID); + EventLog& clear (CStr alteredLogID); template EventLog& @@ -372,7 +372,7 @@ namespace test{ /** Log a function call with a sequence of stringified arguments */ EventLog& call (string target, string function, ArgSeq&& args); - EventLog& call (const char* target, const char* function, ArgSeq&& args); + EventLog& call (CStr target, CStr function, ArgSeq&& args); /** Log a function call with arbitrary arguments */ template @@ -392,7 +392,7 @@ namespace test{ template EventLog& - call (const char* target, string function, ARGS const& ...args) + call (CStr target, string function, ARGS const& ...args) { return call (string(target), function, args...); } diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp index e55922f3b..faeeab38f 100644 --- a/src/lib/test/test-helper.hpp +++ b/src/lib/test/test-helper.hpp @@ -105,7 +105,7 @@ namespace test{ */ template inline string - showSizeof (T const* obj =0, const char* name =0) + showSizeof (T const* obj =0, CStr name =0) { return showSizeof (obj? sizeof(*obj) : sizeof(T), name? name : util::typeStr(obj)); @@ -114,14 +114,14 @@ namespace test{ template inline meta::disable_if, string > // note:: force invocations with pointer to the first overload - showSizeof (T const& obj, const char* name=0) + showSizeof (T const& obj, CStr name =nullptr) { return showSizeof (&obj, name); } template inline string - showSizeof (const char* name) + showSizeof (CStr name) { return showSizeof (nullptr, name); } @@ -375,7 +375,7 @@ namespace test{ * \endcode */ inline lib::test::ExpectString -operator""_expect (const char* lit, size_t siz) +operator""_expect (CStr lit, size_t siz) { return lib::test::ExpectString{lit, siz}; } diff --git a/src/lib/typed-counter.hpp b/src/lib/typed-counter.hpp index 4c2773963..0343fc57d 100644 --- a/src/lib/typed-counter.hpp +++ b/src/lib/typed-counter.hpp @@ -236,7 +236,7 @@ namespace lib { } friend string - operator+ (const char* prefix, FamilyMember id) + operator+ (CStr prefix, FamilyMember id) { return string(prefix)+id; } diff --git a/src/lib/util.hpp b/src/lib/util.hpp index fdccea057..1c63cf0b9 100644 --- a/src/lib/util.hpp +++ b/src/lib/util.hpp @@ -46,14 +46,14 @@ namespace std {// forward declarations to avoid pervasive includes } -const char* cStr (std::string const&); +using CStr = const char*; +CStr cStr (std::string const&); namespace util { using std::string; - using CStr = const char*; template diff --git a/src/stage/ctrl/actions.hpp b/src/stage/ctrl/actions.hpp index 4c52ca8fd..930aee039 100644 --- a/src/stage/ctrl/actions.hpp +++ b/src/stage/ctrl/actions.hpp @@ -361,7 +361,7 @@ namespace ctrl { // Temporary Junk void - unimplemented (const char* todo) + unimplemented (Literal todo) { WARN (stage, "%s is not yet implemented. So sorry.", todo); } diff --git a/src/stage/ctrl/ui-dispatcher.hpp b/src/stage/ctrl/ui-dispatcher.hpp index 82adb0b38..9ab580651 100644 --- a/src/stage/ctrl/ui-dispatcher.hpp +++ b/src/stage/ctrl/ui-dispatcher.hpp @@ -83,7 +83,7 @@ namespace ctrl { namespace { /** @note reads and clears the lumiera error flag */ inline string - generateErrorResponse (const char* problem = "unexpected problem") + generateErrorResponse (lib::Literal problem = "unexpected problem") { static _Fmt messageTemplate{"asynchronous UI response failed: %s (error flag was: %s)"}; string response{messageTemplate % problem % lumiera_error()}; diff --git a/src/stage/gtk-lumiera.cpp b/src/stage/gtk-lumiera.cpp index 446c0fba6..fd2d21a09 100644 --- a/src/stage/gtk-lumiera.cpp +++ b/src/stage/gtk-lumiera.cpp @@ -145,7 +145,7 @@ namespace stage { } catch(...) { - const char* errID = lumiera_error(); // clear C-style error flag + CStr errID = lumiera_error(); // clear C-style error flag WARN (stage, "Unexpected error while starting the GUI thread."); if (errID) TRACE (stage, "Error flag was: %s", errID); diff --git a/src/stage/interact/interaction-director.cpp b/src/stage/interact/interaction-director.cpp index b83250066..ecccd6750 100644 --- a/src/stage/interact/interaction-director.cpp +++ b/src/stage/interact/interaction-director.cpp @@ -117,7 +117,7 @@ namespace interact { namespace { // Temporary Junk inline void - unimplemented (const char* todo) + unimplemented (Literal todo) { WARN (stage, "%s is not yet implemented. So sorry.", todo); } diff --git a/src/stage/interact/ui-coord-resolver.hpp b/src/stage/interact/ui-coord-resolver.hpp index 3525dcc16..ae4b06a68 100644 --- a/src/stage/interact/ui-coord-resolver.hpp +++ b/src/stage/interact/ui-coord-resolver.hpp @@ -279,10 +279,10 @@ namespace interact { struct Resolution { - const char* anchor = nullptr; - size_t depth = 0; + CStr anchor = nullptr; + size_t depth = 0; unique_ptr covfefe{}; - bool isResolved = false; + bool isResolved = false; }; LocationQuery& query_; diff --git a/src/stage/widget/menu-button.cpp b/src/stage/widget/menu-button.cpp index 9c6183056..4a108431d 100644 --- a/src/stage/widget/menu-button.cpp +++ b/src/stage/widget/menu-button.cpp @@ -113,11 +113,11 @@ namespace widget{ void - MenuButton::append (const char *slug, const char* title, + MenuButton::append (CStr slug, CStr title, sigc::slot& callback, bool toggle) { - uString uSlug (slug); - uString uTitle (_(title)); + uString uSlug{slug}; + uString uTitle{_(title)}; append (uSlug, uTitle, callback, toggle); } diff --git a/src/stage/widget/menu-button.hpp b/src/stage/widget/menu-button.hpp index 7496dde8f..39c19e9ef 100644 --- a/src/stage/widget/menu-button.hpp +++ b/src/stage/widget/menu-button.hpp @@ -95,7 +95,7 @@ namespace widget { * @param callback The signal handler when clicked * @param toggle */ - void append (const char* slug, const char* title, sigc::slot& callback, bool toggle=false); + void append (CStr slug, CStr title, sigc::slot& callback, bool toggle=false); /** Append a Gtk::SeparatorMenuItem to the Menu */ diff --git a/src/stage/workspace/dock-area.cpp b/src/stage/workspace/dock-area.cpp index 644170d1c..523c1bb3f 100644 --- a/src/stage/workspace/dock-area.cpp +++ b/src/stage/workspace/dock-area.cpp @@ -261,7 +261,7 @@ namespace workspace { int - DockArea::findPanelDescription (const char* class_name) + DockArea::findPanelDescription (CStr class_name) { REQUIRE(class_name); @@ -313,7 +313,7 @@ namespace workspace { panel::Panel* - DockArea::createPanel_by_name (const char* class_name) + DockArea::createPanel_by_name (CStr class_name) { REQUIRE(class_name); const int index = findPanelDescription(class_name); diff --git a/src/stage/workspace/dock-area.hpp b/src/stage/workspace/dock-area.hpp index 30c6ac01b..8cd5ef822 100644 --- a/src/stage/workspace/dock-area.hpp +++ b/src/stage/workspace/dock-area.hpp @@ -173,7 +173,7 @@ namespace workspace { * @return Returns the index of the panel description found, or -1 * if no description was found for this type. */ - static int findPanelDescription (const char* class_name); + static int findPanelDescription (CStr class_name); /** * Creates a panel by description index. @@ -195,7 +195,7 @@ namespace workspace { * @param class_name The name of the object class to create. * @return Returns a pointer to the new instantiated panel object. */ - panel::Panel* createPanel_by_name (const char* class_name); + panel::Panel* createPanel_by_name (CStr class_name); /** * Gets the type of a given panel. diff --git a/src/stage/workspace/panel-manager.hpp b/src/stage/workspace/panel-manager.hpp index 38cbcaa5b..697a7bcea 100644 --- a/src/stage/workspace/panel-manager.hpp +++ b/src/stage/workspace/panel-manager.hpp @@ -166,7 +166,7 @@ namespace workspace { * @return Returns the index of the panel description found, or -1 * if no description was found for this type. */ - static int findPanelDescription (const char* class_name); + static int findPanelDescription (CStr class_name); /** * Creates a panel by description index. @@ -188,7 +188,7 @@ namespace workspace { * @param class_name The name of the object class to create. * @return Returns a pointer to the new instantiated panel object. */ - panel::Panel* createPanel_by_name (const char* class_name); + panel::Panel* createPanel_by_name (CStr class_name); /** * Gets the type of a given panel. diff --git a/src/steam/asset/media.cpp b/src/steam/asset/media.cpp index 48e09e245..56132401a 100644 --- a/src/steam/asset/media.cpp +++ b/src/steam/asset/media.cpp @@ -192,28 +192,6 @@ namespace asset { Category cat(kind); return operator() (file, cat); } - - - MediaFactory::PType - MediaFactory::operator() (const char* file, const Category& cat) - { - if (!file) file = ""; - return operator() (string(file),cat); - } - - MediaFactory::PType - MediaFactory::operator() (const char* file, asset::Kind kind) - { - if (!file) file = ""; - return operator() (string(file),kind); - } - - MediaFactory::PType - MediaFactory::operator() (Asset::Ident& key, const char* file) - { - if (!file) file = ""; - return operator() (key, string(file)); - } /** Factory method for creating a Clip asset based diff --git a/src/steam/asset/media.hpp b/src/steam/asset/media.hpp index 5ad5a9d1a..157bc131d 100644 --- a/src/steam/asset/media.hpp +++ b/src/steam/asset/media.hpp @@ -141,10 +141,6 @@ namespace asset { PType operator() (const string& file, const Category& cat); PType operator() (const string& file, asset::Kind); - PType operator() (Asset::Ident& key, const char* file); ///< convenience overload using C-String - PType operator() (const char* file, const Category& cat); - PType operator() (const char* file, asset::Kind); - lib::P operator() (Media& mediaref); diff --git a/src/steam/control/command-invocation.hpp b/src/steam/control/command-invocation.hpp index 88a850e52..d28ab423f 100644 --- a/src/steam/control/command-invocation.hpp +++ b/src/steam/control/command-invocation.hpp @@ -137,7 +137,7 @@ namespace control { inline com::RuntimeCheckedCommandInvoker - invoke (const char* cmdID) + invoke (CStr cmdID) { return invoke(Symbol(cmdID)); } diff --git a/src/steam/control/handling-pattern.cpp b/src/steam/control/handling-pattern.cpp index 349affff6..2bb00eb60 100644 --- a/src/steam/control/handling-pattern.cpp +++ b/src/steam/control/handling-pattern.cpp @@ -45,7 +45,7 @@ namespace control { ExecResult HandlingPattern::invoke (CommandImpl& command, string id, Action action) const { - const char* cmdName = cStr(id); + CStr cmdName = cStr(id); TRACE (proc_dbg, "invoking %s...", cmdName); static _Fmt err_pre ("Error state detected, %s *NOT* invoked."); static _Fmt err_post ("Error state after %s invocation."); diff --git a/src/steam/control/stypemanager.cpp b/src/steam/control/stypemanager.cpp index a356ed57c..7f8450268 100644 --- a/src/steam/control/stypemanager.cpp +++ b/src/steam/control/stypemanager.cpp @@ -59,7 +59,7 @@ namespace control { * their basic setup functions using this hook, which can be done via * the C interface functions */ - const char* ON_STREAMTYPES_RESET ("ON_STREAMTYPES_RESET"); + CStr ON_STREAMTYPES_RESET ("ON_STREAMTYPES_RESET"); diff --git a/src/steam/control/stypemanager.hpp b/src/steam/control/stypemanager.hpp index 056ac3a7c..f25ec7331 100644 --- a/src/steam/control/stypemanager.hpp +++ b/src/steam/control/stypemanager.hpp @@ -90,7 +90,7 @@ namespace control { ImplFacade const& fetchImpl (StreamType::ImplFacade::TypeTag); }; - extern const char* ON_STREAMTYPES_RESET; ///< triggered to load the generic pristine default + extern CStr ON_STREAMTYPES_RESET; ///< triggered to load the generic pristine default template diff --git a/src/steam/mobject/session/session.cpp b/src/steam/mobject/session/session.cpp index 50b31ddd4..f72aecd42 100644 --- a/src/steam/mobject/session/session.cpp +++ b/src/steam/mobject/session/session.cpp @@ -84,7 +84,7 @@ namespace mobject { * session should register their basic setup functions using this hook, which can be * done via the C interface functions defined in lifecycle.h */ - const char* ON_SESSION_START = "ON_SESSION_START"; + CStr ON_SESSION_START = "ON_SESSION_START"; /** * LifecycleHook, to perform any initialisation, wiring and registrations necessary @@ -92,7 +92,7 @@ namespace mobject { * and configuration has already be loaded. Any subsystems requiring to build some indices * or wiring to keep track of the session's content should register here. */ - const char* ON_SESSION_INIT = "ON_SESSION_INIT"; + CStr ON_SESSION_INIT = "ON_SESSION_INIT"; /** * LifecycleHook, to perform post loading tasks, requiring an already completely usable @@ -103,7 +103,7 @@ namespace mobject { * fully functional client side APIs. Examples would be statistics gathering, validation * or auto-correction of the session's contents. */ - const char* ON_SESSION_READY = "ON_SESSION_READY"; + CStr ON_SESSION_READY = "ON_SESSION_READY"; /** * LifecycleHook, to commence any activity relying on an opened and fully operative session. @@ -112,7 +112,7 @@ namespace mobject { * sequence will be initiated, by detaching the engine interfaces and signalling the * scheduler to cease running render jobs. */ - const char* ON_SESSION_CLOSE ="ON_SESSION_CLOSE"; + CStr ON_SESSION_CLOSE ="ON_SESSION_CLOSE"; /** * LifecycleHook, to perform any state saving, deregistration or de-activation necessary @@ -122,7 +122,7 @@ namespace mobject { * specific/internal information into the persisted state, besides actually attaching * data to objects within the session? */ - const char* ON_SESSION_END ="ON_SESSION_END"; + CStr ON_SESSION_END ="ON_SESSION_END"; diff --git a/src/vault/media-access-facade.hpp b/src/vault/media-access-facade.hpp index 6ab97ec43..1100535d3 100644 --- a/src/vault/media-access-facade.hpp +++ b/src/vault/media-access-facade.hpp @@ -113,7 +113,7 @@ namespace vault { * for the media asset corresponding to this channel. * May be NULL or empty and need not be unique. */ - const char* chanID; + CStr chanID; /** identifier characterising the access method (or codec) * needed to get at the media data. This should be rather @@ -121,15 +121,16 @@ namespace vault { * e.g. "H264" -- anyhow, it will be used to find a * codec asset for this channel. */ - const char* codecID; + CStr codecID; /** opaque handle, which will be used later to open this * channel and retrieve some frames from it */ MediaAccessFacade::ChanHandle handle; - ChanDesc (const char* chanName=0, const char* codec=0, - MediaAccessFacade::ChanHandle h=0) + ChanDesc (CStr chanName =nullptr + ,CStr codec =nullptr + ,MediaAccessFacade::ChanHandle h =nullptr) : chanID(chanName), codecID(codec), handle(h) diff --git a/tests/core/steam/control/command-instance-manager-test.cpp b/tests/core/steam/control/command-instance-manager-test.cpp index f864044d1..7aebfcead 100644 --- a/tests/core/steam/control/command-instance-manager-test.cpp +++ b/tests/core/steam/control/command-instance-manager-test.cpp @@ -249,7 +249,7 @@ namespace test { Symbol i11 = iManager.newInstance (COMMAND_PROTOTYPE, "i1"); CHECK (i11 == i1); - CHECK ((const char*)i11 == (const char*) i1); + CHECK (CStr(i11) == CStr(i1)); // but the instances themselves are disjoint Command c13 = iManager.getInstance (i1); diff --git a/tests/core/steam/control/command-setup-test.cpp b/tests/core/steam/control/command-setup-test.cpp index 141725769..3da7d75fc 100644 --- a/tests/core/steam/control/command-setup-test.cpp +++ b/tests/core/steam/control/command-setup-test.cpp @@ -119,7 +119,7 @@ namespace test { CHECK (sizeof(def_empty) == sizeof(Literal)); CHECK (sizeof(def_empty) == sizeof(char*)); - const char* actualContent = reinterpret_cast(def_empty); + CStr actualContent = reinterpret_cast(def_empty); CHECK (actualContent == empty_text); // for convenience a string conversion is provided... diff --git a/tests/core/steam/mobject/session/query-resolver-test.cpp b/tests/core/steam/mobject/session/query-resolver-test.cpp index 6c5aef087..98c194eb8 100644 --- a/tests/core/steam/mobject/session/query-resolver-test.cpp +++ b/tests/core/steam/mobject/session/query-resolver-test.cpp @@ -66,7 +66,7 @@ namespace test{ string* next () { - static const char* lumi ="Lumiera"; + static Literal lumi{"Lumiera"}; currentText_ = string (lumi + *DummySolutions::next()); return ¤tText_; } diff --git a/tests/library/item-wrapper-test.cpp b/tests/library/item-wrapper-test.cpp index 78584d2d6..412b2bb6d 100644 --- a/tests/library/item-wrapper-test.cpp +++ b/tests/library/item-wrapper-test.cpp @@ -108,7 +108,7 @@ namespace test{ ulong l2 (rani (1000)); string s1 (randStr(50)); string s2 (randStr(50)); - const char* cp (s1.c_str()); + CStr cp (s1.c_str()); verifyWrapper (l1, l2); verifyWrapper (l1, l2); @@ -121,7 +121,7 @@ namespace test{ verifyWrapper (s1, s2); verifyWrapper (&s1, &s2); - verifyWrapper (cp, "Lumiera"); + verifyWrapper (cp, "Lumiera"); verifySaneInstanceHandling(); diff --git a/tests/library/lazy-init-test.cpp b/tests/library/lazy-init-test.cpp index 16c2b4dc8..1f23df848 100644 --- a/tests/library/lazy-init-test.cpp +++ b/tests/library/lazy-init-test.cpp @@ -152,7 +152,7 @@ namespace test{ verify_inlineStorage() { // char payload[24];// ◁─────────────────────────────── use this to make the test fail.... - const char* payload = "please look elsewhere"; + const char* payload = "I am innocent as a lamb"; auto lambda = [payload]{ return RawAddr(&payload); }; RawAddr location = lambda(); diff --git a/tests/library/life-cycle-test.cpp b/tests/library/life-cycle-test.cpp index e0bafcb09..b585b173e 100644 --- a/tests/library/life-cycle-test.cpp +++ b/tests/library/life-cycle-test.cpp @@ -34,7 +34,7 @@ namespace test { void basicInitHook () { ++basicInit; } void myCallback() { ++customCallback; } - const char* MY_DEADLY_EVENT = "dial M for murder"; + CStr MY_DEADLY_EVENT = "dial M for murder"; namespace // register them to be invoked by lifecycle event id diff --git a/tests/plugin/test-cpp-plugin/example-plugin.cpp b/tests/plugin/test-cpp-plugin/example-plugin.cpp index 0e37bbe3a..19af884eb 100644 --- a/tests/plugin/test-cpp-plugin/example-plugin.cpp +++ b/tests/plugin/test-cpp-plugin/example-plugin.cpp @@ -69,7 +69,7 @@ class ExamplePlugin_de } static void - servus (const char* m) + servus (CStr m) { cout << "Tschüss " << m << endl; } @@ -87,7 +87,7 @@ class ExamplePlugin_en } static void - bye (const char* m) + bye (CStr m) { cout << "Bye " << m << endl; } diff --git a/tests/stage/gen-node-location-query.hpp b/tests/stage/gen-node-location-query.hpp index 2df708cdb..422269e02 100644 --- a/tests/stage/gen-node-location-query.hpp +++ b/tests/stage/gen-node-location-query.hpp @@ -171,7 +171,7 @@ namespace interact { { if (depth(); diff --git a/tests/stage/test/mock-elm.hpp b/tests/stage/test/mock-elm.hpp index 7a1ddbf10..6b6f468b6 100644 --- a/tests/stage/test/mock-elm.hpp +++ b/tests/stage/test/mock-elm.hpp @@ -315,7 +315,7 @@ namespace test{ } catch(...) { - const char* errID = lumiera_error(); + CStr errID = lumiera_error(); if (errID) cerr << "Error while logging shutdown of Mock-UI-Element: " << errID < - + + - + @@ -167028,6 +167029,23 @@ Since then others have made contributions, see the log for the history. + + + + + + +

+ aber Literal kann komplett constexpr sein +

+ + +
+ +
+ + +