source: NonGTP/FCollada/FCDocument/FCDLibrary.hpp @ 964

Revision 964, 2.3 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[964]1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5/*
6        Based on the FS Import classes:
7        Copyright (C) 2005-2006 Feeling Software Inc
8        Copyright (C) 2005-2006 Autodesk Media Entertainment
9        MIT License: http://www.opensource.org/licenses/mit-license.php
10*/
11
12#include "FUtils/FUDaeParser.h"
13
14template <class T>
15FCDLibrary<T>::FCDLibrary(FCDocument* _document)
16{
17        document = _document;
18}
19
20template <class T>
21FCDLibrary<T>::~FCDLibrary()
22{
23        CLEAR_POINTER_VECTOR(entities);
24}
25
26
27// Create a new entity within this library
28template <class T>
29T* FCDLibrary<T>::AddEntity()
30{
31        T* entity = new T(document);
32        entities.push_back(entity);
33        return entity;
34}
35
36// Deletes a entity of this library
37template <class T>
38void FCDLibrary<T>::ReleaseEntity(T* entity)
39{
40        // Not yet implemented, as this will most likely result in dangling pointers!
41        // Needs more structure...
42}
43
44
45// Read in a list of entities for a library of a COLLADA document
46template <class T>
47FUStatus FCDLibrary<T>::LoadFromXML(xmlNode* node)
48{
49        FUStatus status;
50        for (xmlNode* entityNode = node->children; entityNode != NULL; entityNode = entityNode->next)
51        {
52                if (entityNode->type == XML_ELEMENT_NODE)
53                {
54                        T* entity = AddEntity();
55                        status.AppendStatus(entity->LoadFromXML(entityNode));
56                }
57        }
58        return status;
59}
60
61// Write out the library to the COLLADA xml document
62template <class T>
63void FCDLibrary<T>::WriteToXML(xmlNode* node) const
64{
65        for (typename FCDEntityList::const_iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
66        {
67                const T* entity = (const T*) (*itEntity);
68                entity->WriteToXML(node);
69        }
70}
71
72// Search for the entity in this library with a given COLLADA id.
73template <class T>
74T* FCDLibrary<T>::FindDaeId(const string& _daeId)
75{
76        const char* daeId = FUDaeParser::SkipPound(_daeId);
77        for (typename FCDEntityList::iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
78        {
79                if ((*itEntity)->GetDaeId() == daeId) return (*itEntity);
80        }
81        return NULL;
82}
83
84template <class T>
85StringList FCDLibrary<T>::GetPostProcessCmds() const
86{
87        StringList res;
88        for (typename FCDEntityList::const_iterator itEntity = entities.begin(); itEntity != entities.end(); ++itEntity)
89        {
90                res = (*itEntity)->GetPostProcessCmds();
91        }
92        return res;
93}
Note: See TracBrowser for help on using the repository browser.