From 1445868e826b8efa632feae51ce77770f510b08f Mon Sep 17 00:00:00 2001 From: Shon Ferguson <shonferg@users.sourceforge.net> Date: Wed, 16 May 2007 08:32:55 +0000 Subject: [PATCH] Removed SWIG-related junk from Niflib and removed any reference to Python in the documentation. Updated user's guide. --- include/Key.h | 3 - include/NIF_IO.h | 188 --------------------------- include/Ref.h | 40 ------ include/dll_export.h | 17 ++- include/gen/AVObject.h | 3 - include/gen/BoundingBox.h | 3 - include/gen/ByteArray.h | 3 - include/gen/ByteColor3.h | 3 - include/gen/ControllerLink.h | 3 - include/gen/Footer.h | 3 - include/gen/FurniturePosition.h | 3 - include/gen/Header.h | 3 - include/gen/LODRange.h | 3 - include/gen/LimitedHingeDescriptor.h | 3 - include/gen/MatchGroup.h | 3 - include/gen/MipMap.h | 3 - include/gen/Morph.h | 3 - include/gen/NodeGroup.h | 3 - include/gen/OblivionColFilter.h | 3 - include/gen/OblivionSubShape.h | 3 - include/gen/Particle.h | 3 - include/gen/QuaternionXYZW.h | 3 - include/gen/RagDollDescriptor.h | 3 - include/gen/ShaderTexDesc.h | 3 - include/gen/SkinData.h | 3 - include/gen/SkinPartition.h | 3 - include/gen/SkinShape.h | 3 - include/gen/SkinShapeGroup.h | 3 - include/gen/SkinWeight.h | 3 - include/gen/Sphere.h | 3 - include/gen/StringPalette.h | 3 - include/gen/TBC.h | 3 - include/gen/TexDesc.h | 3 - include/gen/TexSource.h | 3 - include/gen/hkTriangle.h | 3 - include/gen/obj_defines.h | 5 +- include/nif_math.h | 89 ------------- include/niflib.h | 114 ++++++++-------- include/obj/NiObject.h | 6 - include/obj/NiSkinInstance.h | 2 - 40 files changed, 65 insertions(+), 492 deletions(-) diff --git a/include/Key.h b/include/Key.h index f1506148..27207b06 100644 --- a/include/Key.h +++ b/include/Key.h @@ -21,8 +21,6 @@ struct Key { float continuity; /*!< The amount of continuity to use in tension, bias, continuity interpolation. Ignored if key type is something else.*/ }; -//These operators cause SWIG warnings -#ifndef SWIG template <class T> ostream & operator<<( ostream & out, Key<T> const & val ) { return out << "Time: " << val.time << endl @@ -32,7 +30,6 @@ ostream & operator<<( ostream & out, Key<T> const & val ) { << "Bias: " << val.bias << endl << "Continuity: " << val.continuity << endl; } -#endif } #endif diff --git a/include/NIF_IO.h b/include/NIF_IO.h index ebf5b4c3..83593224 100644 --- a/include/NIF_IO.h +++ b/include/NIF_IO.h @@ -19,194 +19,6 @@ using namespace std; #define NULL 0 #endif -///*! -// * Class overridable alloc/release methods -// * \param T Type of array -// */ -//template<typename T> -//class array_Traits -//{ -//public: -// /*! -// * Default Initialization method. -// * \param v Vector of types to initialize -// * \param length Length in bytes of memory to allocate -// */ -// static void Initialize( T* v, int length ) { -// memset(v, 0, sizeof(v[0]) * length); -// } -// /*! -// * Default Finalization method. -// * \param v Vector of types to initialize -// * \param length Length in bytes of memory to allocate -// */ -// static void Finalize( T* v, int length ) { -// memset(v, 0, sizeof(v[0]) * length); -// } -// /* -// * Default Initialization method. -// * \param s Vector of types to copy from -// * \param d Vector of types to copy to -// * \param length Length in bytes of memory to allocate -// */ -// static void Copy(T const* s, T* d, int length ) { -// for (int i=0; i<length; ++i) -// d[i] = s[i]; -// } -//}; -// -///*! -// * A fixed length array of type T. -// * Data is allocated into a array portion and the data section. -// * The array simply points to appropriate places in the data section. -// * \param T Type of array -// * \param len_ Size of the array. -// */ -//template<size_t len_, typename T> -//class array -//{ -// typedef typename T * RawData; -// typedef typename T const* ConstRawData; -//public: -// /*! -// *Default Constructor. Allocates empty array. -// */ -// array() { -// array_Traits<T>::Initialize(v_, len_); -// } -// -// /*! -// * Copy constructor. -// * \param other The array being copied -// */ -// array(const array& other) { -// array_Traits<T>::Copy(other.v_, v_, len_); -// } -// -// /*! -// * Copy constructor. -// * \param other The array being copied -// */ -// array(const RawData& other) { -// array_Traits<T>::Copy(other, v_, len_); -// } -// -// /*! -// * Copy constructor. -// * \param other The array being copied -// */ -// array(RawData& other) { -// array_Traits<T>::Copy(other, v_, len_); -// } -// -// /*! -// * Default destructor. -// */ -// ~array() { -// array_Traits<T>::Finalize(v_, len_); -// } -// -// //These operators cause SWIG warnings -// #ifndef SWIG -// -// /* -// * Copy assignment. -// * \param The array to assign to this one. -// * \return A reference to this array. -// */ -// array& operator=(const array& other) { -// array tmp( other ); -// swap( tmp ); -// return *this; -// } -// -// /* -// * Copy assignment. -// * \param The array to assign to this one. -// * \return A reference to this array. -// */ -// array& operator=(const ConstRawData& other) { -// array tmp( other ); -// swap( tmp ); -// return *this; -// } -// -// T& operator[](int index) { -// // assert( index >= 0 && index < len_ ) -// return v_[index]; -// } -// -// const T& operator[](int index) const { -// // assert( index >= 0 && index < len_ ) -// return v_[index]; -// } -// -// T& operator[](unsigned int index) { -// // assert( index >= 0 && index < len_ ) -// return v_[index]; -// } -// -// const T& operator[](unsigned int index) const { -// // assert( index >= 0 && index < len_ ) -// return v_[index]; -// } -// -//#endif -// operator T*() const { -// return v_; -// } -// -// /*! Number of items in the vector. */ -// size_t size() const { return len_; } -// size_t count() const { return len_; } -// -// T* begin() { -// return v_; -// } -// -// T* end() { -// return v_ + len_; -// } -// -// const T* begin() const { -// return v_; -// } -// -// const T* end() const { -// return v_ + len_; -// } -// -// /*! -// * Assign an element to array at specified index. -// * \param index Index in array to assign. -// * \param value Value to copy into string. -// */ -// void assign(int index, T value) { -// v_[index] = value; -// } -// -// /*! -// * Resets array back to zero size. -// */ -// void clear() { -// array_Traits<T>::Finalize(v_, len_); -// } -// -// /*! -// * Swap contents with another array. -// * \param other Other vector to swap with -// */ -// void swap( array &other ) { -// array tmp(other); -// array_Traits<T>::Copy(v_, other.v_, len_); -// array_Traits<T>::Copy(tmp.v_, v_, len_); -// } -// -//private: -// -// T v_[len_]; //! Vector data -//}; - /*! Used to enable static arrays to be members of vectors */ template<int size, class T> struct array { diff --git a/include/Ref.h b/include/Ref.h index 48ebab5e..01bb038f 100644 --- a/include/Ref.h +++ b/include/Ref.h @@ -44,20 +44,12 @@ public: bool operator==(const Ref & ref) const; bool operator!=(const Ref & ref) const; - //These operators generate problems in SWIG -#ifndef SWIG friend ostream & operator<< <T>(ostream & os, const Ref & ref); Ref & operator=( T * object ); Ref & operator=( const Ref & ref ); operator T*() const; -#endif T* operator->() const; - //SWIG specific operators - string __str__(); - string __repr__(); - T* __call__() const; - protected: #ifdef USE_NIFLIB_TEMPLATE_HELPERS template<typename U> friend class Ref; @@ -103,9 +95,6 @@ T* Ref<T>::operator->() const { return _object; } -//These operators generate warnings in SWIG -#ifndef SWIG - template <class T> T& Ref<T>::operator*() const { return *_object; @@ -157,7 +146,6 @@ Ref<T> & Ref<T>::operator=( const Ref & ref ) { return *this; } -#endif //Template functions must be in the header file @@ -190,7 +178,6 @@ bool Ref<T>::operator!=(const Ref & ref) const { return ( _object != ref._object ); } -#ifndef SWIG template <class T> ostream & operator<<(ostream & os, const Ref<T> & ref) { if (ref._object) { @@ -200,34 +187,7 @@ ostream & operator<<(ostream & os, const Ref<T> & ref) { } return os; } -#endif -//SWIG functions -template <class T> -string Ref<T>::__str__() { - if (_object) { - return _object->asString(); - } else { - return string("None"); - } } -template <class T> -string Ref<T>::__repr__() { - if (_object) { - return _object->GetIDString(); - } else { - return string("None"); - } -} - -template <class T> -T* Ref<T>::__call__() const { - return _object; -} - - -} - - #endif diff --git a/include/dll_export.h b/include/dll_export.h index 575929ef..d01dd4ec 100644 --- a/include/dll_export.h +++ b/include/dll_export.h @@ -11,29 +11,28 @@ All rights reserved. Please see niflib.h for license. */ # endif #endif -// shared library: expose NIFLIB_API objects, hide NIFLIB_HIDDEN objects + #ifndef NIFLIB_STATIC_LINK - // building swig wrapper - #if defined(SWIG) - #define NIFLIB_API - #define NIFLIB_HIDDEN - // building shared library (windows) - #elif defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) || defined(__CYGWIN__) + // Building shared library + #if defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) || defined(__CYGWIN__) + // Windows #ifdef BUILDING_NIFLIB_DLL + //The building process is underway, export symbols #define NIFLIB_API __declspec(dllexport) #else + //Header files are being used to import symbols from a previously built library #define NIFLIB_API __declspec(dllimport) #endif #define NIFLIB_HIDDEN - // building shared library (linux) #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) + // Linux (GCC) #define NIFLIB_API __attribute__ ((visibility("default"))) #define NIFLIB_HIDDEN __attribute__ ((visibility("hidden"))) #else #error __attribute__ ((visibility("hidden"))) support required, but not detected (see gcc.gnu.org/wiki/Visibility) #endif -// static library: nothing to hide #else + // Building static library #define NIFLIB_API #define NIFLIB_HIDDEN #endif diff --git a/include/gen/AVObject.h b/include/gen/AVObject.h index 75cfe547..17125fc7 100644 --- a/include/gen/AVObject.h +++ b/include/gen/AVObject.h @@ -25,11 +25,8 @@ struct AVObject { NIFLIB_API ~AVObject(); /*! Copy Constructor */ NIFLIB_API AVObject( const AVObject & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API AVObject & operator=( const AVObject & src ); - #endif /*! * Object name. */ diff --git a/include/gen/BoundingBox.h b/include/gen/BoundingBox.h index c37b3d13..85917619 100644 --- a/include/gen/BoundingBox.h +++ b/include/gen/BoundingBox.h @@ -23,11 +23,8 @@ struct BoundingBox { NIFLIB_API ~BoundingBox(); /*! Copy Constructor */ NIFLIB_API BoundingBox( const BoundingBox & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API BoundingBox & operator=( const BoundingBox & src ); - #endif /*! * Usually 1. */ diff --git a/include/gen/ByteArray.h b/include/gen/ByteArray.h index 73ca2286..9d9fc3cc 100644 --- a/include/gen/ByteArray.h +++ b/include/gen/ByteArray.h @@ -23,11 +23,8 @@ struct ByteArray { NIFLIB_API ~ByteArray(); /*! Copy Constructor */ NIFLIB_API ByteArray( const ByteArray & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API ByteArray & operator=( const ByteArray & src ); - #endif /*! * The number of bytes in this array */ diff --git a/include/gen/ByteColor3.h b/include/gen/ByteColor3.h index f4787611..8ef55965 100644 --- a/include/gen/ByteColor3.h +++ b/include/gen/ByteColor3.h @@ -23,11 +23,8 @@ struct ByteColor3 { NIFLIB_API ~ByteColor3(); /*! Copy Constructor */ NIFLIB_API ByteColor3( const ByteColor3 & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API ByteColor3 & operator=( const ByteColor3 & src ); - #endif /*! * Red color component. */ diff --git a/include/gen/ControllerLink.h b/include/gen/ControllerLink.h index a620f922..38a32adc 100644 --- a/include/gen/ControllerLink.h +++ b/include/gen/ControllerLink.h @@ -33,11 +33,8 @@ struct ControllerLink { NIFLIB_API ~ControllerLink(); /*! Copy Constructor */ NIFLIB_API ControllerLink( const ControllerLink & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API ControllerLink & operator=( const ControllerLink & src ); - #endif /*! * Name of a controllable object in another NIF file. */ diff --git a/include/gen/Footer.h b/include/gen/Footer.h index fd1af39b..41201492 100644 --- a/include/gen/Footer.h +++ b/include/gen/Footer.h @@ -28,11 +28,8 @@ struct Footer { NIFLIB_API ~Footer(); /*! Copy Constructor */ NIFLIB_API Footer( const Footer & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API Footer & operator=( const Footer & src ); - #endif /*! * The number of root references. */ diff --git a/include/gen/FurniturePosition.h b/include/gen/FurniturePosition.h index 0d1b4d3d..80c633a3 100644 --- a/include/gen/FurniturePosition.h +++ b/include/gen/FurniturePosition.h @@ -23,11 +23,8 @@ struct FurniturePosition { NIFLIB_API ~FurniturePosition(); /*! Copy Constructor */ NIFLIB_API FurniturePosition( const FurniturePosition & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API FurniturePosition & operator=( const FurniturePosition & src ); - #endif /*! * Offset of furniture marker. */ diff --git a/include/gen/Header.h b/include/gen/Header.h index 1fc59eb4..b1f8fd82 100644 --- a/include/gen/Header.h +++ b/include/gen/Header.h @@ -24,11 +24,8 @@ struct Header { NIFLIB_API ~Header(); /*! Copy Constructor */ NIFLIB_API Header( const Header & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API Header & operator=( const Header & src ); - #endif /*! * 'NetImmerse File Format x.x.x.x' (versions <= 10.0.1.2) or 'Gamebryo * File Format x.x.x.x' (versions >= 10.1.0.0), with x.x.x.x the version diff --git a/include/gen/LODRange.h b/include/gen/LODRange.h index fbc724bb..7fae7120 100644 --- a/include/gen/LODRange.h +++ b/include/gen/LODRange.h @@ -23,11 +23,8 @@ struct LODRange { NIFLIB_API ~LODRange(); /*! Copy Constructor */ NIFLIB_API LODRange( const LODRange & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API LODRange & operator=( const LODRange & src ); - #endif /*! * Begining of range. */ diff --git a/include/gen/LimitedHingeDescriptor.h b/include/gen/LimitedHingeDescriptor.h index 89cae8e0..8da10ab8 100644 --- a/include/gen/LimitedHingeDescriptor.h +++ b/include/gen/LimitedHingeDescriptor.h @@ -23,11 +23,8 @@ struct LimitedHingeDescriptor { NIFLIB_API ~LimitedHingeDescriptor(); /*! Copy Constructor */ NIFLIB_API LimitedHingeDescriptor( const LimitedHingeDescriptor & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API LimitedHingeDescriptor & operator=( const LimitedHingeDescriptor & src ); - #endif /*! * Unknown. */ diff --git a/include/gen/MatchGroup.h b/include/gen/MatchGroup.h index 835b7aa6..0e506046 100644 --- a/include/gen/MatchGroup.h +++ b/include/gen/MatchGroup.h @@ -23,11 +23,8 @@ struct MatchGroup { NIFLIB_API ~MatchGroup(); /*! Copy Constructor */ NIFLIB_API MatchGroup( const MatchGroup & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API MatchGroup & operator=( const MatchGroup & src ); - #endif /*! * Number of vertices in this group. */ diff --git a/include/gen/MipMap.h b/include/gen/MipMap.h index 95d9974c..96b33828 100644 --- a/include/gen/MipMap.h +++ b/include/gen/MipMap.h @@ -23,11 +23,8 @@ struct MipMap { NIFLIB_API ~MipMap(); /*! Copy Constructor */ NIFLIB_API MipMap( const MipMap & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API MipMap & operator=( const MipMap & src ); - #endif /*! * Width of the mipmap image. */ diff --git a/include/gen/Morph.h b/include/gen/Morph.h index d505769c..1ea73205 100644 --- a/include/gen/Morph.h +++ b/include/gen/Morph.h @@ -23,11 +23,8 @@ struct Morph { NIFLIB_API ~Morph(); /*! Copy Constructor */ NIFLIB_API Morph( const Morph & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API Morph & operator=( const Morph & src ); - #endif /*! * Name of the frame. */ diff --git a/include/gen/NodeGroup.h b/include/gen/NodeGroup.h index fa48602b..fcf63bd2 100644 --- a/include/gen/NodeGroup.h +++ b/include/gen/NodeGroup.h @@ -25,11 +25,8 @@ struct NodeGroup { NIFLIB_API ~NodeGroup(); /*! Copy Constructor */ NIFLIB_API NodeGroup( const NodeGroup & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API NodeGroup & operator=( const NodeGroup & src ); - #endif /*! * Number of node references that follow. */ diff --git a/include/gen/OblivionColFilter.h b/include/gen/OblivionColFilter.h index 6d2fdb22..c39c94f5 100644 --- a/include/gen/OblivionColFilter.h +++ b/include/gen/OblivionColFilter.h @@ -23,11 +23,8 @@ struct OblivionColFilter { NIFLIB_API ~OblivionColFilter(); /*! Copy Constructor */ NIFLIB_API OblivionColFilter( const OblivionColFilter & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API OblivionColFilter & operator=( const OblivionColFilter & src ); - #endif /*! * Sets mesh color in Oblivion Construction Set. */ diff --git a/include/gen/OblivionSubShape.h b/include/gen/OblivionSubShape.h index f902bd1c..ab3e5958 100644 --- a/include/gen/OblivionSubShape.h +++ b/include/gen/OblivionSubShape.h @@ -23,11 +23,8 @@ struct OblivionSubShape { NIFLIB_API ~OblivionSubShape(); /*! Copy Constructor */ NIFLIB_API OblivionSubShape( const OblivionSubShape & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API OblivionSubShape & operator=( const OblivionSubShape & src ); - #endif /*! * Sets mesh color in Oblivion Construction Set. */ diff --git a/include/gen/Particle.h b/include/gen/Particle.h index 5ce7f68e..771b5771 100644 --- a/include/gen/Particle.h +++ b/include/gen/Particle.h @@ -23,11 +23,8 @@ struct Particle { NIFLIB_API ~Particle(); /*! Copy Constructor */ NIFLIB_API Particle( const Particle & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API Particle & operator=( const Particle & src ); - #endif /*! * Particle velocity */ diff --git a/include/gen/QuaternionXYZW.h b/include/gen/QuaternionXYZW.h index 865e66cd..113a4e22 100644 --- a/include/gen/QuaternionXYZW.h +++ b/include/gen/QuaternionXYZW.h @@ -23,11 +23,8 @@ struct QuaternionXYZW { NIFLIB_API ~QuaternionXYZW(); /*! Copy Constructor */ NIFLIB_API QuaternionXYZW( const QuaternionXYZW & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API QuaternionXYZW & operator=( const QuaternionXYZW & src ); - #endif /*! * The x-coordinate. */ diff --git a/include/gen/RagDollDescriptor.h b/include/gen/RagDollDescriptor.h index c897b4e7..982336cb 100644 --- a/include/gen/RagDollDescriptor.h +++ b/include/gen/RagDollDescriptor.h @@ -23,11 +23,8 @@ struct RagdollDescriptor { NIFLIB_API ~RagdollDescriptor(); /*! Copy Constructor */ NIFLIB_API RagdollDescriptor( const RagdollDescriptor & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API RagdollDescriptor & operator=( const RagdollDescriptor & src ); - #endif /*! * Unknown. */ diff --git a/include/gen/ShaderTexDesc.h b/include/gen/ShaderTexDesc.h index 17720ee3..dd74ed9e 100644 --- a/include/gen/ShaderTexDesc.h +++ b/include/gen/ShaderTexDesc.h @@ -25,11 +25,8 @@ struct ShaderTexDesc { NIFLIB_API ~ShaderTexDesc(); /*! Copy Constructor */ NIFLIB_API ShaderTexDesc( const ShaderTexDesc & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API ShaderTexDesc & operator=( const ShaderTexDesc & src ); - #endif /*! * Is it used? */ diff --git a/include/gen/SkinData.h b/include/gen/SkinData.h index 74056e84..f76f54b1 100644 --- a/include/gen/SkinData.h +++ b/include/gen/SkinData.h @@ -25,11 +25,8 @@ struct SkinData { NIFLIB_API ~SkinData(); /*! Copy Constructor */ NIFLIB_API SkinData( const SkinData & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API SkinData & operator=( const SkinData & src ); - #endif /*! * Rotation offset of the skin from this bone in bind position. */ diff --git a/include/gen/SkinPartition.h b/include/gen/SkinPartition.h index 8c4d1c8b..08b5d8b4 100644 --- a/include/gen/SkinPartition.h +++ b/include/gen/SkinPartition.h @@ -24,11 +24,8 @@ struct SkinPartition { NIFLIB_API ~SkinPartition(); /*! Copy Constructor */ NIFLIB_API SkinPartition( const SkinPartition & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API SkinPartition & operator=( const SkinPartition & src ); - #endif /*! * Number of vertices in this submesh. */ diff --git a/include/gen/SkinShape.h b/include/gen/SkinShape.h index b54e7c6d..f742a4e2 100644 --- a/include/gen/SkinShape.h +++ b/include/gen/SkinShape.h @@ -28,11 +28,8 @@ struct SkinShape { NIFLIB_API ~SkinShape(); /*! Copy Constructor */ NIFLIB_API SkinShape( const SkinShape & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API SkinShape & operator=( const SkinShape & src ); - #endif /*! * The shape. */ diff --git a/include/gen/SkinShapeGroup.h b/include/gen/SkinShapeGroup.h index 270fa61d..6453241d 100644 --- a/include/gen/SkinShapeGroup.h +++ b/include/gen/SkinShapeGroup.h @@ -25,11 +25,8 @@ struct SkinShapeGroup { NIFLIB_API ~SkinShapeGroup(); /*! Copy Constructor */ NIFLIB_API SkinShapeGroup( const SkinShapeGroup & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API SkinShapeGroup & operator=( const SkinShapeGroup & src ); - #endif /*! * Counts unknown. */ diff --git a/include/gen/SkinWeight.h b/include/gen/SkinWeight.h index 6e0fe536..4f072618 100644 --- a/include/gen/SkinWeight.h +++ b/include/gen/SkinWeight.h @@ -23,11 +23,8 @@ struct SkinWeight { NIFLIB_API ~SkinWeight(); /*! Copy Constructor */ NIFLIB_API SkinWeight( const SkinWeight & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API SkinWeight & operator=( const SkinWeight & src ); - #endif /*! * The vertex index, in the mesh. */ diff --git a/include/gen/Sphere.h b/include/gen/Sphere.h index 564610d4..38014d6c 100644 --- a/include/gen/Sphere.h +++ b/include/gen/Sphere.h @@ -23,11 +23,8 @@ struct Sphere { NIFLIB_API ~Sphere(); /*! Copy Constructor */ NIFLIB_API Sphere( const Sphere & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API Sphere & operator=( const Sphere & src ); - #endif /*! * The sphere's center. */ diff --git a/include/gen/StringPalette.h b/include/gen/StringPalette.h index 77af4921..21067968 100644 --- a/include/gen/StringPalette.h +++ b/include/gen/StringPalette.h @@ -23,11 +23,8 @@ struct StringPalette { NIFLIB_API ~StringPalette(); /*! Copy Constructor */ NIFLIB_API StringPalette( const StringPalette & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API StringPalette & operator=( const StringPalette & src ); - #endif /*! * A bunch of 0x00 seperated strings. */ diff --git a/include/gen/TBC.h b/include/gen/TBC.h index 543c39ec..078aa82f 100644 --- a/include/gen/TBC.h +++ b/include/gen/TBC.h @@ -23,11 +23,8 @@ struct TBC { NIFLIB_API ~TBC(); /*! Copy Constructor */ NIFLIB_API TBC( const TBC & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API TBC & operator=( const TBC & src ); - #endif /*! * Tension. */ diff --git a/include/gen/TexDesc.h b/include/gen/TexDesc.h index a3e437ea..0258ed9d 100644 --- a/include/gen/TexDesc.h +++ b/include/gen/TexDesc.h @@ -27,11 +27,8 @@ struct TexDesc { NIFLIB_API ~TexDesc(); /*! Copy Constructor */ NIFLIB_API TexDesc( const TexDesc & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API TexDesc & operator=( const TexDesc & src ); - #endif /*! * NiSourceTexture object index. */ diff --git a/include/gen/TexSource.h b/include/gen/TexSource.h index 2ebd30b1..ccdabe38 100644 --- a/include/gen/TexSource.h +++ b/include/gen/TexSource.h @@ -28,11 +28,8 @@ struct TexSource { NIFLIB_API ~TexSource(); /*! Copy Constructor */ NIFLIB_API TexSource( const TexSource & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API TexSource & operator=( const TexSource & src ); - #endif /*! * Is the texture external? */ diff --git a/include/gen/hkTriangle.h b/include/gen/hkTriangle.h index 159987ec..9d6cb3b7 100644 --- a/include/gen/hkTriangle.h +++ b/include/gen/hkTriangle.h @@ -23,11 +23,8 @@ struct hkTriangle { NIFLIB_API ~hkTriangle(); /*! Copy Constructor */ NIFLIB_API hkTriangle( const hkTriangle & src ); - //This operator give SWIG problems - #ifndef SWIG /*! Copy Operator */ NIFLIB_API hkTriangle & operator=( const hkTriangle & src ); - #endif /*! * The triangle. */ diff --git a/include/gen/obj_defines.h b/include/gen/obj_defines.h index 1133d719..a8769005 100644 --- a/include/gen/obj_defines.h +++ b/include/gen/obj_defines.h @@ -10,7 +10,6 @@ All rights reserved. Please see niflib.h for license. */ #define MAXARRAYDUMP 20 -#ifndef SWIG #define NI_OBJECT_MEMBERS \ #define A_KEYED_DATA_MEMBERS \ @@ -2344,6 +2343,4 @@ vector< vector<ByteColor3 > > imageData; \ #define ROOT_COLLISION_NODE_CONSTRUCT #define NI_RAW_IMAGE_DATA_PARENT NiObject -#define NI_RAW_IMAGE_DATA_CONSTRUCT : width((unsigned int)0), height((unsigned int)0), unknownInt((unsigned int)0) - -#endif +#define NI_RAW_IMAGE_DATA_CONSTRUCT : width((unsigned int)0), height((unsigned int)0), unknownInt((unsigned int)0) \ No newline at end of file diff --git a/include/nif_math.h b/include/nif_math.h index 954dad3c..5584813f 100644 --- a/include/nif_math.h +++ b/include/nif_math.h @@ -90,8 +90,6 @@ struct NIFLIB_API Triangle { this->v3 = v3; } -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a C++ array. * \param[in] n The index into the data array. Should be 0, 1, or 2. * \return The value at the given array index by reference so it can be read or set via the bracket operator. @@ -112,7 +110,6 @@ struct NIFLIB_API Triangle { default: throw std::out_of_range("Index out of range for Triangle"); }; } -#endif }; /*!Represents a position or direction in 3D space*/ @@ -218,13 +215,10 @@ struct NIFLIB_API Vector3 { */ Vector3 & operator/=( const float & rh ); -//These operators cause SWIG warnings -#ifndef SWIG /* Sets the components of this Vector3 to those of another Vector3 * \return This vector is returned. */ Vector3 & operator=( const Vector3 & v ) { x = v.x; y = v.y; z = v.z; return *this; } -#endif /* Tests the equality of two Vector3 structures. Vectors are considered equal if all * three components are equal. @@ -266,8 +260,6 @@ struct NIFLIB_API Vector3 { struct NIFLIB_API Float2 { float data[2]; /*!< The two floating point numbers stored as an array. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a C++ array. * \param[in] n The index into the data array. Should be 0 or 1. * \return The value at the given array index by reference so it can be read or set via the bracket operator. @@ -278,7 +270,6 @@ struct NIFLIB_API Float2 { float operator[](int n) const { return data[n]; } -#endif /*! Default constructor. */ Float2() {} @@ -300,18 +291,6 @@ struct NIFLIB_API Float2 { data[0] = f1; data[1] = f2; } - - //Python Operator Overloads - float __getitem__(int n) { - if (n > 1 || n < 0) - throw std::out_of_range("Index out of range for MatrixRow3"); - return data[n]; - } - void __setitem__(int n, float value) { - if (n > 1 || n < 0) - throw std::out_of_range("Index out of range for MatrixRow3"); - data[n] = value; - } }; /*! Stores a 2 by 2 matrix used for bump maps. */ @@ -321,8 +300,6 @@ struct Matrix22 { Float2 rows[2]; /*!< The two rows of Float2 structures which hold two floating point numbers each. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a 2x2 C++ array. * \param[in] n The index into the row array. Should be 0 or 1. * \return The Float2 structure for the given row index by reference so it can be read or set via the bracket operator. @@ -333,7 +310,6 @@ struct Matrix22 { NIFLIB_API const Float2 & operator[](int n) const { return rows[n]; } -#endif /*! Default Constructor */ NIFLIB_API Matrix22(); @@ -365,21 +341,12 @@ struct Matrix22 { rows[0][0] = m11; rows[0][1] = m12; rows[1][0] = m21; rows[1][1] = m22; } - - //Python Operator Overloads - NIFLIB_API Float2 & __getitem__(int n) { - if (n > 1 || n < 0) - throw std::out_of_range("Index out of range for MatrixRow3"); - return rows[n]; - } }; /* Stores three floating point numbers. Used as a row of a Matrix33 and to store the data in attr_vector3 and attr_color3 type attributes. */ struct NIFLIB_API Float3 { float data[3]; /*!< The three floating point numbers stored as an array. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a C++ array. * \param[in] n The index into the data array. Should be 0, 1, or 2. * \return The value at the given array index by reference so it can be read or set via the bracket operator. @@ -390,7 +357,6 @@ struct NIFLIB_API Float3 { float operator[](int n) const { return data[n]; } -#endif /*!Default constructor.*/ Float3() {} @@ -416,18 +382,6 @@ struct NIFLIB_API Float3 { data[1] = f2; data[2] = f3; } - - //Python Operator Overloads - float __getitem__(int n) { - if (n > 2 || n < 0) - throw std::out_of_range("Index out of range for Float3"); - return data[n]; - } - void __setitem__(int n, float value) { - if (n > 2 || n < 0) - throw std::out_of_range("Index out of range for Float3"); - data[n] = value; - } }; /*! Stores a 3 by 3 matrix used for rotation. */ @@ -437,8 +391,6 @@ struct Matrix33 { Float3 rows[3]; /*!< The three rows of Float3 structures which hold three floating point numbers each. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a 3x3 C++ array. * \param[in] n The index into the row array. Should be 0, 1, or 2. * \return The Float3 structure for the given row index by reference so it can be read or set via the bracket operator. @@ -449,7 +401,6 @@ struct Matrix33 { NIFLIB_API const Float3 & operator[](int n) const { return rows[n]; } -#endif /*! Default constructor. Initializes matrix to identity. */ NIFLIB_API Matrix33(); @@ -514,13 +465,6 @@ struct Matrix33 { } NIFLIB_API Matrix33 operator*( const Matrix33 & m ) const; - - //Python Operator Overloads - NIFLIB_API Float3 & __getitem__(int n) { - if (n > 2 || n < 0) - throw std::out_of_range("Index out of range for MatrixRow3"); - return rows[n]; - } }; @@ -528,8 +472,6 @@ struct Matrix33 { struct NIFLIB_API Float4 { float data[4]; /*!< The four floating point numbers stored as an array. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a C++ array. * \param[in] n The index into the data array. Should be 0, 1, 2, or 3. * \return The value at the given array index by reference so it can be read or set via the bracket operator. @@ -540,7 +482,6 @@ struct NIFLIB_API Float4 { float operator[](int n) const { return data[n]; } -#endif /*! Default Constructor.*/ Float4() {} @@ -570,18 +511,6 @@ struct NIFLIB_API Float4 { data[3] = f3; data[4] = f4; } - - //Python Operator Overloads - float __getitem__(int n) { - if (n > 3 || n < 0) - throw std::out_of_range("Index out of range for Float4"); - return data[n]; - } - void __setitem__(int n, float value) { - if (n > 3 || n < 0) - throw std::out_of_range("Index out of range for Float4"); - data[n] = value; - } }; /*! Stores a 4 by 4 matrix used for combined transformations. */ @@ -591,8 +520,6 @@ struct Matrix44 { Float4 rows[4]; /*!< The three rows of Float3 structures which hold three floating point numbers each. */ -//These operators cause SWIG warnings -#ifndef SWIG /*! The bracket operator makes it possible to use this structure like a 4x4 C++ array. * \param[in] n The index into the row array. Should be 0, 1, 2, or 3. * \return The Float4 structure for the given row index by reference so it can be read or set via the bracket operator. @@ -603,7 +530,6 @@ struct Matrix44 { NIFLIB_API Float4 const & operator[](int n) const { return rows[n]; } -#endif /*! Default constructor. Initializes Matrix to Identity. */ NIFLIB_API Matrix44(); @@ -729,8 +655,6 @@ struct Matrix44 { */ NIFLIB_API Matrix44 & operator+=( const Matrix44 & rh ); -//These operators cause SWIG warnings -#ifndef SWIG /* Sets the values of this matrix to those of the given matrix. * \param[in] rh The matrix to copy values from. * \return This matrix is returned. @@ -743,7 +667,6 @@ struct Matrix44 { * \return The given ostream is returned. */ NIFLIB_API friend ostream & operator<<( ostream & lh, const Matrix44 & rh ); -#endif /* Compares two 4x4 matricies. They are considered equal if all components are equal. * \param[in] rh The matrix to compare this one with. @@ -801,13 +724,6 @@ struct Matrix44 { // undocumented NIFLIB_API void Decompose( Vector3 & translate, Matrix33 & rotation, float & scale ) const; - - //Python Operator Overloads - NIFLIB_API Float4 & __getitem__(int n) { - if (n > 3 || n < 0) - throw std::out_of_range("Index out of range for Matrix44"); - return rows[n]; - } }; /*! Stores a color along with alpha translucency */ @@ -938,9 +854,6 @@ struct NIFLIB_API Quaternion { //--ostream functions for printing with cout--// -//These operators cause SWIG warnings -#ifndef SWIG - NIFLIB_API ostream & operator<<( ostream & out, TexCoord const & val ); NIFLIB_API ostream & operator<<( ostream & out, Triangle const & val ); NIFLIB_API ostream & operator<<( ostream & out, Vector3 const & val ); @@ -953,7 +866,5 @@ NIFLIB_API ostream & operator<<( ostream & out, Color3 const & val ); NIFLIB_API ostream & operator<<( ostream & out, Color4 const & val ); NIFLIB_API ostream & operator<<( ostream & out, Quaternion const & val ); -#endif - } #endif diff --git a/include/niflib.h b/include/niflib.h index c8decc80..0b130cbc 100644 --- a/include/niflib.h +++ b/include/niflib.h @@ -103,15 +103,6 @@ enum ExportOptions { * cout << "Not a NIF file.\n" << endl; * } * \endcode - * - * <b>In Python:</b> - * \code - * ver = CheckNifVersion("test_in.nif") - * if ( IsSupportedVersion(ver) == false ): - * print "Unsupported." - * elif ( ver == VER_INVALID ): - * print "Not a NIF file." - * \endcode */ NIFLIB_API unsigned int GetNifVersion( string const & file_name ); @@ -263,21 +254,49 @@ NIFLIB_API string FormatVersionString( unsigned version ); \section compile Compiling the Library -Starting with version 0.5, Niflib creates a lib file that is too large to distribute directly, so to use it through C++ you must first compile it. If you need help to do this, there is information about it on our main website here: <a href="http://www.niftools.org/wiki/index.php/Niflib/Compile">Compiling Niflib</a>. +While it is possible to use the pre-compiled DLL file if you are using Microsoft Visual Studio 2005 as your compiler, you may also want to compile it yourself. You may also want to use Niflib on a platform other than Windows, in which case compiling yourself is the only option. -A Python compile of the library will still be available for Windows, but for other platforms you will need to compile the library yourself. +If you need help to do this, there is information about it on our main website here: <a href="http://www.niftools.org/wiki/index.php/Niflib/Compile">Compiling Niflib</a>. \section include Including the Library \subsection cpp C++ -Once you have compiled Niflib, you will have a binary library file which you must reference from your project. If you’re using Visual Studio, you can add it as an “Additional Dependancy” within your project options. You can also include all the source code in your compile process if you do not want to use an intermediate library file. Finally, make sure the path to niflib.h is in your include search paths. +Visual Studio 2005 is the preferred compiler for Niflib as this is the platform that all development is done on. The instructions in this guide assume that you are using this compiler. If you do not have a copy, you can download Microsoft Visual C++ 2005 Express for free from Microsoft. Niflib should work on other compilers, and is tested on GCC from time to time, but you will have to figure out how to use those compilers on your own. + +You need to make some changes to the project settings of your project before you can build a program that uses Niflib. These settings are available when right-clicking the project in the Solution Explorer and clicking “Properties.” You want to use Niflib in Release or Debug mode, or as a static or dynamic library. + +Debug mode means that Visual C++ will put a bunch of extra data in your program to enable you to use the Visual Debugger and see the real code when you set break points or experience a crash. This adds bloat to your program and slows it down, however, so you should always compile in Release mode when you plan on creating the final version for distribution. + +Dynamic linking means that your program will include a Niflib DLL file which the user can replace with a new version so long as the file hasn’t changed too much. It also means that various applications can share one copy of the Niflib code. On the other hand, it also means that you will need to tell your users how to obtain and install the Microsoft Visual Studio 2005 Runtime DLL files from Microsoft. Static linking means that all of the Niflib code that your application uses will be included directly in the EXE file. This also includes the code from the standard C++ library which would otherwise be part of the MSVS 2005 Runtime DLL. This means your EXE will be bigger, but also means that your user won’t have to install any DLL files. + +These are the project settings that you should change to use each combination of Debug/Release and DLL/Static. This assumes that you’ve already created a default empty project with Debug and Release configurations, and are altering those with these additional settings. It also assumes that you’re using the provided Niflib project file to build Niflib, and have added Niflib’s lib and include folders to the proper paths in the Tools > Options screen under Projects and Solutions > VC++ Directories. + +DLL Release: +Configuration Properties > C/C++ > Code Generation = Multi-threaded DLL (/MD) +Configuration Properties > Linker > Additional Dependencies = niflib_dll.lib + +DLL Debug: +Configuration Properties > C/C++ > Code Generation = Multi-threaded Debug DLL (/MDd) +Configuration Properties > Linker > Additional Dependencies = niflib_dll_debug.lib + +Static Release: +Configuration Properties > C/C++ > Code Generation = Multi-threaded (/MT) +Configuration Properties > Preprocessor > Preprocessor Definitions: (Add this to the end of what is already there, separated by semicolons) NIFLIB_STATIC_LINK +Configuration Properties > Linker > Additional Dependencies = niflib_static.lib + +Static Debug: +Configuration Properties > C/C++ > Code Generation = Multi-threaded Debug (/MTd) +Configuration Properties > Preprocessor > Preprocessor Definitions: (Add this to the end of what is already there, separated by semicolons) NIFLIB_STATIC_LINK +Configuration Properties > Linker > Additional Dependencies = niflib_static_debug.lib + +With that out of the way, you can start writing your source code and include the main Niflib header file: \code #include "niflib.h" \endcode -There are now separate include files for each object type in a NIF file. To include the NiNode object, for example, include the obj/NiNode.h file like so: +In addition to the main header file, there are also separate headers for each object type in a NIF file. To include the NiNode object, for example, include the obj/NiNode.h file like so: \code #include "obj/NiNode.h" @@ -285,13 +304,13 @@ There are now separate include files for each object type in a NIF file. To inc You will have one such line in your source code for each NIF object that your program needs access to. -Niflib also wraps all its functions in the "Niflib" namespace. So, depending on your needs, you can either gain access to all Niflib symbols with a using directive like this: +Niflib also wraps all its functions in the "Niflib" namespace. So, depending on your needs, you can either gain access to all Niflib symbols with a using directive that follows the #include statements like this: \code using namespace Niflib; \endcode -Gain access to specific symbols but not others with specific using directives like this: +Or you can gain access to some symbols but not others with specific using directives like this: \code using Niflib::NiNodeRef; @@ -299,33 +318,17 @@ using Niflib::NiObjectRef; using Niflib::ReadNifTree; \endcode -Or simply prepend all of your Niflib symbols with "Niflib::" like this: +Finally, you can simply prepend all of your Niflib symbols with "Niflib::" like this: \code Niflib::NiObjectRef niObj = Niflib::ReadNifTree( "test.nif" ); \endcode -\subsection py Python - -If you are using the pre-compiled version of the Python SWIG wrapper for Windows, you should follow the instructions in the readme file that is included. Briefly, you will place the _niflib.dll and the niflib.py files in your Python 2.4 install location. If you want to compile them yourself you will need to get SWIG 1.3.25 or higher. There there are two build methods, Scons and a Visual Studio 2005 project, provided for this purpose. - -Once you have these files in the proper position in the Python directory, you can use the library in either of the two standard Python ways: - -\code -from niflib import * -\endcode -or -\code -import niflib -\endcode - -To save space, the examples assume that you have used the first method. Of course if you use the second, you will have to preface all function calls with niflib. For example, ReadNifTree() becomes niflib.ReadNifTree(). Currently the Python module includes all NIF objects and is not split into separate modules for each object like the C++ version, so you will only need a single import statement to get everything. - \section exept Exceptions -Niflib uses C++ exceptions rather than error return codes. These are a lot more convenient in that you don’t have to wrap every single function in an if-test, but not everyone understands what they are, so I thought I’d provide enough of an intro to get you along. C++ exceptions should be mapped to Python exceptions transparently, so this only applies to people using the library via C++. +Niflib uses C++ exceptions rather than error return codes. These are a lot more convenient in that you don’t have to wrap every single function in an if-test, but not everyone understands what they are, so I thought I’d provide enough of an intro to get you along. -Very basically, if you want to check if Niflib function calls are failing, and why, wrap them in a try block like this: +Very basically, if you want to check if Niflib function calls are failing and why, then wrap them in a try block like this: \code try { @@ -342,13 +345,13 @@ catch( ... ) { } \endcode -The really nice thing about exceptions is that you can place all of your Niflib calls within one try block, and if any one of them fails, execution will jump to the catch block. The first block will catch any exception thrown explicitly by Niflib, and an error message can be extracted and printed. Other exceptions, such as from bugs in the library or errors it never occurred to us to test for, will go to the second block which is a catch-all statement that will end your program for any other reason. +The really nice thing about exceptions is that you can place all of your Niflib calls within one try block, and if any one of them fails, execution will jump to the catch block and tell you what went wrong. The first catch block will react to any exception thrown explicitly by Niflib, and an error message can be extracted and printed. Other exceptions, such as from bugs in the library or errors it never occurred to us to test for, will go to the second block which is a catch-all statement that will end your program for any other reason. There are ways to recover from exceptions, but this should be enough to allow you to at least exit gracefully if a function signals an error. \section stl_temp STL & Templates -Niflib makes quite a bit of use of the standard template library, and also includes some templates of its own. You should be familiar with the template syntax for defining variables (ex: template<type>) You should also be familiar with at least the following STL built-in types: string, vector, and list. These types map to Python types seamlessly (string, tuple, and tuple respectively), so no understanding of C++ is required for Python users. +Niflib makes extensive use of the standard template library(STL), and also includes some templates of its own. You should be familiar with the template syntax for defining variables (ex: template<type>) You should also be familiar with at least the following STL built-in types: string, vector, and list. //<center>\ref starting_out "Next Section >>>"</center> @@ -362,16 +365,15 @@ Niflib makes quite a bit of use of the standard template library, and also inclu NIF files are the result of the NetImmmerse/Gamebryo engine saving the current state of a scene graph. A scene graph is a tree of 3D transforms that has meshes and rendering instructions attached. Each object is a class which, when the file is saved, writes its contents to disk. So the NIF file is a listing of all the NIF classes, or objects, that are required to recreate a particular scene. -The objects in a NIF file all inherit from the NiObject class and reference eachother in various ways. These relationships are reconstructed when the file is loaded from disk and can then be broken or redirected. The most important structure is formed by the scene graph objects. These objects inherit from the NiAVObject class and form the spacial structure of the scene represented by the NIF file. Each has a 3D transform that is relative to its parent. +The objects in a NIF file all inherit from the NiObject class and reference each other in various ways. These relationships are reconstructed when the file is loaded from disk and can then be broken or redirected by you. The most important structure is formed by the scene graph objects. These objects inherit from the NiAVObject class and form the spatial structure of the scene represented by the NIF file. Each has a 3D transform that is relative to its parent. -Attatched to the NiAVObject classes are various other sorts of objects that either contain the raw data used to render the scene, such as the verticies in NiTriBasedGeomData and the animation keyframes in NiKeyFrameData, or modify the way the scene is drawn in some other way such as objects inheriting from NiProperty and NiExtraData. +Attached to the NiAVObject classes are various other sorts of objects that either contain the raw data used to render the scene, such as the vertices in NiTriBasedGeomData and the animation key frames in NiKeyFrameData, or modify the way the scene is drawn in some other way such as objects inheriting from NiProperty and NiExtraData. Each object type has member functions which allow you to get and set data, adjust linkage to other objects, and some also include functions to perform useful calculations on the data. -You do not access the classes directly, however. Niflib uses reference counting to determine when objects are destroyed, so you always access a class through a Ref smart pointer. This is a template which takes the class as its template argumetn, such as Ref<NiNode>. For each type of Ref a typedef has been provided in the form of [class name]Ref, so Ref<NiNode> has the typedef NiNodeRef, and this name can be used instead of the more unusual template syntax. When the last Ref smart pointer that points to a particular object is reassigned or goes out of scope, that object will take care of cleaning itself up automatically. - -Objects use Ref smart pointers internally as well, so you don’t have to worry about objects that are referenced by other objects destroying themselves unexpectedly. +You do not access the classes directly, however. Niflib uses reference counting to determine when objects are destroyed, so you always access a class through a Ref smart pointer. This is a template which takes the class as its template argument, such as Ref<NiNode>. For each type of Ref a typedef has been provided in the form of [class name]Ref, so Ref<NiNode> has the typedef NiNodeRef, and this name can be used instead of the more unusual template syntax. When the last Ref smart pointer that points to a particular object is reassigned or goes out of scope, that object will take care of cleaning itself up automatically. +Objects use Ref smart pointers internally as well, so you don’t have to worry about objects that are referenced by other objects destroying themselves unexpectedly. Also, any function that takes a pointer to a NIF object, such as “NiObject*” will also take appropriate Ref versions of compatible objects. Compatible objects are those that can be converted to the correct type via a static cast. That is, a derived type can be substituted for a type that it inherits from. \section rw_files Reading and Writing NIF Files @@ -397,17 +399,13 @@ NiNode * node = new NiNode; All NIF objects inherit from NiObject so a good place to start would be understanding the methods of that class. -You can access the member functions of any class through a Ref smart pointer of the right type by using the -> operator. In Python you will need to use the Ref::Ptr() function as an intermediary between a smart reference and the object that it holds, like so: +You can access the member functions of any class through a Ref smart pointer of the right type by using the -> operator, like so: \code -//C++ niNode->GetChildren; - -#Python -niNode.Ptr().GetChildren() \endcode -If you have a Ref of one type, such as a generic NiObjectRef, and you want to know if the object it points to also inherits from the NiNode class, you use the DynamicCast() template function. To cast from a NiObjectRef to a NiNodeRef, you would do the following: +If you have a Ref of one type, such as a generic NiObjectRef, and want to do something with the object that requires it to be the more specialized NiNode type, you use the DynamicCast() template function. To cast from a NiObjectRef to a NiNodeRef, you would do the following: \code NiObjectRef root = ReadNifTree( “test.nif” ); @@ -416,22 +414,22 @@ if ( node != NULL ) { ... \endcode -Note the template syntax of the DynamicCast() function. In Python these tempates are mapped to functions named DynamicCastTo[object type](). For example, DynamicCastToNiNode(). To use them you must use the Ref::Ptr() function as they expect pointers rather than references. For example: +Note the template syntax of the DynamicCast() function. Notice also that you must always check the value returned by DynamicCast(). If the cast is not successful, i.e. the object is not a derived type of the one you’re trying to cast it to, the function will return NULL. -\code -root = ReadNifTree( “test.nif” ); -node = DynamicCastToNiNode( root.Ptr() ); -if root != NULL: - ... -\endcode +Casting down the inheritance tree is usually automatic, but you can also explicitly call the StaticCast() function. -Notice also that you must always check the value returned by DynamicCast(). If the cast is not successful, i.e. the object is not a derived type of the one you’re trying to cast it to, the function will return NULL. +One useful function of all NIF objects is the NiObject::asString() function. You can use it to get an English summary of the contents of that object. You can also call the NiObject::GetIDString() function to get a short readout that includes the memory address, type, and name, if any, of the object. -Casting down the inheritance tree should be automatic in C++, but you can also explicitly call the StaticCast() function. You will need to use this function to cast a Ref to the type expected by some member functions which take Ref arguments. +You will probably also want to know the type of a object at some point. Each NIF object has a static member variable called TYPE which uniquely identifies that type of object. For example, the type constant for NiNode is NiNode::TYPE while the type constant for NiAVObject is NiAVObject::TYPE. These constants should be used instead of the object name string since comparisons between the unique type ID number are much faster than string comparisons, and because these comparisons are aware of inheritance. The type objects also have a function which you can use to get the type name at any time, the Type::GetTypeName() function. -One useful function of all NIF objects is the NiObject::asString() function. You can use it to get an English summary of the contents of that object. You can also call the NiObject::GetIDString() function to get a short readout that includes the memory address, type, and name, if any, of the object. +For example, you may have a program that does something to NiGeometry objects. There are many types of NiGeometry objects in a NIF file, but perhaps for what you’re doing you only need to know whether the object is derived from the NiGeometry type. You can do this without attempting a dynamic cast by using the NiObject:: IsDerivedType () function. For example: -You will probably also want to know the type of a object at some point. You can retrieve this with the NiObject::GetType() function. This returns a reference to the Type value that uniquly identifies this class. You can get its name by calling the Type::GetTypeName() function. +\code +NiObjectRef niObj = new NiTriShapeData; +if ( niObj->IsDerivedType( NiGeometry::TYPE ) ) { + NiGeometryRef niGeom = DynamicCast<NiGeometry>(niObj); + //You can proceed with the assumption that the dynamic cast was successful +\endcode <center>\ref intro_page "<< Previous Section"</center> diff --git a/include/obj/NiObject.h b/include/obj/NiObject.h index 400cedfe..95c14a5c 100644 --- a/include/obj/NiObject.h +++ b/include/obj/NiObject.h @@ -152,12 +152,9 @@ template <class T> Ref<T> StaticCast( NiObject * object ) { return (T*)object; } -//SWIG doesn't want two versions of the same thing -#ifndef SWIG template <class T> Ref<const T> StaticCast (const NiObject * object) { return (const T*)object; } -#endif template <class T> Ref<T> DynamicCast( NiObject * object ) { if ( object && object->IsDerivedType(T::TYPE) ) { @@ -167,8 +164,6 @@ template <class T> Ref<T> DynamicCast( NiObject * object ) { } } -//SWIG doesn't want two versions of the same thing -#ifndef SWIG template <class T> Ref<const T> DynamicCast( const NiObject * object ) { if ( object && object->IsDerivedType(T::TYPE) ) { return (const T*)object; @@ -176,7 +171,6 @@ template <class T> Ref<const T> DynamicCast( const NiObject * object ) { return NULL; } } -#endif #ifdef USE_NIFLIB_TEMPLATE_HELPERS template <typename T, typename U> Ref<T> StaticCast( Ref<U>& object ) { diff --git a/include/obj/NiSkinInstance.h b/include/obj/NiSkinInstance.h index bcf30896..6ac0acbe 100644 --- a/include/obj/NiSkinInstance.h +++ b/include/obj/NiSkinInstance.h @@ -32,9 +32,7 @@ public: * This constructor is called by NiTriBasedGeom when it creates a new skin * instance using the BindSkin function. */ -#ifndef SWIG // for some reason SWIG cannot properly hide this function in NiSkinInstanceRef NIFLIB_HIDDEN NiSkinInstance( NiNode * skeleton_root, vector< Ref<NiNode> > bone_nodes ); -#endif NIFLIB_API ~NiSkinInstance(); //Run-Time Type Information -- GitLab