FCDocument/FCDLibrary.hpp

00001 /*
00002     Copyright (C) 2005-2006 Feeling Software Inc.
00003     MIT License: http://www.opensource.org/licenses/mit-license.php
00004 */
00005 /*
00006     Based on the FS Import classes:
00007     Copyright (C) 2005-2006 Feeling Software Inc
00008     Copyright (C) 2005-2006 Autodesk Media Entertainment
00009     MIT License: http://www.opensource.org/licenses/mit-license.php
00010 */
00011 
00012 #include "FUtils/FUDaeParser.h"
00013 
00014 template <class T>
00015 FCDLibrary<T>::FCDLibrary(FCDocument* _document)
00016 {
00017     document = _document;
00018 }
00019 
00020 template <class T>
00021 FCDLibrary<T>::~FCDLibrary()
00022 {
00023     CLEAR_POINTER_VECTOR(entities);
00024 }
00025 
00026 
00027 // Create a new entity within this library
00028 template <class T>
00029 T* FCDLibrary<T>::AddEntity()
00030 {
00031     T* entity = new T(document);
00032     entities.push_back(entity);
00033     return entity;
00034 }
00035 
00036 // Deletes a entity of this library
00037 template <class T>
00038 void FCDLibrary<T>::ReleaseEntity(T* entity)
00039 {
00040     // Not yet implemented, as this will most likely result in dangling pointers!
00041     // Needs more structure...
00042 }
00043 
00044 
00045 // Read in a list of entities for a library of a COLLADA document
00046 template <class T>
00047 FUStatus FCDLibrary<T>::LoadFromXML(xmlNode* node)
00048 {
00049     FUStatus status;
00050     for (xmlNode* entityNode = node->children; entityNode != NULL; entityNode = entityNode->next)
00051     {
00052         if (entityNode->type == XML_ELEMENT_NODE)
00053         {
00054             T* entity = AddEntity();
00055             status.AppendStatus(entity->LoadFromXML(entityNode));
00056         }
00057     }
00058     return status;
00059 }
00060 
00061 // Write out the library to the COLLADA xml document
00062 template <class T>
00063 void FCDLibrary<T>::WriteToXML(xmlNode* node) const
00064 {
00065     for (typename FCDEntityList::const_iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
00066     {
00067         const T* entity = (const T*) (*itEntity);
00068         entity->WriteToXML(node);
00069     }
00070 }
00071 
00072 // Search for the entity in this library with a given COLLADA id.
00073 template <class T>
00074 T* FCDLibrary<T>::FindDaeId(const string& _daeId)
00075 {
00076     const char* daeId = FUDaeParser::SkipPound(_daeId);
00077     for (typename FCDEntityList::iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
00078     {
00079         if ((*itEntity)->GetDaeId() == daeId) return (*itEntity);
00080     }
00081     return NULL;
00082 }
00083 
00084 template <class T>
00085 StringList FCDLibrary<T>::GetPostProcessCmds() const
00086 {
00087     StringList res;
00088     for (typename FCDEntityList::const_iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
00089     {
00090         res = (*itEntity)->GetPostProcessCmds();
00091     }
00092     return res;
00093 }

Generated on Fri May 12 16:44:38 2006 for FCollada by  doxygen 1.4.6-NO