////////////////////////////////////////////////////////////////////////////////
///////   Copyright 1992, Silicon Graphics, Inc.  All Rights Reserved.   ///////
//                                                                            //
// This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;     //
// the contents of this file may not be disclosed to third parties, copied    //
// or duplicated in any form, in whole or in part, without the prior written  //
// permission of Silicon Graphics, Inc.                                       //
//                                                                            //
// RESTRICTED RIGHTS LEGEND:                                                  //
// Use,duplication or disclosure by the Government is subject to restrictions //
// as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data     //
// and Computer Software clause at DFARS 252.227-7013, and/or in similar or   //
// successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -    //
// rights reserved under the Copyright Laws of the United States.             //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
#ifndef VkCALLBACKLIST_H
#define VkCALLBACKLIST_H

#include <Vk/VkBase.h>
#include <Vk/VkCallbackObject.h>

#if _VK_MAJOR > 1
#include <Vk/VkComponent.h>

class VkCallbackItem : public VkBase {
#else
class VkCallbackItem {
#endif

  friend class VkCallbackList;
  friend class VkCallbackObject;

  public:

    VkCallbackItem(VkCallbackObject *obj, const char *const name, VkCallbackMethod, void * clientData);
    VkCallbackItem(const char *const name, VkCallbackFunction, void *clientData);
#if _VK_MAJOR > 1
    VkCallbackItem(VkCallbackObject *obj, XrmQuark qName, VkCallbackMethod, void * clientData);
    VkCallbackItem(XrmQuark qName, VkCallbackFunction, void *clientData);
    VkCallbackItem(VkCallbackObject *obj, long index, VkCallbackMethod, void * clientData);
    VkCallbackItem(long index, VkCallbackFunction, void *clientData);
#endif
    ~VkCallbackItem();

    void invoke(VkCallbackObject *, const char * const, void *);
#if _VK_MAJOR > 1
    void invoke(VkCallbackObject *, XrmQuark qName, void *);
    void invoke(VkCallbackObject *, long index, void *);
#endif

  private:

    VkCallbackObject   *_obj;
    char               *_name;
#if _VK_MAJOR > 1
    XrmQuark            _quark;
    long                _index;
#endif
    VkCallbackFunction  _func;    
    VkCallbackMethod    _method;
    void               *_clientData;

  private:

    // This class is not intended to be copied.  Strangers will get a
    // compile-time error.  Because there is no implementing code, friends
    // and inadvertant local use will get an ld-time error.  If a copy
    // constructor or operator= is ever needed, simply write them and
    // make these entries public.
    VkCallbackItem(const VkCallbackItem&);
    VkCallbackItem &operator= (const VkCallbackItem&);
};

#if _VK_MAJOR > 1 
class VkCallbackList : public VkBase {
#else
class VkCallbackList {
#endif

 friend class VkCallbackObject;

  public:

  void add(VkCallbackItem *);
  void add(VkCallbackList *);
  void add(const char *const name,  VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void add(const char *const name, VkCallbackFunction, void *clientData);
#if _VK_MAJOR > 1
  void add(XrmQuark qName,  VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void add(XrmQuark qName, VkCallbackFunction, void *clientData);
  void add(long index,  VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void add(long index, VkCallbackFunction, void *clientData);
#endif

  void invoke(VkCallbackObject *, const char *const, void *);
  int hasCallbacks(const char *);
#if _VK_MAJOR > 1
  void invoke(VkCallbackObject *, XrmQuark, void *);
  int hasCallbacks(XrmQuark);

  void invoke(VkCallbackObject *, long, void *);
  int hasCallbacks(long);
#endif

  int size() { return (_numCallbacks);}

  VkCallbackItem *operator[] (int index) const { return (_callbacks[index]); }

  void remove(VkCallbackItem *);
  void remove(const char *const name, VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void remove(VkCallbackObject *obj);
  void remove (const char *const name, VkCallbackFunction, void *clientData);

#if _VK_MAJOR > 1
  void remove(XrmQuark qName, VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void remove (XrmQuark qName, VkCallbackFunction, void *clientData);

  void remove(long index, VkCallbackObject *obj, VkCallbackMethod, void *clientData);
  void remove (long index, VkCallbackFunction, void *clientData);
#endif

  VkCallbackList();
  ~VkCallbackList();

  private:

    VkCallbackItem    **_callbacks;
    int			_numCallbacks;
    inline void		doDelete (int i);

  private:

    // This class is not intended to be copied.  Strangers will get a
    // compile-time error.  Because there is no implementing code, friends
    // and inadvertant local use will get an ld-time error.  If a copy
    // constructor or operator= is ever needed, simply write them and
    // make these entries public.
    VkCallbackList(const VkCallbackList&);
    VkCallbackList &operator= (const VkCallbackList&);
};


#endif
