view liboctave/singleton-cleanup.h @ 14026:3781981be535 ss-3-5-90

snapshot 3.5.90 * configure.ac (AC_INIT): Version is now 3.5.90. (OCTAVE_API_VERSION_NUMBER): Now 46. (OCTAVE_RELEASE_DATE): Now 2011-12-11.
author John W. Eaton <jwe@octave.org>
date Sun, 11 Dec 2011 23:18:31 -0500
parents b4d399c975de
children
line wrap: on
line source

#if !defined (octave_singleton_cleanup_h)
#define octave_singleton_cleanup_h 1

#include <set>

class
OCTAVE_API
singleton_cleanup_list
{
protected:

  singleton_cleanup_list (void) : fcn_list () { }

public:

  typedef void (*fptr) (void);

  ~singleton_cleanup_list (void);

  static void add (fptr f)
  {
    if (instance_ok ())
      instance->do_add (f);
  }

  static void cleanup (void) { delete instance; instance = 0; }

private:

  static singleton_cleanup_list *instance;

  static bool instance_ok (void);

  static void cleanup_instance (void) { delete instance; instance = 0; }

  std::set<fptr> fcn_list;

  void do_add (fptr f)
  {
    fcn_list.insert (f);
  }

  // No copying!

  singleton_cleanup_list (const singleton_cleanup_list&);

  singleton_cleanup_list& operator = (const singleton_cleanup_list&);
};

#endif