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

Revision 964, 4.8 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/**
7        @file FCDObject.h
8        This file contains the FCDObject and the FCDObjectWithId classes.
9*/
10
11#ifndef __FCD_OBJECT_H_
12#define __FCD_OBJECT_H_
13
14#include "FUtils/FUObject.h"
15#include "FCDocument/FCDocument.h"
16
17/**
18        A basic COLLADA document object.
19       
20        All the objects owned by the COLLADA document derive from this class.
21        The FCDocument object is accessible through this interface to all the object which it owns.
22
23        Space for an handle which has no meaning to FCollada is available in this base class, for our users.
24        You can therefore attach your own objects to most FCollada objects. If you assign memory buffers
25        to the user-specified handle, be aware that FCollada will make no attempt to release it.
26
27        @ingroup FCDocument
28*/
29class FCOLLADA_EXPORT FCDObject : public FUObject
30{
31private:
32        DeclareObjectType;
33
34        // An handle which has no meaning to FCollada but is available for users to
35        // attach objects to most FCollada objects.
36        void* userHandle;
37
38        // Don't use this constructor directly.
39        FCDObject(FUObjectContainer* container);
40
41public:
42        /** Constructor: sets the COLLADA document object.
43                @param document The COLLADA document which owns this object. */
44        FCDObject(FCDocument* document);
45
46        /** Destructor. */
47        virtual ~FCDObject() {}
48
49        /** Retrieves the COLLADA document which owns this object.
50                @return The COLLADA document. */
51        inline FCDocument* GetDocument() { return (FCDocument*) GetContainer(); }
52        inline FCDocument* GetDocument() const { return (FCDocument*) GetContainer(); } /**< See above. */
53
54        /** Retrieves the object's user-specified handle.
55                This handle is available for users and has no
56                meaning to FCollada.
57                @return The object user-specified handle. */
58        inline void* GetUserHandle() const { return userHandle; }
59       
60        /** Sets the object's user-specified handle.
61                This handle is available for users and has no
62                meaning to FCollada.
63                @param handle The user-specified handle. */
64        inline void SetUserHandle(void* handle) { userHandle = handle; }
65};
66
67/**
68        A basic COLLADA object which has a unique COLLADA id.
69       
70        Many COLLADA structures such as entities and sources need a unique COLLADA id.
71        The COLLADA document contains a map of all the COLLADA ids known in its scope.
72        The interface of the FCDObjectWithId class allows for the retrieval and the modification
73        of the unique COLLADA id attached to these objects.
74
75        A unique COLLADA id is built, if none are provided, using the 'baseId' field of the constructor.
76        A unique COLLADA id is generated only on demand.
77
78        @ingroup FCDocument
79*/
80class FCOLLADA_EXPORT FCDObjectWithId : public FCDObject
81{
82private:
83        DeclareObjectType;
84
85        string daeId;
86        bool hasUniqueId;
87
88public:
89        /** Constructor: sets the prefix COLLADA id to be used if no COLLADA id is provided.
90                @param document The COLLADA document which owns this object.
91                @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */
92        FCDObjectWithId(FCDocument* document, const char* baseId = "ObjectWithID");
93
94        /** Destructor. */
95        virtual ~FCDObjectWithId();
96
97        /** Retrieves the unique COLLADA id for this object.
98                If no unique COLLADA id has been previously generated or provided, this function
99                has the side-effect of generating a unique COLLADA id.
100                @return The unique COLLADA id. */
101        const string& GetDaeId() const;
102
103        /** Sets the COLLADA id for this object.
104                There is no guarantee that the given COLLADA id will be used, as it may not be unique.
105                You can call the GetDaeId function after this call to retrieve the final, unique COLLADA id.
106                @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique.
107                        If the COLLADA id is not unique, a new unique COLLADA id will be generated. */
108        void SetDaeId(const string& id);
109
110        /** Sets the COLLADA id for this object.
111                There is no guarantee that the given COLLADA id will be used, as it may not be unique.
112                @param id The wanted COLLADA id for this object. This COLLADA id does not need to be unique.
113                        If the COLLADA id is not unique, a new unique COLLADA id will be generated and
114                        this formal variable will be modified to contain the new COLLADA id. */
115        void SetDaeId(string& id);
116
117        /** [INTERNAL] Release the unique COLLADA id of an object.
118                Use this function wisely, as it leaves the object id-less and without a way to automatically
119                generate a COLLADA id. */
120        void RemoveDaeId();
121
122        /** [INTERNAL] Clones the object. The unique COLLADA id will be copied over to the clone object.
123                Use carefully: when a cloned object with an id is released, it
124                does remove the unique COLLADA id from the unique name map.
125                @param clone The object clone. */
126        void Clone(FCDObjectWithId* clone) const;
127};
128
129#endif // __FCD_OBJECT_H_
Note: See TracBrowser for help on using the repository browser.