1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Fix line endings and tabs

This commit is contained in:
Branan Purvine-Riley
2011-04-11 16:27:55 -07:00
parent d4250e19b5
commit 908aaeb6f6
2738 changed files with 702562 additions and 702562 deletions

View File

@ -1,285 +1,285 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plCreatable_inc
#define plCreatable_inc
#include "hsRefCnt.h"
#include "plFactory.h"
class plCreator;
class hsStream;
class hsResMgr;
class plCreatable : public hsRefCnt
{
public:
virtual const char* ClassName() const = 0;
virtual plCreatable* GetInterface(UInt16 hClass) { return nil; }
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { return nil; }
static hsBool HasBaseClass(UInt16 hBase) { return false; }
virtual UInt16 ClassIndex() const = 0;
virtual void Read(hsStream* s, hsResMgr* mgr) {}
virtual void Write(hsStream* s, hsResMgr* mgr) {}
// WriteVersion writes the current version of this creatable and ReadVersion will read in
// any previous version.
virtual void ReadVersion(hsStream* s, hsResMgr* mgr) { hsAssert(0, "ReadVersion not implemented!"); }
virtual void WriteVersion(hsStream* s, hsResMgr* mgr) { hsAssert(0, "WriteVersion not implemented!"); }
};
// Macros:
// NOTE: Comfortable use of these macros assumes the compiler is comfortable eating
// a spurious semi-colon (;) following a curly brace. If that isn't the case, they
// can easily be wrapped in something like do { original macro } while(0) or the like.
//
// Normal setup for a class:
// In public section of class declaration, insert the following two macros:
// CLASSNAME_REGISTER( myClassName );
// GETINTERFACE_ANY( myClassName, classIWasDerivedFromName );
// Then in the *Creatable.h file for that library (e.g. plSurfaceCreatable.h), add macro
// REGISTER_CREATABLE( myClassName )
// Finally, add an enum to the plCreatableIndex.h file using CLASS_INDEX(className)
// ( e.g. CLASS_INDEX(hsGMaterial) )
//
// CLASSNAME_REGISTER( plClassName ) - Sets up identification for this
// class. The exposed methods are
// static UInt16 Index() - returns the index for that class.
// virtual UInt16 ClassIndex() - returns index for this object's class.
// static plClassName* Convert(plCreatable* c) - if c exposes an interface
// as plClassName, return that, else nil. Incs the ref count of the object.
// static plClassName* ConvertNoRef(plCreatable* c) - Same as Convert(), but
// doesn't inc the ref count.
// static plClassName* Create() - returns a new object of type plClassName
// Insert into public section of class definition.
//
// Normally one of the next 3 macros should follow CLASSNAME_REGISTER
// GETINTERFACE_ANY - allows an interface to an object as plClassName if an object
// is or is derived from plClassName.
// GETINTERFACE_EXACT - allows an interface as plClassName only if the type is
// exactly of type plClassName
// GETINTERFACE_NONE - Never provide an interface as plClassName.
// Instead of using these macros, the class can provide a method
// virtual plCreatable* GetInterface(UInt16 hClass) which returns an object of
// type matching class handle hClass.
// Insert into public section of class definition (like right after CLASSNAME_REGISTER).
//
// REGISTER_CREATABLE( plClassName ) - normal creatable type, any you can instantiate.
// or
// REGISTER_NONCREATABLE( plClassName ) - can't be created either because it's pure virtual
// or just doesn't want to be creatable. It's Create member returns nil. But Convert
// may return an interface, depending on the GETINTERFACE above.
// - This line is the only exposure to the plCreator.
// This will define a Creator for class plClassName, instantiate it as a static, and register
// it with the Factory. The registration also sets the class index value in the plCreator
// subclass, as well as in the class being registered.
// Put after includes in the *Creatable.h file for the library the class belongs to..
//
// USAGE:
// There is a method of identifying an object's type. You should rarely need it,
// using Create() and Convert() instead.
// ClassIndex() the class handle is an immutable index to this class. It provides an
// instantaneous lookup. It may be stored, loaded, sent over the wire, etc.
//
// Create()
// If you know what type object you want to create at compile time, use
// <ObjectType>::Create()
// But if you have a class index at run-time (e.g. loaded from file), use
// plCreatable* plFactory::Create(hClass);
// The ultra-safe way to do this is:
// plCreatable* tmp = plFactory::Create(idx);
// plWantClassName* p = plWantClassName::Convert(tmp);
// hsRefCnt_SafeUnRef(tmp);
//
// If you have a fred interface to an object f, and want a wilma interface, use
// fred* f = fred::Create(); more likely f was passed in.
// wilma* w = wilma::Convert(f)
// NOTE that two strange things may be true here:
// 1) f != nil, w == nil
// either fred's not really derived from wilma,
// or fred doesn't like to be cast down,
// or wilma just doesn't want to expose an interface.
// 2) f != nil, w != nil, and f != w
// fred has pulled a sneaky and created a wilma to return.
// so unrelated classes can still "Convert" as one another.
//
//
////////////////////////////
// EAp - 01/10/2003
// Added macros to support multiple AUX interfaces primarily,
// but they are not limited to that. Usage example:
//
// plBeginInterfaceMap( plMyClass, plBaseClass );
// plAddInterfaceAux( plFooClass, fFooMember );
// plAddInterfaceAux( plBarClass, fBarMember );
// plAddInterface( plSomeOtherClass );
// plEndInterfaceMap();
//
#define CLASSNAME_REGISTER( plClassName ) \
public: \
virtual const char* ClassName() const { return #plClassName; } \
private: \
static UInt16 plClassName##ClassIndex; \
static void SetClassIndex(UInt16 hClass) { \
plClassName##ClassIndex = hClass; \
} \
public: \
virtual UInt16 ClassIndex() const { \
return plClassName::Index(); \
} \
static UInt16 Index() { \
return plClassName##ClassIndex; \
} \
static plClassName * Create() { \
return (plClassName*)plFactory::Create(plClassName##ClassIndex); \
} \
static plClassName * ConvertNoRef(plCreatable* c) { \
plClassName* retVal = c \
? (plClassName *)c->GetInterface(plClassName##ClassIndex) \
: nil; \
return retVal; \
} \
static const plClassName * ConvertNoRef(const plCreatable* c) { \
const plClassName* retVal = c \
? (const plClassName *)c->GetConstInterface(plClassName##ClassIndex) \
: nil; \
return retVal; \
} \
static plClassName * Convert(plCreatable* c) { \
plClassName* retVal = ConvertNoRef(c); \
hsRefCnt_SafeRef(retVal); \
return retVal; \
} \
static hsBool HasDerivedClass(UInt16 hDer) { \
return plFactory::DerivesFrom(plClassName##ClassIndex, hDer); \
} \
friend class plClassName##__Creator;
#define GETINTERFACE_ANY( plClassName, plBaseName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
return plBaseName::GetInterface(hClass); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
return plBaseName::GetConstInterface(hClass); \
}
#define GETINTERFACE_EXACT( plClassName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
return hBaseClass == plClassName##ClassIndex; \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
return hClass == plClassName##ClassIndex ? this : nil; \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
return hClass == plClassName##ClassIndex ? this : nil; \
}
#define GETINTERFACE_NONE( plClassName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { return false; } \
virtual plCreatable* GetInterface(UInt16 hClass) { \
return nil; \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
return nil; \
}
//
// Macro for converting to base class OR a class member
//
#define GETINTERFACE_ANY_AUX( plClassName, plBaseName, plAuxClassName, plAuxClassMember ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
if (hClass == plAuxClassName::Index()) \
return &plAuxClassMember; \
else \
return plBaseName::GetInterface(hClass); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
if (hClass == plAuxClassName::Index()) \
return &plAuxClassMember; \
else \
return plBaseName::GetConstInterface(hClass); \
}
#define plBeginInterfaceMap( plClassName, plBaseName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
/* NOTE: pulling const off the ptr should be ok, right? */ \
return const_cast<plCreatable*>( GetConstInterface( hClass ) ); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
typedef plBaseName MyBaseClass; \
if( hClass == plClassName##ClassIndex ) \
return this
#define plAddInterface( plClassName ) \
else if ( hClass == plClassName::Index() ) \
return plClassName::GetConstInterface(hClass)
#define plAddInterfaceAux( plAuxClassName, plAuxClassMember ) \
else if ( hClass == plAuxClassName::Index() ) \
return &plAuxClassMember
#define plEndInterfaceMap() \
else \
return MyBaseClass::GetConstInterface(hClass); \
}
#endif // plCreatable_inc
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plCreatable_inc
#define plCreatable_inc
#include "hsRefCnt.h"
#include "plFactory.h"
class plCreator;
class hsStream;
class hsResMgr;
class plCreatable : public hsRefCnt
{
public:
virtual const char* ClassName() const = 0;
virtual plCreatable* GetInterface(UInt16 hClass) { return nil; }
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { return nil; }
static hsBool HasBaseClass(UInt16 hBase) { return false; }
virtual UInt16 ClassIndex() const = 0;
virtual void Read(hsStream* s, hsResMgr* mgr) {}
virtual void Write(hsStream* s, hsResMgr* mgr) {}
// WriteVersion writes the current version of this creatable and ReadVersion will read in
// any previous version.
virtual void ReadVersion(hsStream* s, hsResMgr* mgr) { hsAssert(0, "ReadVersion not implemented!"); }
virtual void WriteVersion(hsStream* s, hsResMgr* mgr) { hsAssert(0, "WriteVersion not implemented!"); }
};
// Macros:
// NOTE: Comfortable use of these macros assumes the compiler is comfortable eating
// a spurious semi-colon (;) following a curly brace. If that isn't the case, they
// can easily be wrapped in something like do { original macro } while(0) or the like.
//
// Normal setup for a class:
// In public section of class declaration, insert the following two macros:
// CLASSNAME_REGISTER( myClassName );
// GETINTERFACE_ANY( myClassName, classIWasDerivedFromName );
// Then in the *Creatable.h file for that library (e.g. plSurfaceCreatable.h), add macro
// REGISTER_CREATABLE( myClassName )
// Finally, add an enum to the plCreatableIndex.h file using CLASS_INDEX(className)
// ( e.g. CLASS_INDEX(hsGMaterial) )
//
// CLASSNAME_REGISTER( plClassName ) - Sets up identification for this
// class. The exposed methods are
// static UInt16 Index() - returns the index for that class.
// virtual UInt16 ClassIndex() - returns index for this object's class.
// static plClassName* Convert(plCreatable* c) - if c exposes an interface
// as plClassName, return that, else nil. Incs the ref count of the object.
// static plClassName* ConvertNoRef(plCreatable* c) - Same as Convert(), but
// doesn't inc the ref count.
// static plClassName* Create() - returns a new object of type plClassName
// Insert into public section of class definition.
//
// Normally one of the next 3 macros should follow CLASSNAME_REGISTER
// GETINTERFACE_ANY - allows an interface to an object as plClassName if an object
// is or is derived from plClassName.
// GETINTERFACE_EXACT - allows an interface as plClassName only if the type is
// exactly of type plClassName
// GETINTERFACE_NONE - Never provide an interface as plClassName.
// Instead of using these macros, the class can provide a method
// virtual plCreatable* GetInterface(UInt16 hClass) which returns an object of
// type matching class handle hClass.
// Insert into public section of class definition (like right after CLASSNAME_REGISTER).
//
// REGISTER_CREATABLE( plClassName ) - normal creatable type, any you can instantiate.
// or
// REGISTER_NONCREATABLE( plClassName ) - can't be created either because it's pure virtual
// or just doesn't want to be creatable. It's Create member returns nil. But Convert
// may return an interface, depending on the GETINTERFACE above.
// - This line is the only exposure to the plCreator.
// This will define a Creator for class plClassName, instantiate it as a static, and register
// it with the Factory. The registration also sets the class index value in the plCreator
// subclass, as well as in the class being registered.
// Put after includes in the *Creatable.h file for the library the class belongs to..
//
// USAGE:
// There is a method of identifying an object's type. You should rarely need it,
// using Create() and Convert() instead.
// ClassIndex() the class handle is an immutable index to this class. It provides an
// instantaneous lookup. It may be stored, loaded, sent over the wire, etc.
//
// Create()
// If you know what type object you want to create at compile time, use
// <ObjectType>::Create()
// But if you have a class index at run-time (e.g. loaded from file), use
// plCreatable* plFactory::Create(hClass);
// The ultra-safe way to do this is:
// plCreatable* tmp = plFactory::Create(idx);
// plWantClassName* p = plWantClassName::Convert(tmp);
// hsRefCnt_SafeUnRef(tmp);
//
// If you have a fred interface to an object f, and want a wilma interface, use
// fred* f = fred::Create(); more likely f was passed in.
// wilma* w = wilma::Convert(f)
// NOTE that two strange things may be true here:
// 1) f != nil, w == nil
// either fred's not really derived from wilma,
// or fred doesn't like to be cast down,
// or wilma just doesn't want to expose an interface.
// 2) f != nil, w != nil, and f != w
// fred has pulled a sneaky and created a wilma to return.
// so unrelated classes can still "Convert" as one another.
//
//
////////////////////////////
// EAp - 01/10/2003
// Added macros to support multiple AUX interfaces primarily,
// but they are not limited to that. Usage example:
//
// plBeginInterfaceMap( plMyClass, plBaseClass );
// plAddInterfaceAux( plFooClass, fFooMember );
// plAddInterfaceAux( plBarClass, fBarMember );
// plAddInterface( plSomeOtherClass );
// plEndInterfaceMap();
//
#define CLASSNAME_REGISTER( plClassName ) \
public: \
virtual const char* ClassName() const { return #plClassName; } \
private: \
static UInt16 plClassName##ClassIndex; \
static void SetClassIndex(UInt16 hClass) { \
plClassName##ClassIndex = hClass; \
} \
public: \
virtual UInt16 ClassIndex() const { \
return plClassName::Index(); \
} \
static UInt16 Index() { \
return plClassName##ClassIndex; \
} \
static plClassName * Create() { \
return (plClassName*)plFactory::Create(plClassName##ClassIndex); \
} \
static plClassName * ConvertNoRef(plCreatable* c) { \
plClassName* retVal = c \
? (plClassName *)c->GetInterface(plClassName##ClassIndex) \
: nil; \
return retVal; \
} \
static const plClassName * ConvertNoRef(const plCreatable* c) { \
const plClassName* retVal = c \
? (const plClassName *)c->GetConstInterface(plClassName##ClassIndex) \
: nil; \
return retVal; \
} \
static plClassName * Convert(plCreatable* c) { \
plClassName* retVal = ConvertNoRef(c); \
hsRefCnt_SafeRef(retVal); \
return retVal; \
} \
static hsBool HasDerivedClass(UInt16 hDer) { \
return plFactory::DerivesFrom(plClassName##ClassIndex, hDer); \
} \
friend class plClassName##__Creator;
#define GETINTERFACE_ANY( plClassName, plBaseName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
return plBaseName::GetInterface(hClass); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
return plBaseName::GetConstInterface(hClass); \
}
#define GETINTERFACE_EXACT( plClassName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
return hBaseClass == plClassName##ClassIndex; \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
return hClass == plClassName##ClassIndex ? this : nil; \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
return hClass == plClassName##ClassIndex ? this : nil; \
}
#define GETINTERFACE_NONE( plClassName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { return false; } \
virtual plCreatable* GetInterface(UInt16 hClass) { \
return nil; \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
return nil; \
}
//
// Macro for converting to base class OR a class member
//
#define GETINTERFACE_ANY_AUX( plClassName, plBaseName, plAuxClassName, plAuxClassMember ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
if (hClass == plAuxClassName::Index()) \
return &plAuxClassMember; \
else \
return plBaseName::GetInterface(hClass); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
if( hClass == plClassName##ClassIndex ) \
return this; \
else \
if (hClass == plAuxClassName::Index()) \
return &plAuxClassMember; \
else \
return plBaseName::GetConstInterface(hClass); \
}
#define plBeginInterfaceMap( plClassName, plBaseName ) \
static hsBool HasBaseClass(UInt16 hBaseClass) { \
if( hBaseClass == plClassName##ClassIndex ) \
return true; \
else \
return plBaseName::HasBaseClass(hBaseClass); \
} \
virtual plCreatable* GetInterface(UInt16 hClass) { \
/* NOTE: pulling const off the ptr should be ok, right? */ \
return const_cast<plCreatable*>( GetConstInterface( hClass ) ); \
} \
virtual const plCreatable* GetConstInterface(UInt16 hClass) const { \
typedef plBaseName MyBaseClass; \
if( hClass == plClassName##ClassIndex ) \
return this
#define plAddInterface( plClassName ) \
else if ( hClass == plClassName::Index() ) \
return plClassName::GetConstInterface(hClass)
#define plAddInterfaceAux( plAuxClassName, plAuxClassMember ) \
else if ( hClass == plAuxClassName::Index() ) \
return &plAuxClassMember
#define plEndInterfaceMap() \
else \
return MyBaseClass::GetConstInterface(hClass); \
}
#endif // plCreatable_inc

View File

@ -1,171 +1,171 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plCreator_inc
#define plCreator_inc
#include "plClassIndexMacros.h"
#include "plCreatableIndex.h"
#include "plFactory.h"
class plCreatable;
class plCreator
{
private:
protected:
public:
plCreator() { }
virtual ~plCreator() { }
virtual plCreatable* Create() const = 0;
virtual UInt16 ClassIndex() = 0;
virtual const char* ClassName() const = 0;
virtual hsBool HasBaseClass(UInt16 hBase) = 0;
friend class plFactory;
};
#define REGISTER_CREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return TRACKED_NEW plClassName; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define REGISTER_NONCREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return nil; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define DECLARE_EXTERNAL_CREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
void Register() \
{ \
plFactory::Register( EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
void UnRegister() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return EXTERN_CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return TRACKED_NEW plClassName; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define REGISTER_EXTERNAL_CREATABLE(plClassName) \
static##plClassName##__Creator.Register(); //
#define UNREGISTER_EXTERNAL_CREATABLE(plClassName) \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), &static##plClassName##__Creator);
#define REGISTER_EXTERNAL_NONCREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return EXTERN_CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return nil; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#endif // plCreator_inc
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plCreator_inc
#define plCreator_inc
#include "plClassIndexMacros.h"
#include "plCreatableIndex.h"
#include "plFactory.h"
class plCreatable;
class plCreator
{
private:
protected:
public:
plCreator() { }
virtual ~plCreator() { }
virtual plCreatable* Create() const = 0;
virtual UInt16 ClassIndex() = 0;
virtual const char* ClassName() const = 0;
virtual hsBool HasBaseClass(UInt16 hBase) = 0;
friend class plFactory;
};
#define REGISTER_CREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return TRACKED_NEW plClassName; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define REGISTER_NONCREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return nil; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define DECLARE_EXTERNAL_CREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
void Register() \
{ \
plFactory::Register( EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
void UnRegister() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return EXTERN_CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return TRACKED_NEW plClassName; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#define REGISTER_EXTERNAL_CREATABLE(plClassName) \
static##plClassName##__Creator.Register(); //
#define UNREGISTER_EXTERNAL_CREATABLE(plClassName) \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), &static##plClassName##__Creator);
#define REGISTER_EXTERNAL_NONCREATABLE( plClassName ) \
\
class plClassName##__Creator : public plCreator \
{ \
public: \
plClassName##__Creator() \
{ \
plFactory::Register( EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
plClassName::SetClassIndex(ClassIndex()); \
} \
virtual ~plClassName##__Creator() \
{ \
plFactory::UnRegister(EXTERN_CLASS_INDEX_SCOPED(plClassName), this); \
} \
\
virtual hsBool HasBaseClass(UInt16 hBase) { return plClassName::HasBaseClass(hBase); } \
\
virtual UInt16 ClassIndex() { return EXTERN_CLASS_INDEX_SCOPED(plClassName); } \
virtual const char* ClassName() const { return #plClassName; } \
\
virtual plCreatable* Create() const { return nil; } \
\
}; \
static plClassName##__Creator static##plClassName##__Creator; \
UInt16 plClassName::plClassName##ClassIndex = 0; //
#endif // plCreator_inc

View File

@ -1,341 +1,341 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#define PLFACTORY_PRIVATE
#include "hsTypes.h"
#include "plFactory.h"
#include "hsStream.h"
#include "plCreatable.h"
#include "plCreator.h"
#include "hsUtils.h"
// For class names
#include "plCreatableStrings.h"
static plFactory* theFactory = nil;
plFactory::plFactory()
{
fCreators.SetCountAndZero(plCreatableIndex::plNumClassIndices);
}
plFactory::~plFactory()
{
}
hsBool plFactory::ICreateTheFactory()
{
if( theFactory )
return true;
theFactory = TRACKED_NEW plFactory;
return theFactory != nil;
}
UInt16 plFactory::IGetNumClasses()
{
return plCreatableIndex::plNumClassIndices;
}
void plFactory::IForceShutdown()
{
int i;
for( i = 0; i < fCreators.GetCount(); i++ )
{
if( fCreators[i] )
{
hsRefCnt_SafeUnRef(this);
fCreators[i] = nil;
}
}
}
void plFactory::IShutdown()
{
delete theFactory;
theFactory = nil;
}
UInt16 plFactory::IRegister(UInt16 hClass, plCreator* worker)
{
delete fCreators[hClass];
fCreators[hClass] = worker;
return hClass;
}
//
// return true if creator exists
//
bool plFactory::CanCreate(UInt16 hClass)
{
if( hClass & 0x8000 ) // nil creatable
return false;
if( !theFactory && !ICreateTheFactory() ) // no factory
return false;
if( hClass >= theFactory->IGetNumClasses() ) // invalid index
return false;
return ( theFactory->fCreators[ hClass ] != nil ); // check creator
}
plCreatable* plFactory::ICreate(UInt16 hClass)
{
if (CanCreate(hClass))
{
return fCreators[hClass]->Create();
}
if (!(hClass & 0x8000))
{
hsAssert( false, "Invalid class index or nil creator : plFactory::Create()" );
}
return nil;
}
void plFactory::UnRegister(UInt16 hClass, plCreator* worker)
{
if( theFactory )
{
theFactory->IUnRegister(hClass);
hsRefCnt_SafeUnRef(theFactory);
if( theFactory->RefCnt() < 2 )
IShutdown();
}
}
void plFactory::IUnRegister(UInt16 hClass)
{
fCreators[hClass] = nil;
}
UInt16 plFactory::Register(UInt16 hClass, plCreator* worker)
{
if( !theFactory && !ICreateTheFactory() )
return nil;
hsRefCnt_SafeRef(theFactory);
return theFactory->IRegister(hClass, worker);
}
plCreatable* plFactory::Create(UInt16 hClass)
{
if( !theFactory && !ICreateTheFactory() )
return nil;
return theFactory->ICreate(hClass);
}
UInt16 plFactory::GetNumClasses()
{
if( !theFactory && !ICreateTheFactory() )
return 0;
return theFactory->IGetNumClasses();
}
hsBool plFactory::IDerivesFrom(UInt16 hBase, UInt16 hDer)
{
if( hDer >= fCreators.GetCount() )
return false;
return fCreators[hDer] ? fCreators[hDer]->HasBaseClass(hBase) : false;
}
hsBool plFactory::DerivesFrom(UInt16 hBase, UInt16 hDer)
{
if( !theFactory && !ICreateTheFactory() )
return 0;
return theFactory->IDerivesFrom(hBase, hDer);
}
// slow lookup for things like console
UInt16 plFactory::FindClassIndex(const char* className)
{
int numClasses=GetNumClasses();
if (className && theFactory)
{
int i;
for( i = 0; i < theFactory->fCreators.GetCount(); i++ )
{
if( theFactory->fCreators[i] && !_stricmp(className, theFactory->fCreators[i]->ClassName()) )
{
return theFactory->fCreators[i]->ClassIndex();
}
}
}
return numClasses; // err
}
hsBool plFactory::IIsValidClassIndex(UInt16 hClass)
{
return ( hClass < fCreators.GetCount() );
}
hsBool plFactory::IsValidClassIndex(UInt16 hClass)
{
return theFactory->IIsValidClassIndex(hClass);
}
void plFactory::SetTheFactory(plFactory* fac)
{
// There are four cases here.
// 1) Our factory is nil, and we're being given one to use
// Just take it and ref it.
// 2) Our factory is non-nil, and we're being given on to use
// Ours is bogus, pitch it and use the new one.
// 3) Our factory is non-nil, and we're being given a nil one
// Means we're being shut down. Unref the old one. If
// the refcnt drops to one, we're the last one out, so
// go ahead and delete it.
// 4) Our factory is nil and the new one is nil
// Shouldn't happen, but if it does, just ignore it.
if( !theFactory && fac )
{
hsRefCnt_SafeAssign(theFactory, fac);
}
else if( theFactory && fac )
{
theFactory->IForceShutdown();
hsRefCnt_SafeAssign(theFactory, fac);
}
else if( theFactory && !fac )
{
hsRefCnt_SafeUnRef(theFactory);
if( theFactory->RefCnt() < 2 )
delete theFactory;
theFactory = nil;
}
}
plFactory* plFactory::GetTheFactory()
{
if( !theFactory && !ICreateTheFactory() )
return nil;
return theFactory;
}
// For my own nefarious purposes... hsStatusMessage plCreatableIndex
const char *plFactory::GetNameOfClass(UInt16 type)
{
if( type < GetNumClasses() )
{
if( theFactory->fCreators[ type ] )
return theFactory->fCreators[ type ]->ClassName();
static int keyedStringsSize = sizeof(plCreatableStrings::fKeyedStrings)/4;
// If we don't have a creator yet, try falling back on plCreatableStrings
if( type < KEYED_OBJ_DELINEATOR && type<keyedStringsSize)
return plCreatableStrings::fKeyedStrings[ type ];
if (type < plCreatableIndex::kDatabaseStructIndexesStart)
{
static int nonKeyedStringsSize = sizeof(plCreatableStrings::fNonKeyedStrings)/4;
int idx=type - KEYED_OBJ_DELINEATOR;
if (idx<nonKeyedStringsSize)
return plCreatableStrings::fNonKeyedStrings[ idx ];
}
static int nonKeyedPostDBStringsSize = sizeof(plCreatableStrings::fNonKeyedPostDBStrings)/4;
int idx=type - plCreatableIndex::kDatabaseStructIndexesEnd -1;
if (idx<nonKeyedPostDBStringsSize)
return plCreatableStrings::fNonKeyedPostDBStrings[ idx ];
}
hsAssert(type < GetNumClasses() || type==0xffff,"InValid type");
return nil;
}
#ifdef HS_DEBUGGING
/*
**
** Function Name: Validate
** Input(s): Void
** Output(s): Void
** Function Description: This function examines all the Workers in the Factory and compares their Factory
** index to the Enums found in plCreatableIndex. If they are Keyed objects, and
** larger than 512 on the Factory index, or non-Keyed objects with a Factory
** index of less than 512, exit with an Error Message. Otherwise continue through
** the iteration of Factory Indices.
**
**
*/
void plFactory::IValidate(UInt16 keyIndex)
{
int FactoryIndex = GetNumClasses();
hsBool bogus = false;
for(int iter=0; iter < FactoryIndex; iter++)
{
if (IDerivesFrom(keyIndex, iter))
{
if(iter >= KEYED_OBJ_DELINEATOR && theFactory->fCreators[iter])
{
char Buffer[512];
sprintf(Buffer, "Object %s is a hsKeyedObject, Must appear before 'KEYED_OBJ_DELINEATOR' in plCreatableIndex.h\n",GetNameOfClass(iter));
hsStatusMessage(Buffer);
bogus = true;
}
}
else
{
if(iter < KEYED_OBJ_DELINEATOR && theFactory->fCreators[iter])
{
char Buffer[512];
sprintf(Buffer, "Object %s is NOT a hsKeyedObject, Must appear after 'KEYED_OBJ_DELINEATOR' in plCreatableIndex.h\n",GetNameOfClass(iter));
hsStatusMessage(Buffer);
bogus = true;
}
}
}
hsAssert(!bogus,"The class(s) you just added to plCreatableIndex.h in wrong spot, see output window");
}
void plFactory::Validate(UInt16 keyIndex)
{
theFactory->IValidate(keyIndex);
}
#endif
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#define PLFACTORY_PRIVATE
#include "hsTypes.h"
#include "plFactory.h"
#include "hsStream.h"
#include "plCreatable.h"
#include "plCreator.h"
#include "hsUtils.h"
// For class names
#include "plCreatableStrings.h"
static plFactory* theFactory = nil;
plFactory::plFactory()
{
fCreators.SetCountAndZero(plCreatableIndex::plNumClassIndices);
}
plFactory::~plFactory()
{
}
hsBool plFactory::ICreateTheFactory()
{
if( theFactory )
return true;
theFactory = TRACKED_NEW plFactory;
return theFactory != nil;
}
UInt16 plFactory::IGetNumClasses()
{
return plCreatableIndex::plNumClassIndices;
}
void plFactory::IForceShutdown()
{
int i;
for( i = 0; i < fCreators.GetCount(); i++ )
{
if( fCreators[i] )
{
hsRefCnt_SafeUnRef(this);
fCreators[i] = nil;
}
}
}
void plFactory::IShutdown()
{
delete theFactory;
theFactory = nil;
}
UInt16 plFactory::IRegister(UInt16 hClass, plCreator* worker)
{
delete fCreators[hClass];
fCreators[hClass] = worker;
return hClass;
}
//
// return true if creator exists
//
bool plFactory::CanCreate(UInt16 hClass)
{
if( hClass & 0x8000 ) // nil creatable
return false;
if( !theFactory && !ICreateTheFactory() ) // no factory
return false;
if( hClass >= theFactory->IGetNumClasses() ) // invalid index
return false;
return ( theFactory->fCreators[ hClass ] != nil ); // check creator
}
plCreatable* plFactory::ICreate(UInt16 hClass)
{
if (CanCreate(hClass))
{
return fCreators[hClass]->Create();
}
if (!(hClass & 0x8000))
{
hsAssert( false, "Invalid class index or nil creator : plFactory::Create()" );
}
return nil;
}
void plFactory::UnRegister(UInt16 hClass, plCreator* worker)
{
if( theFactory )
{
theFactory->IUnRegister(hClass);
hsRefCnt_SafeUnRef(theFactory);
if( theFactory->RefCnt() < 2 )
IShutdown();
}
}
void plFactory::IUnRegister(UInt16 hClass)
{
fCreators[hClass] = nil;
}
UInt16 plFactory::Register(UInt16 hClass, plCreator* worker)
{
if( !theFactory && !ICreateTheFactory() )
return nil;
hsRefCnt_SafeRef(theFactory);
return theFactory->IRegister(hClass, worker);
}
plCreatable* plFactory::Create(UInt16 hClass)
{
if( !theFactory && !ICreateTheFactory() )
return nil;
return theFactory->ICreate(hClass);
}
UInt16 plFactory::GetNumClasses()
{
if( !theFactory && !ICreateTheFactory() )
return 0;
return theFactory->IGetNumClasses();
}
hsBool plFactory::IDerivesFrom(UInt16 hBase, UInt16 hDer)
{
if( hDer >= fCreators.GetCount() )
return false;
return fCreators[hDer] ? fCreators[hDer]->HasBaseClass(hBase) : false;
}
hsBool plFactory::DerivesFrom(UInt16 hBase, UInt16 hDer)
{
if( !theFactory && !ICreateTheFactory() )
return 0;
return theFactory->IDerivesFrom(hBase, hDer);
}
// slow lookup for things like console
UInt16 plFactory::FindClassIndex(const char* className)
{
int numClasses=GetNumClasses();
if (className && theFactory)
{
int i;
for( i = 0; i < theFactory->fCreators.GetCount(); i++ )
{
if( theFactory->fCreators[i] && !_stricmp(className, theFactory->fCreators[i]->ClassName()) )
{
return theFactory->fCreators[i]->ClassIndex();
}
}
}
return numClasses; // err
}
hsBool plFactory::IIsValidClassIndex(UInt16 hClass)
{
return ( hClass < fCreators.GetCount() );
}
hsBool plFactory::IsValidClassIndex(UInt16 hClass)
{
return theFactory->IIsValidClassIndex(hClass);
}
void plFactory::SetTheFactory(plFactory* fac)
{
// There are four cases here.
// 1) Our factory is nil, and we're being given one to use
// Just take it and ref it.
// 2) Our factory is non-nil, and we're being given on to use
// Ours is bogus, pitch it and use the new one.
// 3) Our factory is non-nil, and we're being given a nil one
// Means we're being shut down. Unref the old one. If
// the refcnt drops to one, we're the last one out, so
// go ahead and delete it.
// 4) Our factory is nil and the new one is nil
// Shouldn't happen, but if it does, just ignore it.
if( !theFactory && fac )
{
hsRefCnt_SafeAssign(theFactory, fac);
}
else if( theFactory && fac )
{
theFactory->IForceShutdown();
hsRefCnt_SafeAssign(theFactory, fac);
}
else if( theFactory && !fac )
{
hsRefCnt_SafeUnRef(theFactory);
if( theFactory->RefCnt() < 2 )
delete theFactory;
theFactory = nil;
}
}
plFactory* plFactory::GetTheFactory()
{
if( !theFactory && !ICreateTheFactory() )
return nil;
return theFactory;
}
// For my own nefarious purposes... hsStatusMessage plCreatableIndex
const char *plFactory::GetNameOfClass(UInt16 type)
{
if( type < GetNumClasses() )
{
if( theFactory->fCreators[ type ] )
return theFactory->fCreators[ type ]->ClassName();
static int keyedStringsSize = sizeof(plCreatableStrings::fKeyedStrings)/4;
// If we don't have a creator yet, try falling back on plCreatableStrings
if( type < KEYED_OBJ_DELINEATOR && type<keyedStringsSize)
return plCreatableStrings::fKeyedStrings[ type ];
if (type < plCreatableIndex::kDatabaseStructIndexesStart)
{
static int nonKeyedStringsSize = sizeof(plCreatableStrings::fNonKeyedStrings)/4;
int idx=type - KEYED_OBJ_DELINEATOR;
if (idx<nonKeyedStringsSize)
return plCreatableStrings::fNonKeyedStrings[ idx ];
}
static int nonKeyedPostDBStringsSize = sizeof(plCreatableStrings::fNonKeyedPostDBStrings)/4;
int idx=type - plCreatableIndex::kDatabaseStructIndexesEnd -1;
if (idx<nonKeyedPostDBStringsSize)
return plCreatableStrings::fNonKeyedPostDBStrings[ idx ];
}
hsAssert(type < GetNumClasses() || type==0xffff,"InValid type");
return nil;
}
#ifdef HS_DEBUGGING
/*
**
** Function Name: Validate
** Input(s): Void
** Output(s): Void
** Function Description: This function examines all the Workers in the Factory and compares their Factory
** index to the Enums found in plCreatableIndex. If they are Keyed objects, and
** larger than 512 on the Factory index, or non-Keyed objects with a Factory
** index of less than 512, exit with an Error Message. Otherwise continue through
** the iteration of Factory Indices.
**
**
*/
void plFactory::IValidate(UInt16 keyIndex)
{
int FactoryIndex = GetNumClasses();
hsBool bogus = false;
for(int iter=0; iter < FactoryIndex; iter++)
{
if (IDerivesFrom(keyIndex, iter))
{
if(iter >= KEYED_OBJ_DELINEATOR && theFactory->fCreators[iter])
{
char Buffer[512];
sprintf(Buffer, "Object %s is a hsKeyedObject, Must appear before 'KEYED_OBJ_DELINEATOR' in plCreatableIndex.h\n",GetNameOfClass(iter));
hsStatusMessage(Buffer);
bogus = true;
}
}
else
{
if(iter < KEYED_OBJ_DELINEATOR && theFactory->fCreators[iter])
{
char Buffer[512];
sprintf(Buffer, "Object %s is NOT a hsKeyedObject, Must appear after 'KEYED_OBJ_DELINEATOR' in plCreatableIndex.h\n",GetNameOfClass(iter));
hsStatusMessage(Buffer);
bogus = true;
}
}
}
hsAssert(!bogus,"The class(s) you just added to plCreatableIndex.h in wrong spot, see output window");
}
void plFactory::Validate(UInt16 keyIndex)
{
theFactory->IValidate(keyIndex);
}
#endif

View File

@ -1,96 +1,96 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plFactory_inc
#define plFactory_inc
#ifdef PLFACTORY_PRIVATE
#include "hsTemplates.h"
#endif
#include "hsRefCnt.h"
#include "hsTypes.h"
class plCreator;
class plCreatable;
class hsStream;
class hsResMgr;
class plFactory : public hsRefCnt
{
#ifdef PLFACTORY_PRIVATE
private:
hsTArray<plCreator*> fCreators;
void IForceShutdown();
void IUnRegister(UInt16 hClass);
UInt16 IRegister(UInt16 hClass, plCreator* worker);
hsBool IIsEmpty();
UInt16 IGetNumClasses();
plCreatable* ICreate(UInt16 hClass);
hsBool IDerivesFrom(UInt16 hBase, UInt16 hDer);
hsBool IIsValidClassIndex(UInt16 hClass);
static hsBool ICreateTheFactory();
static void IShutdown();
plFactory();
~plFactory();
#endif
public:
// Don't use this unless you're initializing a DLL
friend class plClient;
static plFactory* GetTheFactory();
static UInt16 Register(UInt16 hClass, plCreator* worker); // returns hClass
static void UnRegister(UInt16 hClass, plCreator* worker);
static bool CanCreate(UInt16 hClass); // return true if creator exists. doesn't assert
static plCreatable* Create(UInt16 hClass);
static hsBool DerivesFrom(UInt16 hBase, UInt16 hDer);
static UInt16 GetNumClasses();
static UInt16 FindClassIndex(const char* className); // slow lookup for things like console
static hsBool IsValidClassIndex(UInt16 hClass);
// Don't call this unless you're a DLL being initialized.
static void SetTheFactory(plFactory* fac);
static const char *GetNameOfClass(UInt16 type);
#ifdef HS_DEBUGGING
void IValidate(UInt16 keyIndex);
static void Validate(UInt16 keyIndex);
#endif
};
#endif // plFactory_inc
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef plFactory_inc
#define plFactory_inc
#ifdef PLFACTORY_PRIVATE
#include "hsTemplates.h"
#endif
#include "hsRefCnt.h"
#include "hsTypes.h"
class plCreator;
class plCreatable;
class hsStream;
class hsResMgr;
class plFactory : public hsRefCnt
{
#ifdef PLFACTORY_PRIVATE
private:
hsTArray<plCreator*> fCreators;
void IForceShutdown();
void IUnRegister(UInt16 hClass);
UInt16 IRegister(UInt16 hClass, plCreator* worker);
hsBool IIsEmpty();
UInt16 IGetNumClasses();
plCreatable* ICreate(UInt16 hClass);
hsBool IDerivesFrom(UInt16 hBase, UInt16 hDer);
hsBool IIsValidClassIndex(UInt16 hClass);
static hsBool ICreateTheFactory();
static void IShutdown();
plFactory();
~plFactory();
#endif
public:
// Don't use this unless you're initializing a DLL
friend class plClient;
static plFactory* GetTheFactory();
static UInt16 Register(UInt16 hClass, plCreator* worker); // returns hClass
static void UnRegister(UInt16 hClass, plCreator* worker);
static bool CanCreate(UInt16 hClass); // return true if creator exists. doesn't assert
static plCreatable* Create(UInt16 hClass);
static hsBool DerivesFrom(UInt16 hBase, UInt16 hDer);
static UInt16 GetNumClasses();
static UInt16 FindClassIndex(const char* className); // slow lookup for things like console
static hsBool IsValidClassIndex(UInt16 hClass);
// Don't call this unless you're a DLL being initialized.
static void SetTheFactory(plFactory* fac);
static const char *GetNameOfClass(UInt16 type);
#ifdef HS_DEBUGGING
void IValidate(UInt16 keyIndex);
static void Validate(UInt16 keyIndex);
#endif
};
#endif // plFactory_inc