summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelParts.cpp12
-rw-r--r--slicer/slicer/modelParts.h4
-rw-r--r--slicer/slicer/modelPartsTypes.cpp14
-rw-r--r--slicer/slicer/modelPartsTypes.h4
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h10
5 files changed, 28 insertions, 16 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp
index b53997e..9c2c6e9 100644
--- a/slicer/slicer/modelParts.cpp
+++ b/slicer/slicer/modelParts.cpp
@@ -3,12 +3,13 @@
namespace Slicer {
const Metadata emptyMetadata;
+ static ClassNameMap names __attribute__((init_priority(209)));
+ static ClassRefMap refs __attribute__((init_priority(209)));
- ClassNameMap * &
+ ClassNameMap *
classNameMap()
{
- static ClassNameMap * refs = new ClassNameMap();
- return refs;
+ return &names;
}
const std::string &
@@ -31,11 +32,10 @@ namespace Slicer {
return name;
}
- ClassRefMap * &
+ ClassRefMap *
classRefMap()
{
- static ClassRefMap * refs = new ClassRefMap();
- return refs;
+ return &refs;
}
void
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index 59f12c7..c131dc8 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -89,9 +89,9 @@ namespace Slicer {
typedef boost::function<ModelPartPtr(void *)> ClassRef;
typedef boost::function<bool(HookCommonPtr)> HookFilter;
typedef std::map<std::string, ClassRef> ClassRefMap;
- DLL_PUBLIC ClassRefMap * & classRefMap();
+ DLL_PUBLIC ClassRefMap * classRefMap();
typedef boost::bimap<std::string, std::string> ClassNameMap;
- DLL_PUBLIC ClassNameMap * & classNameMap();
+ DLL_PUBLIC ClassNameMap * classNameMap();
typedef std::list<std::string> Metadata;
DLL_PUBLIC extern const Metadata emptyMetadata;
diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp
index 7cf508e..e5744df 100644
--- a/slicer/slicer/modelPartsTypes.cpp
+++ b/slicer/slicer/modelPartsTypes.cpp
@@ -83,6 +83,20 @@ namespace Slicer {
ModelPartType ModelPartForComplexBase::GetType() const { return type; }
const ModelPartType ModelPartForComplexBase::type = mpt_Complex;
+ void ModelPartForComplexBase::registerClass(const std::string & className, const TypeId & typeName, const ClassRef & cr)
+ {
+ Slicer::classRefMap()->insert({ className, cr });
+ if (typeName) {
+ Slicer::classNameMap()->insert({ className, *typeName });
+ }
+ }
+ void ModelPartForComplexBase::unregisterClass(const std::string & className, const TypeId & typeName)
+ {
+ Slicer::classRefMap()->erase(className);
+ if (typeName) {
+ Slicer::classNameMap()->left.erase(className);
+ }
+ }
void ModelPartForEnumBase::OnEachChild(const ChildHandler &) { }
ChildRefPtr ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) { return NULL; }
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index a1230e9..483d8a7 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -90,6 +90,10 @@ namespace Slicer {
public:
virtual ModelPartType GetType() const override;
static const ModelPartType type;
+
+ protected:
+ static void registerClass(const std::string & className, const TypeId & typeName, const ClassRef &);
+ static void unregisterClass(const std::string & className, const TypeId & typeName);
};
template<typename T>
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index d8d86bc..658e95b 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -307,19 +307,13 @@ namespace Slicer {
template<typename T>
void ModelPartForClass<T>::registerClass()
{
- Slicer::classRefMap()->insert({ className, &ModelPartForClass<T>::CreateModelPart });
- if (typeName) {
- Slicer::classNameMap()->insert({ className, *typeName });
- }
+ ModelPartForComplexBase::registerClass(className, typeName, &ModelPartForClass<T>::CreateModelPart);
}
template<typename T>
void ModelPartForClass<T>::unregisterClass()
{
- Slicer::classRefMap()->erase(className);
- if (typeName) {
- Slicer::classNameMap()->left.erase(className);
- }
+ ModelPartForComplexBase::unregisterClass(className, typeName);
}
template<typename T>