2 * \file scene_class_registry.cpp
3 * \brief CSceneClassRegistry
4 * \date 2012-08-20 09:57GMT
5 * \author Jan Boon (Kaetemi)
10 * Copyright (C) 2012 by authors
12 * This file is part of RYZOM CORE PIPELINE.
13 * RYZOM CORE PIPELINE is free software: you can redistribute it
14 * and/or modify it under the terms of the GNU Affero General Public
15 * License as published by the Free Software Foundation, either
16 * version 3 of the License, or (at your option) any later version.
18 * RYZOM CORE PIPELINE is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Affero General Public License for more details.
23 * You should have received a copy of the GNU Affero General Public
24 * License along with RYZOM CORE PIPELINE. If not, see
25 * <http://www.gnu.org/licenses/>.
28 #include <nel/misc/types_nl.h>
29 #include "scene_class_registry.h"
35 // #include <nel/misc/debug.h>
40 // using namespace NLMISC;
45 ////////////////////////////////////////////////////////////////////////
46 ////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////
49 // Elevate warnings to errors in this file for stricter reading
51 #define nlwarning nlerror
53 // Elevate debug to error in this file for debugging
55 // #define nldebug nlerror
57 ////////////////////////////////////////////////////////////////////////
58 ////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////
61 CSceneClassRegistry::CSceneClassRegistry()
66 CSceneClassRegistry::~CSceneClassRegistry()
71 void CSceneClassRegistry::add(const ISceneClassDesc
*desc
)
73 TKey
key(desc
->superClassId(), desc
->classId());
74 if (m_ClassDescriptions
.find(key
) != m_ClassDescriptions
.end()) { nlerror("Already added this class to the registry"); return; }
75 m_ClassDescriptions
[key
] = desc
;
78 void CSceneClassRegistry::remove(const TSClassId superClassId
, const NLMISC::CClassId classId
)
80 TKey
key(superClassId
, classId
);
81 if (m_ClassDescriptions
.find(key
) == m_ClassDescriptions
.end()) { nlwarning("Try to remove class that is not found"); return; }
82 m_ClassDescriptions
.erase(key
);
85 /// Add a superclass to the registry
86 void CSceneClassRegistry::add(const ISuperClassDesc
*desc
)
88 // nldebug("Register superclass 0x%x", desc->superClassId());
89 if (m_SuperClassDescriptions
.find(desc
->superClassId()) != m_SuperClassDescriptions
.end()) { nlerror("Already added this superclass to the registry"); return; }
90 m_SuperClassDescriptions
[desc
->superClassId()] = desc
;
93 /// Remove a superclass from the registry
94 void CSceneClassRegistry::remove(const TSClassId superClassId
)
96 if (m_SuperClassDescriptions
.find(superClassId
) == m_SuperClassDescriptions
.end()) { nlwarning("Try to remove superclass that is not found"); return; }
97 m_SuperClassDescriptions
.erase(superClassId
);
100 /// Create a class by class id
101 CSceneClass
*CSceneClassRegistry::create(CScene
*scene
, const TSClassId superClassId
, const NLMISC::CClassId classId
) const
103 TKey
key(superClassId
, classId
);
104 if (m_ClassDescriptions
.find(key
) == m_ClassDescriptions
.end()) { /* nldebug("Try to create class that does not exist"); */ return NULL
; }
105 return m_ClassDescriptions
.find(key
)->second
->create(scene
);
108 /// Create an unknown class by superclass id
109 CSceneClass
*CSceneClassRegistry::createUnknown(CScene
*scene
, TSClassId superClassId
, const NLMISC::CClassId classId
, const ucstring
&displayName
, const ucstring
&dllFilename
, const ucstring
&dllDescription
) const
111 if (m_SuperClassDescriptions
.find(superClassId
) == m_SuperClassDescriptions
.end()) { nlwarning("Creating superclass 0x%x (%s) %s that does not exist", superClassId
, displayName
.toUtf8().c_str(), classId
.toString().c_str()); return NULL
; }
112 return m_SuperClassDescriptions
.find(superClassId
)->second
->createUnknown(scene
, classId
, displayName
, dllFilename
, dllDescription
);
115 /// Destroy a class by pointer
116 void CSceneClassRegistry::destroy(CSceneClass
*sceneClass
) const
118 sceneClass
->classDesc()->destroy(sceneClass
);
121 /// Return the description of a class by class id
122 const ISceneClassDesc
*CSceneClassRegistry::describe(const TSClassId superClassId
, const NLMISC::CClassId classId
) const
124 TKey
key(superClassId
, classId
);
125 if (m_ClassDescriptions
.find(key
) == m_ClassDescriptions
.end()) { nldebug("Try to describe class that does not exist"); return NULL
; }
126 return m_ClassDescriptions
.find(key
)->second
;
129 ////////////////////////////////////////////////////////////////////////
130 ////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////
133 CSceneClassRegistry::TKey::TKey(TSClassId superClassId
, NLMISC::CClassId classId
) : SuperClassId(superClassId
), ClassId(classId
)
138 bool CSceneClassRegistry::TKey::operator<(const CSceneClassRegistry::TKey
&right
) const
140 if (SuperClassId
< right
.SuperClassId
)
142 if (SuperClassId
> right
.SuperClassId
)
144 if (ClassId
< right
.ClassId
)
146 if (ClassId
> right
.ClassId
)
151 bool CSceneClassRegistry::TKey::operator>(const CSceneClassRegistry::TKey
&right
) const
153 if (SuperClassId
> right
.SuperClassId
)
155 if (SuperClassId
< right
.SuperClassId
)
157 if (ClassId
> right
.ClassId
)
159 if (ClassId
< right
.ClassId
)
164 bool CSceneClassRegistry::TKey::operator==(const CSceneClassRegistry::TKey
&right
) const
166 return ClassId
== right
.ClassId
&& SuperClassId
== right
.SuperClassId
;
169 ////////////////////////////////////////////////////////////////////////
170 ////////////////////////////////////////////////////////////////////////
171 ////////////////////////////////////////////////////////////////////////
173 } /* namespace MAX */
174 } /* namespace PIPELINE */