From 3dcd84232c81337bb66a8af10fb84ccc387f93ef Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 31 Mar 2017 23:44:24 +0200 Subject: [PATCH] Symbol-Table hack: the disease starts to spread (#158) we need a real symbol table implementation, so we can assemble symbols and then intern them. This was the whole purpose of inventing the class Symbol --- src/lib/symbol-impl.cpp | 21 +++++++++++++++++++++ src/lib/symbol.hpp | 14 +++++++++++++- tests/gui/test/placeholder-command.hpp | 11 +---------- tests/gui/test/test-nexus.cpp | 16 ---------------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/lib/symbol-impl.cpp b/src/lib/symbol-impl.cpp index 3762179c4..332cebe12 100644 --- a/src/lib/symbol-impl.cpp +++ b/src/lib/symbol-impl.cpp @@ -42,8 +42,12 @@ extern "C" { #include #include +#include +#include +#include using std::size_t; +using std::string; using boost::hash_combine; @@ -85,4 +89,21 @@ namespace lib { + namespace { // quick-n-dirty symbol table implementation + + /** @warning grows eternally, never shrinks */ + std::deque idStringBuffer; ////////////////////////////////TICKET #158 replace by symbol table + } + + /** @internal quick-n-dirty hack, used as workaround for creating command-IDs on the fly */ + Symbol + internedString (string&& idString) + { + idStringBuffer.emplace_back (std::forward (idString)); + return Symbol (idStringBuffer.back().c_str()); + } + /////////////////////////////////////(End)symbol-table hack + + + } // namespace lib diff --git a/src/lib/symbol.hpp b/src/lib/symbol.hpp index 3fc613572..179e4e7ad 100644 --- a/src/lib/symbol.hpp +++ b/src/lib/symbol.hpp @@ -167,7 +167,19 @@ namespace lib { const char* symP (sym); return symP + str; } - + + /* ===== temporary symbol table workaround ===== */ + + /** place the string persistently in memory. + * @todo temporary workaround, shall be replaced by lib::Symbol implementation ///////////////TICKET #157 maintain symbol table for interned strings + * @return a C-String marked as lib::Symbol, pointing + * to the permanent location in heap memory. + * @warning eternally growing, please look away... + * @see symbol-impl.cpp implementation + */ + Symbol internedString (std::string&& idString); + + } // namespace lib #endif diff --git a/tests/gui/test/placeholder-command.hpp b/tests/gui/test/placeholder-command.hpp index 931e12e6b..dc8313d3a 100644 --- a/tests/gui/test/placeholder-command.hpp +++ b/tests/gui/test/placeholder-command.hpp @@ -62,15 +62,6 @@ namespace test{ using lib::Symbol; - /** place the string persistently in memory. - * @internal used as workaround for creating command-IDs on the fly - * @todo temporary workaround, shall be replaced by lib::Symbol implementation ///////////////TICKET #157 maintain symbol table for interned strings - * @return a C-String marked as lib::Literal, pointing - * to the permanent location in heap memory. - * @see \ref test-nexus.cpp implementation - */ - Symbol internedString (string&& idString); - /** @@ -130,7 +121,7 @@ namespace test{ fabricateNewInstance (lib::test::EventLog const& invocationLog) { log_ = invocationLog; - return proc::control::CommandDef(internedString (uniqueTypeInstance())) + return proc::control::CommandDef(lib::internedString (uniqueTypeInstance())) .operation(PlaceholderCommand::operate) .captureUndo(PlaceholderCommand::capture) .undoOperation(PlaceholderCommand::undo); diff --git a/tests/gui/test/test-nexus.cpp b/tests/gui/test/test-nexus.cpp index d4145d64f..2d4a9dfd8 100644 --- a/tests/gui/test/test-nexus.cpp +++ b/tests/gui/test/test-nexus.cpp @@ -89,22 +89,6 @@ using util::_Fmt; namespace gui { namespace test{ - namespace { // quick-n-dirty symbol table implementation - - /** @warning grows eternally, never shrinks */ - std::deque idStringBuffer; ////////////////////////////////TICKET #158 replace by symbol table - } - - Symbol - internedString (string&& idString) - { - idStringBuffer.emplace_back (std::forward (idString)); - return Symbol (idStringBuffer.back().c_str()); - } - ////////////////////////(End)symbol-table hack - - - namespace { // internal details