Very important object notification callbacks

Callback handlers get notified whenever a very important object gets modified.

class vipnotifyObj : public x::eventcallback<vipintvalue>::baseObj {

public:
  vipnotifyObj();
  ~vipnotifyObj() noexcept;

  void event(const vipintvalue &value);
};

By default, x::vipobj uses an event callback list of weak references to a subclass of eventcallback<T>::baseObj. x::vipobj's optional second template parameter overrides the callback type. In either case, the callback class must be a reference-counted object.

class vipnotifyObj : virtual public x::obj {

public:
  vipnotifyObj();
  ~vipnotifyObj() noexcept;

  void event(const vipintvalue &value);
};

typedef x::vipobj<vipintvalue, vipnotifyObj> vip_t;

vip_t vip(2);

This example produces mostly the same results as the first example. When the callback handler gets registered, and whenever the value of the very impotant object's is deemed to have changed, the handler's event() method gets invoked, with the object's value.

It's possible to use a different method named other than event(), or to use separate methods: one method for the initial value of the very important object, at registration time, and another method for all subsequent updates.

This is done by using callback invocation classes, the same way it's done by event callbacks:

class viphandler : virtual public x::obj {

public:
	viphandler();
	~viphandler() noexcept;

	void cbinitial(const vipintvalue &initialvalue);

	void cbupdate(const vipintvalue &updatedvalue);
};

class invoke_initial {

public:
	static void event(const x::ptr<viphandler> &h,
			  const vipintvalue &value)
	{
		h->cbinitial(v);
	}
};

class invoke_update {

public:
	static void event(const x::ptr<viphandler> &h,
			  const vipintvalue &value)
	{
		h->cbupdate(v);
	}
};

typedef x::vipobj<vipintvalue, viphandler, invoke_update, invoke_initial> vip_t;

The optional third parameter to x::vipobj specifies the callback invocation class for updates to the very important object. The fourth parameter specifies the callback invocation class for the initial value of the very important object at the time that the callback handler gets registered, and it defaults to the third template parameter class.

The callback invocation class defines a static event() method that takes a reference to a registered handler object, and a reference to the very important object's value. The above example implements a callback handler whose cbinitial() method gets invoked when the callback handler gets registered, and the cbupdate() method gets invoked when the very important object value gets updated after registration.