1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASAXFWL_INTERMEDIATETARGETABLE_H__
12 #define __COLLADASAXFWL_INTERMEDIATETARGETABLE_H__
13 
14 #include "COLLADASaxFWLPrerequisites.h"
15 
16 
17 namespace COLLADASaxFWL
18 {
19 
20 	typedef size_t ClassId;
21 
22 	namespace INTERMEDIATETARGETABLE_TYPE
23 	{
24 		const ClassId
25 			NO_TYPE = 0,
26 			KINEMATICS_INSTANCE = 1,
27 			KINEMATICATTACHMENT = 2,
28 			KINEMATICLINK = 3,
29 			KINEMATICMODEL = 4,
30 			KINEMATICCONTROLLER = 5,
31 			KINEMATICSCENE = 6
32 			;
33 	}
34 
35 	/** Use this as base class for all classes that can appear in the sid tree and that are not derived from
36 	framework Animatable, Object or Targetable. It should only be used for Loader specific classes that store
37 	intermediate data.*/
38 	class IntermediateTargetable
39 	{
40 	public:
~IntermediateTargetable()41 		virtual ~IntermediateTargetable(){};
42 
43 		/** Returns the class id of the targetable.*/
44 		virtual ClassId getClassId() const =0;
45 	};
46 
47 
48 	/** Base class of all classes that can be referenced in the model.*/
49 	template<ClassId classId>
50 	class IntermediateTargetableTemplate : public IntermediateTargetable
51 	{
52 	public:
IntermediateTargetableTemplate()53 		IntermediateTargetableTemplate() {}
~IntermediateTargetableTemplate()54 		virtual ~IntermediateTargetableTemplate(){};
55 
56 		/** Returns the class id of the targetable.*/
ID()57 		static ClassId ID() { return classId; }
58 
59 		/** Returns the class id of the targetable.*/
getClassId()60 		ClassId getClassId() const { return ID(); }
61 	};
62 
63 	template<class IntermediateTargetableType>
intermediateTargetableSafeCast(IntermediateTargetable * targetable)64 	IntermediateTargetableType* intermediateTargetableSafeCast(IntermediateTargetable* targetable)
65 	{
66 		if ( !targetable)
67 			return 0;
68 
69 		if ( targetable->getClassId() == IntermediateTargetableType::ID() )
70 			return (IntermediateTargetableType*)targetable;
71 		else
72 			return 0;
73 	}
74 
75 	template<class IntermediateTargetableType>
intermediateTargetableSafeCast(const IntermediateTargetable * targetable)76 	const IntermediateTargetableType* intermediateTargetableSafeCast( const IntermediateTargetable* targetable)
77 	{
78 		if ( !targetable)
79 			return 0;
80 
81 		if ( targetable->getClassId() == IntermediateTargetableType::ID() )
82 			return (IntermediateTargetableType*)targetable;
83 		else
84 			return 0;
85 	}
86 
87 } // namespace COLLADASAXFWL
88 
89 #endif // __COLLADASAXFWL_INTERMEDIATETARGETABLE_H__
90