From f3dac454d0cd82ddcfae2f10ff2f653d2f6af421 Mon Sep 17 00:00:00 2001 From: Amorilia <amorilia@users.sourceforge.net> Date: Wed, 21 Sep 2011 19:47:15 +0100 Subject: [PATCH] Updated public interface in preparation for missing_link_stack support during read. --- include/niflib.h | 16 ++++++++++++++++ src/niflib.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/niflib.h b/include/niflib.h index ce5e87ee..f2335433 100644 --- a/include/niflib.h +++ b/include/niflib.h @@ -107,6 +107,22 @@ enum ExportOptions { */ NIFLIB_API unsigned int GetNifVersion( string const & file_name ); +/*! + * Return the missing link stack with objects replaced from nif trees at specified roots. + */ +NIFLIB_API list<Ref<NiObject> > ProcessMissingLinkStack( + list<Ref<NiObject> > const & roots, + const list<NiObject *> & missing_link_stack); + +/*! + * Reads the given input stream and returns a vector of object references + * \param in The input stream to read NIF data from. + * \param missing_link_stack A stack where to copy NULL refs from (in case of reading a nif from an incomplete nif tree) + * \param info Optionally, a NifInfo structure pointer can be passed in, and it will be filled with information from the header of the NIF file. + * \return All the NIF objects read from the stream. + */ +NIFLIB_API vector<Ref<NiObject> > ReadNifList( istream & in, const list<Ref<NiObject> > & missing_link_stack, NifInfo * info ); + /*! * Reads the given file by file name and returns a vector of object references * \param file_name The name of the file to load, or the complete path if it is not in the working directory. diff --git a/src/niflib.cpp b/src/niflib.cpp index 60231eed..03355192 100644 --- a/src/niflib.cpp +++ b/src/niflib.cpp @@ -119,6 +119,11 @@ vector<NiObjectRef> ReadNifList( string const & file_name, NifInfo * info ) { } vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) { + list<NiObjectRef> missing_link_stack; + return ReadNifList(in, missing_link_stack, info); +} + +vector<NiObjectRef> ReadNifList( istream & in, const list<NiObjectRef> & missing_link_stack, NifInfo * info ) { //Ensure that objects are registered if ( g_objects_registered == false ) { @@ -397,6 +402,32 @@ vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) { return obj_list; } +NiObjectRef _ProcessMissingLinkStackHelper(NiObjectRef root, NiObject *obj) { + // search by name + NiNodeRef rootnode = DynamicCast<NiNode>(root); + NiNodeRef objnode = DynamicCast<NiNode>(obj); + if (rootnode != NULL && objnode != NULL) { + if (!(rootnode->GetName().empty()) && rootnode->GetName() == objnode->GetName()) { + return StaticCast<NiObject>(rootnode); + } + } + // nothing found + return NiObjectRef(); +} + +list<NiObjectRef> ProcessMissingLinkStack( + list<NiObjectRef> const & roots, + const list<NiObject *> & missing_link_stack) +{ + list<NiObjectRef> result; + for (list<NiObject *>::const_iterator obj = missing_link_stack.begin(); obj != missing_link_stack.end(); ++obj) { + for (list<NiObjectRef>::const_iterator root = roots.begin(); root != roots.end(); ++root) { + result.push_back(_ProcessMissingLinkStackHelper(*root, *obj)); + } + } + return result; +} + // Writes a valid Nif File given an ostream, a list to the root objects of a file tree // (missing_link_stack stores a stack of links which are referred to but which // are not inside the tree rooted by roots) -- GitLab