1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2009 Sam Hocevar <sam@hocevar.net>
5  *               2009 Mathew Eis (kingrobot)
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #ifndef     __FTCleanup__
28 #define     __FTCleanup__
29 
30 #include <set>
31 
32 #include "FTFace.h"
33 
34 /**
35  * A dummy object type for items to be stored in the cleanup list
36  */
37 typedef void* FTCleanupObject;
38 
39 /**
40  * FTCleanup is used as a "callback" by FTLibrary to
41  * make sure things are cleaned up in the right order
42  */
43 class FTCleanup
44 {
45     protected:
46 
47         /**
48          * singleton instance
49          */
50         static FTCleanup* _instance;
51 
52         /**
53          * Constructors
54          */
55          FTCleanup();
56 
57         /**
58          * Destructor
59          */
60          ~FTCleanup();
61 
62     public:
63 
64         /**
65          * Generate the instance if necessary and return it
66          *
67          * @return The FTCleanup instance
68          */
Instance()69         static FTCleanup* Instance()
70         {
71             if (FTCleanup::_instance == 0)
72                 FTCleanup::_instance = new FTCleanup;
73             return FTCleanup::_instance;
74         }
75 
76         /**
77         * Destroy the FTCleanup instance
78         */
DestroyAll()79         static void DestroyAll()
80         {
81             delete FTCleanup::_instance;
82         }
83 
84         /**
85          * Add an FT_Face to the cleanup list
86          *
87          * @param obj The reference to the FT_Face to be deleted on cleanup
88          */
89         void RegisterObject(FT_Face **obj);
90 
91         /**
92          * Remove an FT_Face from the cleanup list
93          *
94          * @param obj The reference to the FT_Face to be removed from the list
95          */
96         void UnregisterObject(FT_Face **obj);
97 
98     private:
99 
100         std::set<FT_Face **> cleanupFT_FaceItems;
101 };
102 
103 #endif  //  __FTCleanup__
104 
105