AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzXomlResource.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CZ_XOML_RESOURCE_H_)
00015 #define _CZ_XOML_RESOURCE_H_
00016 
00017 #include "CzString.h"
00018 #include "CzUtil.h"
00019 #include "CzXml.h"
00020 #include "CzXomlResourceManager.h"
00021 
00022 class CzAnimInstance;
00023 class IzAnimTarget;
00024 class CzXomlClassDef;
00025 struct CzXomlProperty;
00026 struct CzXomlVariable;
00027 
00028 /**
00029  @addtogroup XOML
00030  @{
00031  */
00032 
00033 /**
00034  @class IzXomlResource
00035 
00036  @brief Base class that is used by all classes that can be instantiated from XOML markup
00037 
00038  All classes that can be created from XOML are derived from IzXomlResource. IzXomlResource provides the base details of the XOML resource including:
00039  - Name of resource
00040  - Generic type of class
00041  - Actual type of class
00042  - Pure virtual LoadFromXoml method that should be implemented by derived classes. The XOML system will call this method to initialise the class from its XML attriibutes and inner tags
00043 
00044  Each class that is derived from IzXomlResource must have a creator which is a class derived from IzXomlClassCreator which creates an instance of our XOML class. The creator class is 
00045  a very simple class as is shown by the scene creator class example below:
00046 
00047  @code
00048 class CzSceneCreator : public IzXomlClassCreator
00049 {
00050 public:
00051     CzSceneCreator()
00052     {
00053         setClassName("scene");
00054     }
00055     IzXomlResource* CreateInstance(IzXomlResource* parent) { return new CzScene(); }
00056 };
00057  @endcode
00058 
00059  To create a class that can be instantiated from XOML you should:
00060  - Derive the class from IzXomlResource
00061  - Set its XOML base type (game, actor, scene, animation etc..)
00062  - Implement a class derived from IzXomlClassCreator that implements CreateInstance() which creates an instance of the class
00063  - Add the class type to the list of class creators in CZ_XOML using addClass()
00064 
00065  */
00066 class IzXomlResource
00067 {
00068 public:
00069 
00070     /**
00071      @enum  eSetPropertyError
00072     
00073      @brief Values that represent a SetProperty error
00074 
00075         NotFound - The requested property was not found
00076         Success - Property was set successfully
00077         IncompatibleTypes - The supplied data is not compatible with the target property type
00078         ReadOnly - The property is read only
00079         SearchForResource - The property that was supplied is of type string but the target property is a resuorce. If this occurs then usually the caller will search for the resuorce
00080      */
00081     enum eSetPropertyError
00082     {
00083         NotFound = 0, 
00084         Success = 1, 
00085         SearchForResource = 2, 
00086         IncompatibleTypes = -1, 
00087         NoAccess = -2, 
00088     };
00089 
00090     // Properties
00091 protected:
00092     CzString                Name;                   ///< Resource name (unique per resource type)
00093     CzString                DebugInfo;              ///< Filename and line number for debug info
00094 #if defined (_DEBUG)
00095     CzString                ClassType;              ///< Resource class type
00096     CzString                ActualClassType;        ///< Actual class type
00097     CzString                Tag;                    ///< Tag name (used to group resource into groups)
00098 #endif  // _DEBUG
00099     CzXomlResourceManager*  Parent;                 ///< Parent manager
00100     bool                    Managed;                ///< True if managed by the resource system. Managed resources are auto cleaned up by the resource system
00101     unsigned int            NameHash;               ///< Resource name hash
00102     unsigned int            ClassTypeHash;          ///< Base type of XOML class (e.g. Scene, Actor, Animation, Game etc..)
00103     unsigned int            ActualClassTypeHash;    ///< Actual type of XOML class
00104     unsigned int            TagHash;                ///< Tag name as a string hash, used to put resources into loading groups
00105     IzXomlResource*         Container;              ///< The resource that acts as the container for this resource
00106 public:
00107     void                    setParent(CzXomlResourceManager* parent) { Parent = parent; }
00108     CzXomlResourceManager*  getParent()                             { return Parent; }
00109     void                    setName(const char* name);
00110     CzString&               getName()                               { return Name; }
00111     void                    setDebugInfo(const char* info)          { DebugInfo = info; }
00112     CzString&               getDebugInfo()                          { return DebugInfo; }
00113     unsigned int            getNameHash()                           { return NameHash; }
00114     void                    setClassType(const char* type_name);
00115     unsigned int            getClassTypeHash()                      { return ClassTypeHash; }
00116     void                    setActualClassType(const char* type_name);
00117     unsigned int            getActualClassTypeHash()                { return ActualClassTypeHash; }
00118     void                    setTag(const char* Tag);
00119 #if defined (_DEBUG)
00120     CzString&               getTag()                                { return Tag; }
00121 #endif  // _DEBUG
00122     unsigned int            getTagHash()                            { return TagHash; }
00123     void                    setManaged(bool managed)                { Managed = managed; }
00124     bool                    isManaged() const                       { return Managed; }
00125     void                    setContainer(IzXomlResource* container) { Container = container; }
00126     IzXomlResource*         getContainer()                          { return Container; }
00127     // Properties end
00128 protected:
00129 public:
00130     IzXomlResource() : Managed(false), Parent(NULL) {}
00131     virtual ~IzXomlResource() {}
00132 
00133     virtual int     LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node) = 0;
00134     virtual bool    PostLoadFromXoml(IzXomlResource* parent, CzXmlNode* node) { return true; }
00135 
00136     virtual void    Remove();
00137 
00138     static int      setProperty(CzXomlClassDef* class_def, IzXomlResource* target, unsigned int property_name, const CzString& data, bool delta);
00139     static int      setProperty(CzXomlClassDef* class_def, IzXomlResource* target, unsigned int property_name, const CzXomlProperty& prop, bool delta);
00140     static int      setProperty(CzXomlClassDef* class_def, IzAnimTarget* target, CzAnimInstance* animation);
00141     static int      setProperty(CzXomlClassDef* class_def, IzXomlResource* target, unsigned int property_name, CzXomlVariable* variable);
00142     static int      getProperty(CzXomlClassDef* class_def, IzXomlResource* target, unsigned int property_name, CzXomlProperty& prop);
00143     // Internal
00144 };
00145 
00146 
00147 /// @}
00148 
00149 #endif  // _CZ_XOML_RESOURCE_H_