From a87be66ab1dae7eb4257e2a0d828412fc630c46e Mon Sep 17 00:00:00 2001
From: Tazpn <tazpn@users.sourceforge.net>
Date: Mon, 12 Jun 2006 22:56:56 +0000
Subject: [PATCH] Update Ni*Properties with helper functions.  Flags are left
 as ushort for now until enums are generated by xml. Add DynamicCast for
 collections.  Disabled with USE_NIFLIB_TEMPLATE_HELPERS by default to avoid
 showing up in python.

---
 obj/NiDitherProperty.cpp      |  8 ++++
 obj/NiDitherProperty.h        |  4 ++
 obj/NiFogProperty.cpp         | 24 ++++++++++++
 obj/NiFogProperty.h           | 10 +++++
 obj/NiObject.h                | 32 ++++++++++++++++
 obj/NiShadeProperty.cpp       |  7 ++++
 obj/NiShadeProperty.h         |  4 ++
 obj/NiSpecularProperty.cpp    |  7 ++++
 obj/NiSpecularProperty.h      |  4 ++
 obj/NiStencilProperty.cpp     | 71 +++++++++++++++++++++++++++++++++++
 obj/NiStencilProperty.h       | 29 ++++++++++++++
 obj/NiVertexColorProperty.cpp | 23 ++++++++++++
 obj/NiVertexColorProperty.h   | 10 +++++
 obj/NiWireframeProperty.cpp   |  8 ++++
 obj/NiWireframeProperty.h     |  4 ++
 obj/NiZBufferProperty.cpp     | 15 ++++++++
 obj/NiZBufferProperty.h       |  7 ++++
 17 files changed, 267 insertions(+)

diff --git a/obj/NiDitherProperty.cpp b/obj/NiDitherProperty.cpp
index 6e3048b4..0a0d8765 100644
--- a/obj/NiDitherProperty.cpp
+++ b/obj/NiDitherProperty.cpp
@@ -34,3 +34,11 @@ const Type & NiDitherProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiDitherProperty::GetFlags() const {
+   return flags;
+}
+
+void NiDitherProperty::SetFlags( ushort n ) {
+   flags = n;
+}
+
diff --git a/obj/NiDitherProperty.h b/obj/NiDitherProperty.h
index 98251087..72fcba7e 100644
--- a/obj/NiDitherProperty.h
+++ b/obj/NiDitherProperty.h
@@ -27,6 +27,10 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags( ushort n );
+
 protected:
 	NI_DITHER_PROPERTY_MEMBERS
 };
diff --git a/obj/NiFogProperty.cpp b/obj/NiFogProperty.cpp
index 5bfd82db..ebfc2fd9 100644
--- a/obj/NiFogProperty.cpp
+++ b/obj/NiFogProperty.cpp
@@ -34,3 +34,27 @@ const Type & NiFogProperty::GetType() const {
 	return TYPE;
 };
 
+
+ushort NiFogProperty::GetFlags() const {
+   return flags;
+}
+
+void NiFogProperty::SetFlags( ushort n ) {
+   flags = n;
+}
+
+float NiFogProperty::GetFogDepth() const {
+   return fogDepth;
+}
+
+void NiFogProperty::SetFogDepth(float value) {
+   fogDepth = value;
+}
+
+Color3 NiFogProperty::GetFogColor() const {
+   return fogColor;
+}
+
+void NiFogProperty::SetFogColor(Color3 value) {
+   fogColor = value;
+}
diff --git a/obj/NiFogProperty.h b/obj/NiFogProperty.h
index c8739742..a3d2160b 100644
--- a/obj/NiFogProperty.h
+++ b/obj/NiFogProperty.h
@@ -27,6 +27,16 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags( ushort n );
+   
+   float GetFogDepth() const;
+   void SetFogDepth(float value);
+
+   Color3 GetFogColor() const;
+   void SetFogColor(Color3 value);
+
 protected:
 	NI_FOG_PROPERTY_MEMBERS
 };
diff --git a/obj/NiObject.h b/obj/NiObject.h
index 65599444..fdcaf84b 100644
--- a/obj/NiObject.h
+++ b/obj/NiObject.h
@@ -171,4 +171,36 @@ template <class T> Ref<const T> DynamicCast( const NiObject * object ) {
 	}
 }
 
+#ifdef USE_NIFLIB_TEMPLATE_HELPERS
+/*!
+ * Dynamically cast from a collection of objects to another collection
+ * \param objs A collection of object references to be dynamically casted to the specified type.
+ * \return A collection of objects that support the requested type.
+ */
+template <typename U, typename T>
+inline vector<Ref<U> > DynamicCast( vector<Ref<T> > const & objs ) {
+   vector<Ref<U> > retval;
+   for (vector<Ref<T> >::const_iterator itr = objs.begin(), end = objs.end(); itr != end; ++itr) {
+      Ref<U> obj = DynamicCast<U>(*itr);
+      if (obj) retval.insert(retval.end(), obj);
+   }
+   return retval;
+}
+
+/*!
+* Dynamically cast from a collection of objects to another collection
+* \param objs A collection of object references to be dynamically casted to the specified type.
+* \return A collection of objects that support the requested type.
+*/
+template <typename U, typename T>
+inline list<Ref<U> > DynamicCast( list<Ref<T> > const & objs ) {
+   list<Ref<U> > retval;
+   for (list<Ref<T> >::const_iterator itr = objs.begin(), end = objs.end(); itr != end; ++itr) {
+      Ref<U> obj = DynamicCast<U>(*itr);
+      if (obj) retval.insert(retval.end(), obj);
+   }
+   return retval;
+}
+#endif
+
 #endif
diff --git a/obj/NiShadeProperty.cpp b/obj/NiShadeProperty.cpp
index f956e013..c9dcb8bc 100644
--- a/obj/NiShadeProperty.cpp
+++ b/obj/NiShadeProperty.cpp
@@ -34,3 +34,10 @@ const Type & NiShadeProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiShadeProperty::GetFlags() const {
+   return flags;
+}
+
+void NiShadeProperty::SetFlags( ushort n ) {
+   flags = n;
+}
diff --git a/obj/NiShadeProperty.h b/obj/NiShadeProperty.h
index e7b974b5..84eb7add 100644
--- a/obj/NiShadeProperty.h
+++ b/obj/NiShadeProperty.h
@@ -28,6 +28,10 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags( ushort n );
+
 protected:
 	NI_SHADE_PROPERTY_MEMBERS
 };
diff --git a/obj/NiSpecularProperty.cpp b/obj/NiSpecularProperty.cpp
index ff7c2a44..7eb32fbf 100644
--- a/obj/NiSpecularProperty.cpp
+++ b/obj/NiSpecularProperty.cpp
@@ -34,3 +34,10 @@ const Type & NiSpecularProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiSpecularProperty::GetFlags() const {
+   return flags;
+}
+
+void NiSpecularProperty::SetFlags( ushort n ) {
+   flags = n;
+}
diff --git a/obj/NiSpecularProperty.h b/obj/NiSpecularProperty.h
index fbb87b29..d87ca8c5 100644
--- a/obj/NiSpecularProperty.h
+++ b/obj/NiSpecularProperty.h
@@ -27,6 +27,10 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags( ushort n );
+
 protected:
 	NI_SPECULAR_PROPERTY_MEMBERS
 };
diff --git a/obj/NiStencilProperty.cpp b/obj/NiStencilProperty.cpp
index 93594578..af97d288 100644
--- a/obj/NiStencilProperty.cpp
+++ b/obj/NiStencilProperty.cpp
@@ -34,3 +34,74 @@ const Type & NiStencilProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiStencilProperty::GetFlags() const {
+   return flags;
+}
+
+void NiStencilProperty::SetFlags(ushort value) {
+   flags = value;
+}
+
+bool NiStencilProperty::GetStencilEnabled() const {
+   return stencilEnabled;
+}
+
+void NiStencilProperty::SetStencilEnabled(bool value) {
+   stencilEnabled = value;
+}
+
+uint NiStencilProperty::GetStencilFunction() const {
+   return stencilFunction;
+}
+
+void NiStencilProperty::SetStencilFunction(uint value) {
+   stencilFunction = value;
+}
+
+uint NiStencilProperty::GetStencilRef() const {
+   return stencilRef;
+}
+
+void NiStencilProperty::SetStencilRef(uint value) {
+   stencilRef = value;
+}
+
+uint NiStencilProperty::GetStencilMask() const {
+   return stencilMask;
+}
+
+void NiStencilProperty::SetStencilMask(uint value) {
+   stencilMask = value;
+}
+
+uint NiStencilProperty::GetFailAction() const {
+   return failAction;
+}
+
+void NiStencilProperty::SetFailAction(uint value) {
+   failAction = value;
+}
+
+uint NiStencilProperty::GetZFailAction() const {
+   return zFailAction;
+}
+
+void NiStencilProperty::SetZFailAction(uint value) {
+   zFailAction = value;
+}
+
+uint NiStencilProperty::GetPassAction() const {
+   return passAction;
+}
+
+void NiStencilProperty::SetPassAction(uint value) {
+   passAction = value;
+}
+
+uint NiStencilProperty::GetDrawMode() const {
+   return drawMode;
+}
+
+void NiStencilProperty::SetDrawMode(uint value) {
+   drawMode = value;
+}
diff --git a/obj/NiStencilProperty.h b/obj/NiStencilProperty.h
index be57453c..ccaace85 100644
--- a/obj/NiStencilProperty.h
+++ b/obj/NiStencilProperty.h
@@ -27,6 +27,35 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags(ushort value);
+
+   bool GetStencilEnabled() const;
+   void SetStencilEnabled(bool value);
+
+   uint GetStencilFunction() const;
+   void SetStencilFunction(uint value);
+
+   uint GetStencilRef() const;
+   void SetStencilRef(uint value);
+
+   uint GetStencilMask() const;
+   void SetStencilMask(uint value);
+
+   uint GetFailAction() const;
+   void SetFailAction(uint value);
+
+   uint GetZFailAction() const;
+   void SetZFailAction(uint value);
+
+   uint GetPassAction() const;
+   void SetPassAction(uint value);
+
+   uint GetDrawMode() const;
+   void SetDrawMode(uint value);
+
+
 protected:
 	NI_STENCIL_PROPERTY_MEMBERS
 };
diff --git a/obj/NiVertexColorProperty.cpp b/obj/NiVertexColorProperty.cpp
index 62fda8d2..2d89b528 100644
--- a/obj/NiVertexColorProperty.cpp
+++ b/obj/NiVertexColorProperty.cpp
@@ -34,3 +34,26 @@ const Type & NiVertexColorProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiVertexColorProperty::GetFlags() const {
+   return flags;
+}
+
+void NiVertexColorProperty::SetFlags(ushort value) {
+   flags = value;
+}
+
+VertMode NiVertexColorProperty::GetVertexMode() const {
+   return vertexMode;
+}
+
+void NiVertexColorProperty::SetVertexMode(VertMode value) {
+   vertexMode = value;
+}
+
+LightMode NiVertexColorProperty::GetLightingMode() const {
+   return lightingMode;
+}
+
+void NiVertexColorProperty::SetLightingMode(LightMode value) {
+   lightingMode = value;
+}
diff --git a/obj/NiVertexColorProperty.h b/obj/NiVertexColorProperty.h
index 82929309..09c8d785 100644
--- a/obj/NiVertexColorProperty.h
+++ b/obj/NiVertexColorProperty.h
@@ -30,6 +30,16 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags(ushort value);
+
+   VertMode GetVertexMode() const;
+   void SetVertexMode(VertMode value);
+
+   LightMode GetLightingMode() const;
+   void SetLightingMode(LightMode value);
+
 protected:
 	NI_VERTEX_COLOR_PROPERTY_MEMBERS
 };
diff --git a/obj/NiWireframeProperty.cpp b/obj/NiWireframeProperty.cpp
index c87a1044..ab865618 100644
--- a/obj/NiWireframeProperty.cpp
+++ b/obj/NiWireframeProperty.cpp
@@ -34,3 +34,11 @@ const Type & NiWireframeProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiWireframeProperty::GetFlags() const {
+   return flags;
+}
+
+void NiWireframeProperty::SetFlags(ushort value) {
+   flags = value;
+}
+
diff --git a/obj/NiWireframeProperty.h b/obj/NiWireframeProperty.h
index 24cddd96..b9eb0db1 100644
--- a/obj/NiWireframeProperty.h
+++ b/obj/NiWireframeProperty.h
@@ -27,6 +27,10 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags( ushort n );
+
 protected:
 	NI_WIREFRAME_PROPERTY_MEMBERS
 };
diff --git a/obj/NiZBufferProperty.cpp b/obj/NiZBufferProperty.cpp
index 30d68868..23324ef5 100644
--- a/obj/NiZBufferProperty.cpp
+++ b/obj/NiZBufferProperty.cpp
@@ -34,3 +34,18 @@ const Type & NiZBufferProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiZBufferProperty::GetFlags() const {
+   return flags;
+}
+
+void NiZBufferProperty::SetFlags(ushort value) {
+   flags = value;
+}
+
+uint NiZBufferProperty::GetFunction() const {
+   return function;
+}
+
+void NiZBufferProperty::SetFunction(uint value) {
+   function = value;
+}
diff --git a/obj/NiZBufferProperty.h b/obj/NiZBufferProperty.h
index 801f6382..5b8c6764 100644
--- a/obj/NiZBufferProperty.h
+++ b/obj/NiZBufferProperty.h
@@ -28,6 +28,13 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+   ushort GetFlags() const;
+   void SetFlags(ushort value);
+
+   uint GetFunction() const;
+   void SetFunction(uint value);
+
 protected:
 	NI_Z_BUFFER_PROPERTY_MEMBERS
 };
-- 
GitLab