From 3b3ca65562375b3cfdf8919acae8c3259df05c91 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 25 Nov 2011 15:17:54 +0200 Subject: Add names to NodeMetadata --- src/nodemetadata.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src/nodemetadata.cpp') diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index ef6ea1cd2..2f47aba22 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ core::map NodeMetadata::m_types; +core::map NodeMetadata::m_names; NodeMetadata::NodeMetadata(IGameDef *gamedef): m_gamedef(gamedef) @@ -41,6 +42,36 @@ NodeMetadata::~NodeMetadata() { } +NodeMetadata* NodeMetadata::create(const std::string &name, IGameDef *gamedef) +{ + // Find factory function + core::map::Node *n; + n = m_names.find(name); + if(n == NULL) + { + // If factory is not found, just return. + errorstream<<"WARNING: NodeMetadata: No factory for name=\"" + <getValue(); + NodeMetadata *meta = (*f)(iss, gamedef); + return meta; + } + catch(SerializationError &e) + { + errorstream<<"NodeMetadata: SerializationError " + <<"while creating name=\""<::Node *n; - n = m_types.find(id); - if(n) - return; - m_types.insert(id, f); + { // typeId + core::map::Node *n; + n = m_types.find(id); + if(!n) + m_types.insert(id, f); + } + { // typeName + core::map::Node *n; + n = m_names.find(name); + if(!n) + m_names.insert(name, f); + } } /* -- cgit v1.2.3