summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelParts.cpp24
-rw-r--r--slicer/slicer/modelPartsTypes.cpp4
-rw-r--r--slicer/slicer/modelPartsTypes.h10
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h13
-rw-r--r--slicer/tool/parser.cpp14
5 files changed, 46 insertions, 19 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp
index 2c1bd86..6a521cb 100644
--- a/slicer/slicer/modelParts.cpp
+++ b/slicer/slicer/modelParts.cpp
@@ -3,13 +3,29 @@
namespace Slicer {
const Metadata emptyMetadata;
- static ClassNameMap names __attribute__((init_priority(209)));
- static ClassRefMap refs __attribute__((init_priority(209)));
+ 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;
+ return names;
}
const std::string &
@@ -35,7 +51,7 @@ namespace Slicer {
ClassRefMap *
classRefMap()
{
- return &refs;
+ return refs;
}
void
diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp
index 41f8125..bedfd7d 100644
--- a/slicer/slicer/modelPartsTypes.cpp
+++ b/slicer/slicer/modelPartsTypes.cpp
@@ -83,14 +83,14 @@ 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)
+ void ModelPartForComplexBase::registerClass(const std::string & className, const std::string * 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)
+ void ModelPartForComplexBase::unregisterClass(const std::string & className, const std::string * typeName)
{
Slicer::classRefMap()->erase(className);
if (typeName) {
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index a27ad66..71736bf 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -103,8 +103,8 @@ namespace Slicer {
protected:
ModelPartPtr getSubclassModelPart(const std::string & name, void * m);
- static void registerClass(const std::string & className, const TypeId & typeName, const ClassRef &);
- static void unregisterClass(const std::string & className, const TypeId & typeName);
+ static void registerClass(const std::string & className, const std::string * typeName, const ClassRef &);
+ static void unregisterClass(const std::string & className, const std::string * typeName);
static TypeId GetTypeId(const std::string & id, const std::string & className);
};
@@ -187,10 +187,12 @@ namespace Slicer {
virtual IceUtil::Optional<std::string> GetTypeIdProperty() const override;
static const std::string typeIdProperty;
- static const std::string className;
- static const IceUtil::Optional<std::string> typeName;
+ static const std::string * className;
+ static const std::string * typeName;
static ModelPartPtr CreateModelPart(void *);
+ static void initClassName() __attribute__ ((constructor(209)));
+ static void deleteClassName() __attribute__ ((destructor(209)));
static void registerClass() __attribute__ ((constructor(210)));
static void unregisterClass() __attribute__ ((destructor(210)));
};
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index fe38863..f9d8a4f 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -279,22 +279,29 @@ namespace Slicer {
}
template<typename T>
+ void ModelPartForClass<T>::deleteClassName()
+ {
+ delete className;
+ delete typeName;
+ }
+
+ template<typename T>
void ModelPartForClass<T>::registerClass()
{
- ModelPartForComplexBase::registerClass(className, typeName, &ModelPartForClass<T>::CreateModelPart);
+ ModelPartForComplexBase::registerClass(*className, typeName, &ModelPartForClass<T>::CreateModelPart);
}
template<typename T>
void ModelPartForClass<T>::unregisterClass()
{
- ModelPartForComplexBase::unregisterClass(className, typeName);
+ ModelPartForComplexBase::unregisterClass(*className, typeName);
}
template<typename T>
TypeId
ModelPartForClass<T>::GetTypeId() const
{
- return ModelPartForComplexBase::GetTypeId(this->Model->ice_id(), className);
+ return ModelPartForComplexBase::GetTypeId(this->Model->ice_id(), *className);
}
// ModelPartForStruct
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 818cd7e..b24eac6 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -194,19 +194,21 @@ namespace Slicer {
auto typeName = metaDataValue("slicer:typename:", c->getMetaData());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
- fprintbf(cpp, "__attribute__ ((init_priority(209)))\nconst std::string ModelPartForClass< %s >::className(\"%s\");\n",
- decl->typeId(), c->scoped());
+ fprintbf(cpp, "const std::string * ModelPartForClass< %s >::className = nullptr;\n",
+ decl->typeId());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
- fprintbf(cpp, "__attribute__ ((init_priority(209)))\nconst IceUtil::Optional<std::string> ModelPartForClass< %s >::typeName",
+ fprintbf(cpp, "const std::string * ModelPartForClass< %s >::typeName = nullptr;\n",
decl->typeId());
+ fprintbf(cpp, "template<>\nvoid ModelPartForClass< %s >::initClassName() {\n\tclassName = new std::string(\"%s\");\n",
+ decl->typeId(), c->scoped());
if (typeName) {
- fprintbf(cpp, "(\"%s\")",
+ fprintbf(cpp, "\t typeName = new std::string(\"%s\");",
*typeName);
}
else {
- fprintbf(cpp, "(IceUtil::None)");
+ fprintbf(cpp, "\t typeName = nullptr;");
}
- fprintbf(cpp, ";\n\n");
+ fprintbf(cpp, "\n}\n");
fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ",
c->scoped());