source: NonGTP/FCollada/FUtils/FUObject.h @ 964

Revision 964, 3.1 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        The idea is simple: the object registers itself in the constructor, with one container.
7        It may register/unregister itself with other containers subsequently.
8
9        It keeps a list of the containers and a pointer to the main container so that the up-classes
10        can easily access it. In the destructor, the object unregisters itself with the container(s).
11
12        The object has a RTTI-like static class structure so that the container(s) know which
13        object type list to remove this object from when it is deleted.
14*/
15
16/**
17        @file FUObject.h
18        This file contains the FUObject class, the FUObjectContainer class and the FUObjectType class.
19*/
20
21#ifndef _FU_OBJECT_H_
22#define _FU_OBJECT_H_
23
24class FUObjectContainer;
25
26#include "FUtils/FUObjectType.h"
27
28/**
29        A contained object.
30        Each object holds a pointer to the container that contains it.
31        This pointer is useful so that the container can be notified if the object
32        gets released by someone else.
33        @ingroup FUtils
34*/
35class FCOLLADA_EXPORT FUObject
36{
37private:
38        FUObjectContainer* container;
39        static class FUObjectType* baseObjectType;
40
41protected:
42        /** Retrieves the container of the object.
43                @return A pointer to the container. */
44        inline FUObjectContainer* GetContainer() { return container; }
45        inline const FUObjectContainer* GetContainer() const { return container; } /**< See above. */
46
47public:
48        /** Constructor.
49                Although it is not an abstract class, class is
50                not meant to be used directly. This constructor
51                informs the container of the object's creation.
52                @param container The container that contains this object. */
53        FUObject(FUObjectContainer* container);
54
55        /** Destructor.
56                This function informs the container of this object's release. */
57        ~FUObject();
58
59        /** Retrieves the type of the base object class.
60                @return The type of the base object class. */
61        static const FUObjectType& GetClassType() { return *baseObjectType; }
62
63        /** Retrieves the type of the object class.
64                @return The type of the base object class. */
65        virtual const FUObjectType& GetObjectType() const { return *baseObjectType; }
66};
67
68/** A dynamically-sized array of contained objects. */
69typedef vector<FUObject*> FUObjectList;
70
71/**
72        An object container
73        Each container holds a list of contained objects.
74        It will release all the objects when it is released and the
75        objects inform it of their creation/destruction.
76        @ingroup FUtils
77*/
78class FCOLLADA_EXPORT FUObjectContainer
79{
80private:
81        friend class FUObject;
82        FUObjectList objects;
83
84        void RegisterObject(FUObject* object);
85        void UnregisterObject(FUObject* object);
86
87public:
88        /** Constructor: empty. */
89        FUObjectContainer() {}
90
91        /** Destructor.
92                Releases all the objects contained within this container. */
93        virtual ~FUObjectContainer();
94
95protected:
96        /** Retrieves the list of objects contained within the container.
97                This list should be accessed for debugging and testing purposes only.
98                @return The list of contained objects. */
99        inline const FUObjectList& GetObjects() const { return objects; }
100};
101
102#endif // _FU_OBJECT_H_
Note: See TracBrowser for help on using the repository browser.