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

Revision 964, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
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/**
13        @file FCDLibrary.h
14        This file contains the FCDLibrary template class.
15        See the FCDLibrary.hpp file for the template implementation.
16*/
17
18#ifndef _FCD_LIBRARY_
19#define _FCD_LIBRARY_
20
21class FCDocument;
22class FCDEntity;
23
24/**
25        A COLLADA library.
26
27        A COLLADA library holds a list of entities. There are libraries for the following entities:
28        animations (FCDAnimation), animation clips (FCDAnimationClip), meshes and splines (FCDGeometry),
29        materials (FCDMaterial), effects (FCDEffect), images (FCDImage), skins and morphers (FCDController),
30        cameras (FCDCamera), lights (FCDLight), physics models (FCDPhysicsModel), physics materials
31        (FCDPhysicsMaterial), physics scenes (FCDPhysicsSceneNode) and visual scenes (FCDSceneNode).
32
33        The COLLADA libraries are contained within the FCDocument object.
34
35        @ingroup FCDocument
36*/     
37template <class T>
38class FCDLibrary
39{
40private:
41        FCDocument* document;
42
43protected:
44        /** The list type for the entities. */
45        typedef vector<T*> FCDEntityList;
46
47        /** Entities list. This list should contain all the root entities of the correct type.
48                Note that the following entity types are tree-based, rather than list-based: FCDAnimation,
49                FCDSceneNode and FCDPhysicsSceneNode. */
50        FCDEntityList entities;
51
52        /** Retrieves the parent document.
53                @return The parent document. */
54        inline FCDocument* GetDocument() { return document; }
55        inline const FCDocument* GetDocument() const { return document; } /**< See above. */
56
57public:
58        /** Constructor: do not use directly.
59                All the necessary libraries are created by the FCDocument object during its creation.
60                @param document The parent document. */
61        FCDLibrary(FCDocument* document);
62
63        /** Destructor: do not use directly.
64                The libraries are released by the FCDocument, just before it is released. */
65        virtual ~FCDLibrary();
66
67        /** Create a new entity within this library.
68                @return The newly created entity. */
69        T* AddEntity();
70
71        /** Releases an entity contained within this library.
72                @param entity The entity to delete. */
73        void ReleaseEntity(T* entity);
74
75        /** Retrieve the library entity with the given COLLADA id.
76                @param daeId The COLLADA id of the entity.
77                @return The library entity which matches the COLLADA id.
78                        This pointer will be NULL if no matching entity was found. */
79        T* FindDaeId(const string& daeId);
80
81        /** Returns whether the library contains no entities.
82                @return Whether the library is empty. */
83        inline bool IsEmpty() const { return entities.empty(); }
84
85        /** [INTERNAL] Reads in the contents of the library from the COLLADA XML document.
86                @param node The COLLADA XML tree node to parse into entities.
87                @return The status of the import. If the status is not successful, it may be dangerous to
88                        extract information from the library. */
89        virtual FUStatus LoadFromXML(xmlNode* node);
90
91        /** [INTERNAL] Writes out the library entities to the COLLADA XML document.
92                @param node The COLLADA XML tree node in which to write the library entities. */
93        virtual void WriteToXML(xmlNode* node) const;
94
95        /** @deprecated [INTERNAL] Retrieves the list of post-processing commands for the entities of this library.
96                @return The list of post-processing commands. */
97        StringList GetPostProcessCmds() const;
98
99        /** Retrieve the number of entities within the library.
100                @return the number of entities contained within the library. */
101        inline size_t GetEntityCount() const { return entities.size(); }
102
103        /** Retrieve an indexed entity from the library.
104                @param index The index of the entity to retrieve.
105                        Should be within the range [0, GetEntityCount()[.
106                @return The indexed entity. */
107        inline T* GetEntity(size_t index) { FUAssert(index < GetEntityCount(), return NULL); return entities.at(index); }
108
109        /** Retrieve an indexed entity from the library.
110                @param index The index of the entity to retrieve.
111                        Should be within the range [0, GetEntityCount()[.
112                @return The indexed entity. */
113        inline const T* GetEntity(size_t index) const { FUAssert(index < GetEntityCount(), return NULL); return entities.at(index); }
114};
115
116#include "FCDocument/FCDLibrary.hpp"
117
118#endif // _FCD_LIBRARY_
Note: See TracBrowser for help on using the repository browser.