#include <Standard_Type.hxx>
-#include <Standard_Mutex.hxx>
+
#include <Standard_Assert.hxx>
+#include <Standard_CStringHasher.hxx>
+#include <Standard_Mutex.hxx>
#include <unordered_map>
//============================================================================
+namespace
+{
+ static Standard_CString copy_string (const char* theString)
+ {
+ size_t aLength = strlen (theString);
+ char* aResult = static_cast<char*> (Standard::Allocate (aLength + 1));
+ strncpy (aResult, theString, aLength + 1); //including null-character
+ return aResult;
+ }
+}
+
Standard_Type::Standard_Type (const std::type_info& theInfo,
const char* theName,
Standard_Size theSize,
const Handle(Standard_Type)& theParent) :
myInfo(theInfo),
- myName(theName),
+ myName(copy_string (theName)),
mySize(theSize),
myParent(theParent)
{
namespace {
// Map of string to type
- typedef std::unordered_map<std::type_index, Standard_Type*> registry_type;
+ typedef std::unordered_map<Standard_CString, Standard_Type*, Standard_CStringHasher, Standard_CStringHasher> registry_type;
// Registry is made static in the function to ensure that it gets
// initialized by the time of first access
// return existing descriptor if already in the registry
registry_type& aRegistry = GetRegistry();
Standard_Type* aType = 0;
- auto anIter = aRegistry.find(theInfo);
+ auto anIter = aRegistry.find(theName);
if (anIter != aRegistry.end())
return anIter->second;
aType = new Standard_Type (theInfo, theName, theSize, theParent);
// then add it to registry and return (the reference to the handle stored in the registry)
- aRegistry.emplace(theInfo, aType);
+ aRegistry.emplace(theName, aType);
return aType;
}
{
// remove descriptor from the registry
registry_type& aRegistry = GetRegistry();
- Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry",);
+ Standard_ASSERT(aRegistry.erase(myName) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry",);
+ Standard::Free (myName);
}