From c4b2fd430b4c1d85283bc0eb46e2331d240ec056 Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Sun, 30 Apr 2006 00:20:59 +0000
Subject: [PATCH] Created NifStream and << operators for blk_ref and IBlock *. 
 Special code will need to be generated by the Python to handle reading of
 links.

---
 NIF_Blocks.h |  2 +-
 NIF_IO.cpp   | 44 ++++++++++++++++++++++++++------------------
 NIF_IO.h     | 17 ++++++++++++-----
 3 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/NIF_Blocks.h b/NIF_Blocks.h
index 1957d3a9..ddbbd3e8 100644
--- a/NIF_Blocks.h
+++ b/NIF_Blocks.h
@@ -149,7 +149,7 @@ public:
 		index = new_index;
 	}
 
-	blk_ref GetLink() { return link; }
+	blk_ref GetLink() const { return link; }
 
 
 
diff --git a/NIF_IO.cpp b/NIF_IO.cpp
index e145d6db..15075a77 100644
--- a/NIF_IO.cpp
+++ b/NIF_IO.cpp
@@ -315,6 +315,32 @@ void NifStream( float const & val, ostream& out, uint version ) { WriteFloat( va
 void NifStream( string & val, istream& in, uint version ) { val = ReadString( in ); };
 void NifStream( string const & val, ostream& out, uint version ) { WriteString( val, out ); }
 
+//--Link Types--//
+
+//There is intentionally no function to read directly to blk_ref
+
+void NifStream( blk_ref const & val, ostream& out, uint version ) {
+	if ( val.is_null() == false ) {
+		WriteInt( val->GetBlockNum(), out );
+	} else {
+		WriteInt(-1, out );
+	}
+}
+
+//There is intentionally no function to read directly to IBlock *
+
+void NifStream( IBlock * const & val, ostream& out, uint version ) {
+	if ( val != NULL ) {
+		WriteInt( val->GetBlockNum(), out );
+	} else {
+		WriteInt( -1, out );
+	}
+}
+
+ostream & operator<<( ostream & out, IBlock * const & val ) {
+	return out << blk_ref(val);
+}
+
 //--Structs--//
 
 //HeaderString
@@ -856,24 +882,6 @@ ostream & operator<<( ostream & out, PixelLayout const & val ) {
 	};
 }
 
-//!!!REMOVE THIS LATER!!!//
-void NifStream( IBlock * val, istream& in, uint version ) {
-	int n;
-	in.read( (char*)&n, 4 );
-	val = 0;	// TODO: do something with that n, something like this:
-	//if ( n == -1 )
-	//  val = 0;
-	//else
-	//  val = blk_ref(n);
-	// BUT: block n may not have been processed yet, so we can't return a pointer... ? they will have to be
-	// resolved when calling FixLinks()?
-};
-
-void NifStream( IBlock const * const val, ostream& out, uint version ) {
-	NifStream( val->GetBlockNum(), out, version );
-};
-//!!!REMOVE THIS LATER!!!//
-
 //The HexString function creates a formatted hex display of the given data for use in printing
 //a debug string for information that is not understood
 string HexString( const byte * src, uint len ) {
diff --git a/NIF_IO.h b/NIF_IO.h
index 85c7d881..1f9da5d6 100644
--- a/NIF_IO.h
+++ b/NIF_IO.h
@@ -138,6 +138,18 @@ void NifStream( float const & val, ostream& out, uint version = 0  );
 void NifStream( string & val, istream& in, uint version = 0 );
 void NifStream( string const & val, ostream& out, uint version = 0  );
 
+//--Link Types--//
+
+//blk_ref
+//There is intentionally no function to read directly to blk_ref
+void NifStream( blk_ref const & val, ostream& out, uint version );
+ostream & operator<<( ostream & out, blk_ref const & val );
+
+//IBlock *
+//There is intentionally no function to read directly to IBlock *
+void NifStream( IBlock * const & val, ostream& out, uint version );
+ostream & operator<<( ostream & out, IBlock * const & val );
+
 //--Structs--//
 
 //HeaderString
@@ -269,11 +281,6 @@ void NifStream( PixelLayout & val, istream& in, uint version = 0 );
 void NifStream( PixelLayout const & val, ostream& out, uint version = 0  );
 ostream & operator<<( ostream & out, PixelLayout const & val );
 
-//!!!REMOVE THIS LATER!!!//
-void NifStream( IBlock * val, istream& in, uint version = 0 );
-void NifStream( IBlock const * const val, ostream& out, uint version = 0 );
-//!!!REMOVE THIS LATER!!!//
-
 //--Templates--//
 
 //Key<T>
-- 
GitLab