Added: #1440 Functionality for ClassDirectory3

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 6fc37e7338
commit 847ca01fb6

@ -68,6 +68,7 @@ CClassDirectory3::~CClassDirectory3()
}
m_ChunkCache.clear();
m_Entries.clear();
m_ClassIdToIndex.clear();
}
std::string CClassDirectory3::getClassName()
@ -140,6 +141,7 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level)
switch (id)
{
case 0x2040: // ClassEntry
{
if (parsedDllEntry && (lastCached != id))
throw EStorageParse(); // There were chunks inbetween
if (!parsedDllEntry)
@ -148,8 +150,11 @@ void CClassDirectory3::parse(uint16 version, TParseLevel level)
lastCached = id;
parsedDllEntry = true;
}
m_Entries.push_back(static_cast<CClassEntry *>(it->second));
CClassEntry *classEntry = static_cast<CClassEntry *>(it->second);
m_ClassIdToIndex[classEntry->classId()] = m_Entries.size();
m_Entries.push_back(classEntry);
break;
}
default:
m_ChunkCache.push_back(*it); // Dummy entry to know the location
lastCached = id;
@ -222,15 +227,45 @@ void CClassDirectory3::disown()
CStorageContainer::disown();
m_ChunkCache.clear();
m_Entries.clear();
m_ClassIdToIndex.clear();
// Ownership goes back to Chunks
ChunksOwnsPointers = true;
}
// Parallel to CDllDirectory
const CClassEntry *CClassDirectory3::get(std::vector<CClassEntry *>::size_type idx) const
const CClassEntry *CClassDirectory3::get(uint16 index) const
{
return m_Entries[idx];
nlassert(!ChunksOwnsPointers);
return m_Entries[index];
}
void CClassDirectory3::reset()
{
nlassert(!ChunksOwnsPointers);
for (std::vector<CClassEntry *>::iterator subit = m_Entries.begin(), subend = m_Entries.end(); subit != subend; ++subit)
{
delete (*subit);
}
m_Entries.clear();
m_ClassIdToIndex.clear();
}
uint16 CClassDirectory3::getOrCreateIndex(const ISceneClassDesc *sceneClassDesc)
{
nlassert(!ChunksOwnsPointers);
std::map<NLMISC::CClassId, uint16>::iterator it = m_ClassIdToIndex.find(sceneClassDesc->classId());
// Return existing index
if (it != m_ClassIdToIndex.end())
return it->second;
// Create new entry
CClassEntry *classEntry = new CClassEntry(sceneClassDesc);
uint16 index = m_Entries.size();
m_ClassIdToIndex[classEntry->classId()] = index;
m_Entries.push_back(classEntry);
return index;
}
IStorageObject *CClassDirectory3::createChunkById(uint16 id, bool container)
@ -261,6 +296,16 @@ CClassEntry::CClassEntry() : m_Header(NULL), m_Name(NULL)
}
CClassEntry::CClassEntry(const ISceneClassDesc *sceneClassDesc) : m_Header(new CClassEntryHeader()), m_Name(new CStorageValue<ucstring>())
{
Chunks.push_back(TStorageObjectWithId(0x2060, m_Header));
Chunks.push_back(TStorageObjectWithId(0x2042, m_Name));
m_Header->DllIndex = -9; // Invalid temporary value
m_Header->ClassId = sceneClassDesc->classId();
m_Header->SuperClassId = sceneClassDesc->superClassId();
m_Name->Value = sceneClassDesc->displayName();
}
CClassEntry::~CClassEntry()
{
@ -359,16 +404,16 @@ std::string CClassEntryHeader::getClassName()
void CClassEntryHeader::serial(NLMISC::IStream &stream)
{
stream.serial(DllIndex);
stream.serial(ClassID);
stream.serial(SuperClassID);
stream.serial(ClassId);
stream.serial(SuperClassId);
}
void CClassEntryHeader::toString(std::ostream &ostream, const std::string &pad)
{
ostream << "(" << getClassName() << ") { ";
ostream << "\n" << pad << "DllIndex: " << DllIndex;
ostream << "\n" << pad << "ClassID: " << NLMISC::toString(ClassID);
ostream << "\n" << pad << "SuperClassID: " << SuperClassID;
ostream << "\n" << pad << "ClassId: " << NLMISC::toString(ClassId);
ostream << "\n" << pad << "SuperClassId: " << SuperClassId;
ostream << " } ";
}

@ -38,6 +38,7 @@
// Project includes
#include "storage_object.h"
#include "storage_value.h"
#include "scene_class.h"
namespace PIPELINE {
namespace MAX {
@ -65,7 +66,12 @@ public:
virtual void disown();
// public
const CClassEntry *get(std::vector<CClassEntry *>::size_type idx) const;
// Get a class entry corresponding to a chunk index, pointers become invalid after reset
const CClassEntry *get(uint16 index) const;
// Reset the class directory, all class entry pointers become invalid, use class id and scene class registry
void reset();
// Get or create the chunk index for a class by class description
uint16 getOrCreateIndex(const ISceneClassDesc *sceneClassDesc);
protected:
virtual IStorageObject *createChunkById(uint16 id, bool container);
@ -73,6 +79,7 @@ protected:
private:
TStorageObjectContainer m_ChunkCache;
std::vector<CClassEntry *> m_Entries;
std::map<NLMISC::CClassId, uint16> m_ClassIdToIndex;
}; /* class CClassDirectory3 */
@ -90,8 +97,8 @@ public:
// public data
sint32 DllIndex;
NLMISC::CClassId ClassID;
uint32 SuperClassID;
NLMISC::CClassId ClassId;
uint32 SuperClassId;
// inherited
virtual std::string getClassName();
@ -110,6 +117,7 @@ class CClassEntry : public CStorageContainer
{
public:
CClassEntry();
CClassEntry(const ISceneClassDesc *sceneClassDesc);
virtual ~CClassEntry();
// inherited
@ -122,8 +130,8 @@ public:
const ucstring &displayName() const { return m_Name->Value; }
sint32 dllIndex() const { return m_Header->DllIndex; }
NLMISC::CClassId cslassId() const { return m_Header->ClassID; }
uint32 superClassId() const { return m_Header->SuperClassID; }
NLMISC::CClassId classId() const { return m_Header->ClassId; }
uint32 superClassId() const { return m_Header->SuperClassId; }
protected:
virtual IStorageObject *createChunkById(uint16 id, bool container);

@ -224,9 +224,9 @@ void CDllDirectory::disown()
}
// Parallel to CClassDirectory3
const CDllEntry *CDllDirectory::get(std::vector<CDllEntry *>::size_type idx) const
const CDllEntry *CDllDirectory::get(uint16 index) const
{
return m_Entries[idx];
return m_Entries[index];
}
IStorageObject *CDllDirectory::createChunkById(uint16 id, bool container)

@ -63,7 +63,7 @@ public:
virtual void disown();
// public
const CDllEntry *get(std::vector<CDllEntry *>::size_type idx) const;
const CDllEntry *get(uint16 index) const;
protected:
virtual IStorageObject *createChunkById(uint16 id, bool container);

@ -155,69 +155,6 @@ IStorageObject *CSceneClassContainer::createChunkById(uint16 id, bool container)
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CSceneClass::CSceneClass()
{
}
CSceneClass::~CSceneClass()
{
}
std::string CSceneClass::getClassName()
{
return getClassDesc()->getInternalName();
}
void CSceneClass::toString(std::ostream &ostream, const std::string &pad)
{
CStorageContainer::toString(ostream, pad);
}
void CSceneClass::parse(uint16 version, TParseLevel level)
{
CStorageContainer::parse(version, level);
}
void CSceneClass::clean()
{
CStorageContainer::clean();
}
void CSceneClass::build(uint16 version)
{
CStorageContainer::build(version);
}
void CSceneClass::disown()
{
CStorageContainer::disown();
}
IStorageObject *CSceneClass::createChunkById(uint16 id, bool container)
{
return CStorageContainer::createChunkById(id, container);
}
const ucchar *CSceneClass::DisplayName = ucstring("Unknown Scene Class").c_str();
const char *CSceneClass::InternalName = "SceneClass";
const NLMISC::CClassId CSceneClass::ClassId = NLMISC::CClassId::Null;
const TSClassId CSceneClass::SuperClassId = 0x0000;
namespace {
static const CSceneClassDesc<CSceneClass> SceneClassDesc;
} /* anonymous namespace */
const ISceneClassDesc *CSceneClass::getClassDesc()
{
return static_cast<const ISceneClassDesc *>(&SceneClassDesc);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
} /* namespace MAX */
} /* namespace PIPELINE */

@ -37,13 +37,11 @@
// Project includes
#include "storage_object.h"
#include "storage_value.h"
#include "scene_class.h"
namespace PIPELINE {
namespace MAX {
// Don't really care about superclass IDs right now, but we have to.
typedef uint32 TSClassId;
/**
* \brief CScene
* \date 2012-08-19 19:25GMT
@ -94,97 +92,6 @@ protected:
}; /* class CSceneClassContainer */
class ISceneClassDesc;
/**
* \brief CSceneClass
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClass
*/
class CSceneClass : public CStorageContainer
{
public:
CSceneClass();
virtual ~CSceneClass();
// inherited
virtual std::string getClassName();
virtual void toString(std::ostream &ostream, const std::string &pad = "");
virtual void parse(uint16 version, TParseLevel level);
virtual void clean();
virtual void build(uint16 version);
virtual void disown();
// static const
static const ucchar *DisplayName;
static const char *InternalName;
static const NLMISC::CClassId ClassId;
static const TSClassId SuperClassId;
// virtual
virtual const ISceneClassDesc *getClassDesc();
protected:
virtual IStorageObject *createChunkById(uint16 id, bool container);
}; /* class CSceneClass */
/**
* \brief ISceneClassDesc
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* ISceneClassDesc
*/
class ISceneClassDesc
{
public:
virtual CSceneClass *create() const = 0;
virtual void destroy(CSceneClass *sc) const = 0;
virtual const ucchar *getDisplayName() const = 0;
virtual const char *getInternalName() const = 0;
virtual NLMISC::CClassId getClassId() const = 0;
virtual TSClassId getSuperClassId() const = 0;
}; /* class ISceneClassDesc */
/**
* \brief CSceneClassDesc
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClassDesc
* Use in a cpp when registering the CClassId.
*/
template <typename T>
class CSceneClassDesc : public ISceneClassDesc
{
public:
virtual CSceneClass *create() const { return static_cast<CSceneClass *>(new T()); }
virtual void destroy(CSceneClass *sc) const { delete static_cast<T *>(sc); }
virtual const ucchar *getDisplayName() const { return T::DisplayName; }
virtual const char *getInternalName() const { return T::InternalName; }
virtual NLMISC::CClassId getClassId() const { return T::ClassId; }
virtual TSClassId getSuperClassId() const { return T::SuperClassId; }
}; /* class CSceneClassDesc */
/**
* \brief CSceneClassRegistry
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClassRegistry
*/
class CSceneClassRegistry
{
public:
void add(const NLMISC::CClassId, const ISceneClassDesc *desc);
void remove(const NLMISC::CClassId);
CSceneClass *create(const NLMISC::CClassId classid) const;
void destroy(CSceneClass *sceneClass) const;
const ISceneClassDesc *describe(const NLMISC::CClassId classid) const;
}; /* class ISceneClassConstructor */
} /* namespace MAX */
} /* namespace PIPELINE */

@ -0,0 +1,114 @@
/**
* \file scene_class.cpp
* \brief CSceneClass
* \date 2012-08-20 09:07GMT
* \author Jan Boon (Kaetemi)
* CSceneClass
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE PIPELINE.
* RYZOM CORE PIPELINE is free software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* RYZOM CORE PIPELINE is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE PIPELINE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <nel/misc/types_nl.h>
#include "scene_class.h"
// STL includes
// NeL includes
// #include <nel/misc/debug.h>
// Project includes
using namespace std;
// using namespace NLMISC;
namespace PIPELINE {
namespace MAX {
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CSceneClass::CSceneClass()
{
}
CSceneClass::~CSceneClass()
{
}
std::string CSceneClass::getClassName()
{
return getClassDesc()->internalName();
}
void CSceneClass::toString(std::ostream &ostream, const std::string &pad)
{
CStorageContainer::toString(ostream, pad);
}
void CSceneClass::parse(uint16 version, TParseLevel level)
{
CStorageContainer::parse(version, level);
}
void CSceneClass::clean()
{
CStorageContainer::clean();
}
void CSceneClass::build(uint16 version)
{
CStorageContainer::build(version);
}
void CSceneClass::disown()
{
CStorageContainer::disown();
}
IStorageObject *CSceneClass::createChunkById(uint16 id, bool container)
{
return CStorageContainer::createChunkById(id, container);
}
const ucchar *CSceneClass::DisplayName = ucstring("Scene Class").c_str();
const char *CSceneClass::InternalName = "SceneClass";
const NLMISC::CClassId CSceneClass::ClassId = NLMISC::CClassId::Null;
const TSClassId CSceneClass::SuperClassId = 0x0000;
namespace {
static const CSceneClassDesc<CSceneClass> SceneClassDesc;
} /* anonymous namespace */
const ISceneClassDesc *CSceneClass::getClassDesc()
{
return static_cast<const ISceneClassDesc *>(&SceneClassDesc);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
} /* namespace MAX */
} /* namespace PIPELINE */
/* end of file */

@ -0,0 +1,143 @@
/**
* \file scene_class.h
* \brief CSceneClass
* \date 2012-08-20 09:07GMT
* \author Jan Boon (Kaetemi)
* CSceneClass
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE PIPELINE.
* RYZOM CORE PIPELINE is free software: you can redistribute it
* and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* RYZOM CORE PIPELINE is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE PIPELINE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef PIPELINE_SCENE_CLASS_H
#define PIPELINE_SCENE_CLASS_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/misc/class_id.h>
// Project includes
#include "storage_object.h"
#include "storage_value.h"
namespace PIPELINE {
namespace MAX {
// Don't really care about superclass IDs right now, but we have to.
typedef uint32 TSClassId;
class ISceneClassDesc;
/**
* \brief CSceneClass
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClass
*/
class CSceneClass : public CStorageContainer
{
public:
CSceneClass();
virtual ~CSceneClass();
// inherited
virtual std::string getClassName();
virtual void toString(std::ostream &ostream, const std::string &pad = "");
virtual void parse(uint16 version, TParseLevel level);
virtual void clean();
virtual void build(uint16 version);
virtual void disown();
// static const
static const ucchar *DisplayName;
static const char *InternalName;
static const NLMISC::CClassId ClassId;
static const TSClassId SuperClassId;
// virtual
virtual const ISceneClassDesc *getClassDesc();
protected:
virtual IStorageObject *createChunkById(uint16 id, bool container);
}; /* class CSceneClass */
/**
* \brief ISceneClassDesc
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* ISceneClassDesc
*/
class ISceneClassDesc
{
public:
virtual CSceneClass *create() const = 0;
virtual void destroy(CSceneClass *sc) const = 0;
virtual const ucchar *displayName() const = 0;
virtual const char *internalName() const = 0;
virtual NLMISC::CClassId classId() const = 0;
virtual TSClassId superClassId() const = 0;
}; /* class ISceneClassDesc */
/**
* \brief CSceneClassDesc
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClassDesc
* Use in a cpp when registering the CClassId.
*/
template <typename T>
class CSceneClassDesc : public ISceneClassDesc
{
public:
virtual CSceneClass *create() const { return static_cast<CSceneClass *>(new T()); }
virtual void destroy(CSceneClass *sc) const { delete static_cast<T *>(sc); }
virtual const ucchar *displayName() const { return T::DisplayName; }
virtual const char *internalName() const { return T::InternalName; }
virtual NLMISC::CClassId classId() const { return T::ClassId; }
virtual TSClassId superClassId() const { return T::SuperClassId; }
}; /* class CSceneClassDesc */
/**
* \brief CSceneClassRegistry
* \date 2012-08-19 19:25GMT
* \author Jan Boon (Kaetemi)
* CSceneClassRegistry
*/
class CSceneClassRegistry
{
public:
void add(const NLMISC::CClassId, const ISceneClassDesc *desc);
void remove(const NLMISC::CClassId);
CSceneClass *create(const NLMISC::CClassId classid) const;
void destroy(CSceneClass *sceneClass) const;
const ISceneClassDesc *describe(const NLMISC::CClassId classid) const;
}; /* class ISceneClassConstructor */
} /* namespace MAX */
} /* namespace PIPELINE */
#endif /* #ifndef PIPELINE_SCENE_CLASS_H */
/* end of file */
Loading…
Cancel
Save