diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-21 21:09:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-03-21 21:09:36 +0000 |
commit | 656170e81e3e4065ff078179737f73686c5d2f1b (patch) | |
tree | 1ef2c1e46eb17ddd76034950259ad3098127b017 | |
parent | Remove unnecessary headers (diff) | |
download | slicer-656170e81e3e4065ff078179737f73686c5d2f1b.tar.bz2 slicer-656170e81e3e4065ff078179737f73686c5d2f1b.tar.xz slicer-656170e81e3e4065ff078179737f73686c5d2f1b.zip |
Shuffle some code around to make bimap unrequired in modelParts.h
-rw-r--r-- | slicer/db/sqlInsertSerializer.cpp | 1 | ||||
-rw-r--r-- | slicer/db/sqlTablePatchSerializer.cpp | 1 | ||||
-rw-r--r-- | slicer/db/sqlUpdateSerializer.cpp | 1 | ||||
-rw-r--r-- | slicer/slicer/modelParts.cpp | 51 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 9 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.cpp | 59 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 8 |
7 files changed, 69 insertions, 61 deletions
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 0addf86..e7f702b 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -7,6 +7,7 @@ #include <modifycommand.h> #include <slicer/metadata.h> #include <boost/numeric/conversion/cast.hpp> +#include <boost/bind.hpp> namespace Slicer { SqlInsertSerializer::SqlInsertSerializer(DB::Connection * const c, const std::string & t) : diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp index 50505cb..da4b7f4 100644 --- a/slicer/db/sqlTablePatchSerializer.cpp +++ b/slicer/db/sqlTablePatchSerializer.cpp @@ -4,6 +4,7 @@ #include <slicer/metadata.h> #include <compileTimeFormatter.h> #include <scopeExit.h> +#include <boost/bind.hpp> namespace Slicer { AdHocFormatter(ttname, "slicer_tmp_%?"); diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 613a87a..0c20b12 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -6,6 +6,7 @@ #include <buffer.h> #include <modifycommand.h> #include <slicer/metadata.h> +#include <boost/bind.hpp> namespace Slicer { SqlUpdateSerializer::SqlUpdateSerializer(DB::Connection * const c, const std::string & t) : diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index dbefdcd..68b2597 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -3,57 +3,6 @@ namespace Slicer { const Metadata emptyMetadata; - static void createClassMaps() __attribute__((constructor(208))); - static void deleteClassMaps() __attribute__((destructor(208))); - static ClassNameMap * names; - static ClassRefMap * refs; - - void createClassMaps() - { - names = new ClassNameMap(); - refs = new ClassRefMap(); - } - - static void deleteClassMaps() - { - delete names; - delete refs; - names = nullptr; - refs = nullptr; - } - - ClassNameMap * - classNameMap() - { - return names; - } - - const std::string & - ModelPart::ToModelTypeName(const std::string & name) - { - auto mapped = classNameMap()->right.find(name); - if (mapped != classNameMap()->right.end()) { - return mapped->second; - } - return name; - } - - const std::string & - ModelPart::ToExchangeTypeName(const std::string & name) - { - auto mapped = classNameMap()->left.find(name); - if (mapped != classNameMap()->left.end()) { - return mapped->second; - } - return name; - } - - ClassRefMap * - classRefMap() - { - return refs; - } - void ModelPart::Create() { diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 15fdc30..36d8d48 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -8,8 +8,8 @@ #include <Ice/StreamF.h> #include <stdexcept> #include <boost/function.hpp> -#include <boost/bimap.hpp> #include <vector> +#include <list> #include <visibility.h> namespace Slicer { @@ -84,10 +84,6 @@ namespace Slicer { typedef boost::function<ModelPartPtr(void *)> ClassRef; typedef boost::function<bool(const HookCommon *)> HookFilter; - typedef std::map<std::string, ClassRef> ClassRefMap; - DLL_PUBLIC ClassRefMap * classRefMap(); - typedef boost::bimap<std::string, std::string> ClassNameMap; - DLL_PUBLIC ClassNameMap * classNameMap(); typedef std::list<std::string> Metadata; DLL_PUBLIC extern const Metadata emptyMetadata; @@ -160,9 +156,6 @@ namespace Slicer { virtual const Metadata & GetMetadata() const; virtual bool IsOptional() const; virtual ModelPartPtr GetContainedModelPart(); - - static const std::string & ToExchangeTypeName(const std::string &); - static const std::string & ToModelTypeName(const std::string &); }; template<typename T> diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index a1575e2..4dae657 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -1,8 +1,63 @@ #include "modelPartsTypes.impl.h" #include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/predicate.hpp> +#include <boost/bimap.hpp> namespace Slicer { + typedef std::map<std::string, ClassRef> ClassRefMap; + typedef boost::bimap<std::string, std::string> ClassNameMap; + + static void createClassMaps() __attribute__((constructor(208))); + static void deleteClassMaps() __attribute__((destructor(208))); + static ClassNameMap * names; + static ClassRefMap * refs; + + void createClassMaps() + { + names = new ClassNameMap(); + refs = new ClassRefMap(); + } + + static void deleteClassMaps() + { + delete names; + delete refs; + names = nullptr; + refs = nullptr; + } + + ClassNameMap * + classNameMap() + { + return names; + } + + ClassRefMap * + classRefMap() + { + return refs; + } + + const std::string & + ModelPartForComplexBase::ToModelTypeName(const std::string & name) + { + auto mapped = classNameMap()->right.find(name); + if (mapped != classNameMap()->right.end()) { + return mapped->second; + } + return name; + } + + const std::string & + ModelPartForComplexBase::ToExchangeTypeName(const std::string & name) + { + auto mapped = classNameMap()->left.find(name); + if (mapped != classNameMap()->left.end()) { + return mapped->second; + } + return name; + } + MODELPARTFOR(std::string, ModelPartForSimple); MODELPARTFOR(bool, ModelPartForSimple); MODELPARTFOR(Ice::Float, ModelPartForSimple); @@ -113,7 +168,7 @@ namespace Slicer { } ModelPartPtr ModelPartForComplexBase::getSubclassModelPart(const std::string & name, void * m) { - auto ref = classRefMap()->find(ModelPart::ToModelTypeName(name)); + auto ref = classRefMap()->find(ToModelTypeName(name)); if (ref == classRefMap()->end()) { throw UnknownType(name); } @@ -121,7 +176,7 @@ namespace Slicer { } TypeId ModelPartForComplexBase::GetTypeId(const std::string & id, const std::string & className) { - return (id == className) ? TypeId() : ModelPart::ToExchangeTypeName(id); + return (id == className) ? TypeId() : ToExchangeTypeName(id); } std::string ModelPartForComplexBase::demangle(const char * mangled) diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 327f1c6..d50224d 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -3,9 +3,12 @@ #include "modelParts.h" #include <Ice/ObjectF.h> +#include <boost/multi_index_container_fwd.hpp> #include <boost/multi_index/sequenced_index_fwd.hpp> #include <boost/multi_index/ordered_index_fwd.hpp> #include <boost/multi_index/global_fun.hpp> +#include <boost/multi_index/member.hpp> +#include <boost/bimap.hpp> namespace Slicer { template<typename T> @@ -136,6 +139,9 @@ namespace Slicer { 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 &); }; template<typename T> @@ -227,6 +233,8 @@ namespace Slicer { static const std::string * typeName; static ModelPartPtr CreateModelPart(void *); + + private: static void initClassName(); static void deleteClassName(); static void registerClass() __attribute__ ((constructor(210))); |