diff --git a/src/include/symbol.hpp b/src/include/symbol.hpp index 5de94a2cd..00e19571d 100644 --- a/src/include/symbol.hpp +++ b/src/include/symbol.hpp @@ -32,6 +32,7 @@ ** - automatically maintain a symbol table at runtime to support this ** - provide some magic (macros) allowing to build distinct types based on symbols. ** + ** @see symbol-impl.cpp ** @see configrules.hpp ** @see query.hpp */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index f5ff19566..b6f89847b 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -46,6 +46,7 @@ liblumiera_la_SOURCES = \ $(liblumiera_la_srcdir)/test/testoption.cpp \ $(liblumiera_la_srcdir)/test/test-helper.cpp \ $(liblumiera_la_srcdir)/test/suite.cpp \ + $(liblumiera_la_srcdir)/symbol-impl.cpp \ $(liblumiera_la_srcdir)/cmdline.cpp \ $(liblumiera_la_srcdir)/logging.cpp diff --git a/src/lib/safeclib.h b/src/lib/safeclib.h index d949595f8..ed0d73fd3 100644 --- a/src/lib/safeclib.h +++ b/src/lib/safeclib.h @@ -25,7 +25,7 @@ /** * @file - * Portable and safe wrapers around some clib functions and some tools + * Portable and safe wrappers around some clib functions and some tools */ LUMIERA_ERROR_DECLARE(NO_MEMORY); diff --git a/src/lib/symbol-impl.cpp b/src/lib/symbol-impl.cpp new file mode 100644 index 000000000..4b5e9bb35 --- /dev/null +++ b/src/lib/symbol-impl.cpp @@ -0,0 +1,78 @@ +/* + Symbol(impl) - helpers for working with literal string IDs + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +/** @file symbol-impl.hpp + ** Collection of helpers for working with the lumiera::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. + ** + ** lumiera::Symbol + ** control::CommandRegistry for usage example of the hash function. + ** + */ + + + +#include "include/symbol.hpp" +#include "lib/safeclib.h" + +#include +#include + +using std::size_t; +using boost::hash_combine; + + + + +namespace lumiera { + + /** equality on Symbol values is defined + * based on the content, not the address. */ + inline bool + operator== (Symbol sy1, Symbol sy2) + { + return lumiera_strncmp (sy1,sy2, STRING_MAX_RELEVANT); + } + + + /** generating a hash value, e.g. for hashtables. + This function is intended to be picked up by ADL, + and should be usable both with \c std::tr1 and + \c . It is implemented + similar as the boost::hash specialisation for std::string */ + size_t hash_value (Symbol sym) + { + size_t hash=0; + const char *pos = sym; + size_t maxpos = STRING_MAX_RELEVANT; + for ( ; pos && --maxpos; ++pos) + hash_combine(hash, *pos); + + return hash; + } + + + +} // namespace lumiera diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index 560e43b6f..f8c136f12 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -33,6 +33,7 @@ #include #include +// #include /////////TODO which boost include to use here?? #include diff --git a/src/proc/control/command-registry.hpp b/src/proc/control/command-registry.hpp index 975c126c9..4f0abfe56 100644 --- a/src/proc/control/command-registry.hpp +++ b/src/proc/control/command-registry.hpp @@ -77,13 +77,13 @@ namespace control { : public lib::Sync<> , noncopyable { - TypedAllocationManager allocator_; - + // using a hashtable to implement the index typedef std::tr1::unordered_map CmdIndex; typedef std::map ReverseIndex; CmdIndex index_; ReverseIndex ridx_; + TypedAllocationManager allocator_; public: diff --git a/src/proc/control/command.hpp b/src/proc/control/command.hpp index ba45edf44..fe66a53ee 100644 --- a/src/proc/control/command.hpp +++ b/src/proc/control/command.hpp @@ -198,16 +198,16 @@ namespace control { inline bool operator== (Command const& c1, Command const& c2) - { - return (!c1 && !c2) - || ( c1 && c2 && (&c1.impl() == &c2.impl())); - } + { + return (!c1 && !c2) + || ( c1 && c2 && (&c1.impl() == &c2.impl())); + } inline bool operator!= (Command const& c1, Command const& c2) - { - return ! (c1 == c2); - } + { + return ! (c1 == c2); + }