From 656170e81e3e4065ff078179737f73686c5d2f1b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 21 Mar 2018 21:09:36 +0000 Subject: Shuffle some code around to make bimap unrequired in modelParts.h --- slicer/db/sqlInsertSerializer.cpp | 1 + slicer/db/sqlTablePatchSerializer.cpp | 1 + slicer/db/sqlUpdateSerializer.cpp | 1 + slicer/slicer/modelParts.cpp | 51 ------------------------------ slicer/slicer/modelParts.h | 9 +----- slicer/slicer/modelPartsTypes.cpp | 59 +++++++++++++++++++++++++++++++++-- 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 #include #include +#include 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 #include #include +#include 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 #include #include +#include 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 #include #include -#include #include +#include #include namespace Slicer { @@ -84,10 +84,6 @@ namespace Slicer { typedef boost::function ClassRef; typedef boost::function HookFilter; - typedef std::map ClassRefMap; - DLL_PUBLIC ClassRefMap * classRefMap(); - typedef boost::bimap ClassNameMap; - DLL_PUBLIC ClassNameMap * classNameMap(); typedef std::list 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 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 #include +#include namespace Slicer { + typedef std::map ClassRefMap; + typedef boost::bimap 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 +#include #include #include #include +#include +#include namespace Slicer { template @@ -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 @@ -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))); -- cgit v1.2.3