singleton-cleanup.h

Go to the documentation of this file.
00001 #if !defined (octave_singleton_cleanup_h)
00002 #define octave_singleton_cleanup_h 1
00003 
00004 #include <set>
00005 
00006 class
00007 OCTAVE_API
00008 singleton_cleanup_list
00009 {
00010 protected:
00011 
00012   singleton_cleanup_list (void) : fcn_list () { }
00013 
00014 public:
00015 
00016   typedef void (*fptr) (void);
00017 
00018   ~singleton_cleanup_list (void);
00019 
00020   static void add (fptr f)
00021   {
00022     if (instance_ok ())
00023       instance->do_add (f);
00024   }
00025 
00026   static void cleanup (void) { delete instance; instance = 0; }
00027 
00028 private:
00029 
00030   static singleton_cleanup_list *instance;
00031 
00032   static bool instance_ok (void);
00033 
00034   static void cleanup_instance (void) { delete instance; instance = 0; }
00035 
00036   std::set<fptr> fcn_list;
00037 
00038   void do_add (fptr f)
00039   {
00040     fcn_list.insert (f);
00041   }
00042 
00043   // No copying!
00044 
00045   singleton_cleanup_list (const singleton_cleanup_list&);
00046 
00047   singleton_cleanup_list& operator = (const singleton_cleanup_list&);
00048 };
00049 
00050 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines