diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-05-22 19:27:32 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-07-22 13:15:30 +0100 |
commit | 2cb7daf66d328e5d1de515ddceeaa20bf37a52e6 (patch) | |
tree | ce5b55df5411704723bd2a8faf4eba0f672013da | |
parent | Don't build ICE stuff as a static library (diff) | |
download | slicer-2cb7daf66d328e5d1de515ddceeaa20bf37a52e6.tar.bz2 slicer-2cb7daf66d328e5d1de515ddceeaa20bf37a52e6.tar.xz slicer-2cb7daf66d328e5d1de515ddceeaa20bf37a52e6.zip |
Multi-index
Use Boost multi-index instead of bimap to gain access to custom
compators, specific the transparent ones, so we can expose a string_view
interface to them.
-rw-r--r-- | slicer/slicer/modelParts.cpp | 7 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 4 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.cpp | 28 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 1 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 26 |
5 files changed, 42 insertions, 24 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 3736156..702bc93 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -1,5 +1,6 @@ #include "modelParts.h" #include <boost/lexical_cast.hpp> +#include <boost/algorithm/string/predicate.hpp> namespace Slicer { const Metadata emptyMetadata; @@ -90,5 +91,11 @@ namespace Slicer { { ch(this->name, modelPart, this); } + + bool + case_less::operator()(std::string_view && a, std::string_view && b) const + { + return boost::ilexicographical_compare(a, b); + } } diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 7f5cd6a..6e13fc9 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -118,6 +118,10 @@ namespace Slicer { const std::string name; }; + struct DLL_PUBLIC case_less { + bool operator()(std::string_view && lhs, std::string_view && rhs) const; + }; + class DLL_PUBLIC ModelPart : public std::enable_shared_from_this<ModelPart> { public: virtual ~ModelPart() = default; diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index bca297f..58e8caf 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -4,8 +4,13 @@ #include <cxxabi.h> namespace Slicer { - typedef std::map<std::string, ClassRef> ClassRefMap; - typedef boost::bimap<std::string, std::string> ClassNameMap; + typedef std::map<std::string, ClassRef, std::less<>> ClassRefMap; + typedef boost::multi_index_container< + std::pair<std::string, std::string>, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<std::string, std::string>, const std::string, &std::pair<std::string, std::string>::first>, std::less<>>, + boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<std::string, std::string>, const std::string, &std::pair<std::string, std::string>::second>, std::less<>> + >> ClassNameMap; static void createClassMaps() __attribute__((constructor(208))); static void deleteClassMaps() __attribute__((destructor(208))); @@ -41,9 +46,10 @@ namespace Slicer { const std::string & ModelPartForComplexBase::ToModelTypeName(const std::string & name) { - auto mapped = classNameMap()->right.find(name); - if (mapped != classNameMap()->right.end()) { - return mapped->second; + auto & right = classNameMap()->get<1>(); + auto mapped = right.find(name); + if (mapped != right.end()) { + return mapped->first; } return name; } @@ -51,8 +57,9 @@ namespace Slicer { const std::string & ModelPartForComplexBase::ToExchangeTypeName(const std::string & name) { - auto mapped = classNameMap()->left.find(name); - if (mapped != classNameMap()->left.end()) { + auto & left = classNameMap()->get<0>(); + auto mapped = left.find(name); + if (mapped != left.end()) { return mapped->second; } return name; @@ -163,7 +170,7 @@ namespace Slicer { { Slicer::classRefMap()->erase(className); if (typeName) { - Slicer::classNameMap()->left.erase(className); + classNameMap()->get<0>().erase(className); } } ModelPartPtr ModelPartForComplexBase::getSubclassModelPart(const std::string & name, void * m) @@ -185,11 +192,6 @@ namespace Slicer { return "::" + std::string(buf.get()); } - std::string ModelPartForComplexBase::hookNameLower(const HookCommon & h) - { - return boost::algorithm::to_lower_copy(h.name); - } - void ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch) { if (this->hasModel()) { diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index ee5a083..e105f08 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -131,7 +131,6 @@ namespace Slicer { static void unregisterClass(const std::string & className, const std::string * typeName); static TypeId GetTypeId(const std::string & id, const std::string & className); static std::string demangle(const char * mangled); - static std::string hookNameLower(const HookCommon &); static const std::string & ToExchangeTypeName(const std::string &); static const std::string & ToModelTypeName(const std::string &); diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index f8e2ba6..79e8645 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -11,7 +11,6 @@ #include <boost/multi_index/global_fun.hpp> #include <boost/multi_index/member.hpp> #include <boost/algorithm/string/case_conv.hpp> -#include <boost/bimap.hpp> #define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \ template<> ModelPartPtr ModelPart::CreateFor<Type>() { return std::make_shared<ModelPartType>(nullptr); } \ @@ -323,8 +322,8 @@ namespace Slicer { HookPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, - boost::multi_index::ordered_non_unique<boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>>, - boost::multi_index::ordered_non_unique<boost::multi_index::global_fun<const HookCommon &, std::string, &ModelPartForComplexBase::hookNameLower>>>> { + boost::multi_index::ordered_non_unique<boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, std::less<>>, + boost::multi_index::ordered_non_unique<boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, case_less>>> { }; template<typename T> @@ -543,7 +542,12 @@ namespace Slicer { // ModelPartForEnum template<typename T> - class ModelPartForEnum<T>::Enumerations : public boost::bimap<T, std::string> { + class ModelPartForEnum<T>::Enumerations : public boost::multi_index_container< + std::pair<T, std::string>, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<T, std::string>, const T, &std::pair<T, std::string>::first>>, + boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<T, std::string>, const std::string, &std::pair<T, std::string>::second>, std::less<>> + >> { }; template<typename T> @@ -561,18 +565,20 @@ namespace Slicer { template<typename T> T ModelPartForEnum<T>::lookup(const std::string & val) { - auto i = enumerations.right.find(val); - if (i == enumerations.right.end()) { - throw InvalidEnumerationSymbol(val, typeid(T).name()); + auto & right = enumerations.template get<1>(); + auto i = right.find(val); + if (i == right.end()) { + throw InvalidEnumerationSymbol(std::string(val), typeid(T).name()); } - return i->second; + return i->first; } template<typename T> const std::string & ModelPartForEnum<T>::lookup(T val) { - auto i = enumerations.left.find(val); - if (i == enumerations.left.end()) { + auto & left = enumerations.template get<0>(); + auto i = left.find(val); + if (i == left.end()) { throw InvalidEnumerationValue((::Ice::Int)val, typeid(T).name()); } return i->second; |