Sha256: 87f267f11d3e950acb0bb3f7006e3af3d3f50f30869ba6e9b7325949adeb7715

Contents?: true

Size: 1.84 KB

Versions: 16

Compression:

Stored size: 1.84 KB

Contents

// Copyright (c) 2023 M.J.N. Corino, The Netherlands
//
// This software is released under the MIT license.

/*
 * WxRuby3 persistence classes
 */

#ifndef _WXRUBY_PERSISTENCE_HASH_H
#define _WXRUBY_PERSISTENCE_HASH_H

#include <wx/persist.h>
#include <wx/config.h>

#include <map>

/*
  This class serves as a base for any Ruby defined persistence manager in order to provide
  customized save and restore methods for Ruby values but also as a replacement for the
  default global persistence manager instance.
 */
class WxRubyPersistenceManager : public wxPersistenceManager
{
private:
  typedef std::map<VALUE, VALUE> rb_object_to_rb_po_map_t;
  rb_object_to_rb_po_map_t rb_object_po_map_;

public:
  WxRubyPersistenceManager() : wxPersistenceManager() {}

  bool SaveRubyValue(const wxPersistentObject& who, const wxString& name, VALUE value);

  VALUE RestoreRubyValue(const wxPersistentObject& who, const wxString& name);


  bool DoSaveRubyValue(const wxPersistentObject& who, const wxString& name, VALUE value);

  VALUE DoRestoreRubyValue(const wxPersistentObject& who, const wxString& name);

  void RegisterRbPO(VALUE rb_obj, VALUE rb_po)
  {
    rb_object_po_map_[rb_obj] = rb_po;
  }

  VALUE FindRbPO(VALUE rb_obj)
  {
    VALUE rb_po = Qnil;
    if (rb_object_po_map_.count(rb_obj) > 0)
    {
      rb_po = rb_object_po_map_[rb_obj];
    }
    return rb_po;
  }

  VALUE UnregisterRbPO(VALUE rb_obj)
  {
    VALUE rb_po = Qnil;
    if (rb_object_po_map_.count(rb_obj) > 0)
    {
      rb_po = rb_object_po_map_[rb_obj];
      rb_object_po_map_.erase(rb_obj);
    }
    return rb_po;
  }

  void GC_markPO();

  static void UnregisterPersistentObject(VALUE rb_obj);
};

class WxRubyPersistentObject : public wxPersistentObject
{
public:
  virtual ~WxRubyPersistentObject();
protected:
  WxRubyPersistentObject(VALUE rb_obj);
};

#endif /* _WXRUBY_PERSISTENCE_HASH_H */

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wxruby3-1.5.0 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.4.2 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.4.1 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.4.0 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.3.1 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.3.0 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.2.1 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.2.0 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.1.2 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.1.1 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.1.0 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-1.0.1 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-0.9.8 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-0.9.7 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-0.9.5 ext/wxruby3/include/wxruby-Persistence.h
wxruby3-0.9.4 ext/wxruby3/include/wxruby-Persistence.h