VuGroupEntity


friend class VuSessionsIterator;
friend class VuSessionEntity;

public:
  // constructors & destructor
  VuGroupEntity(char *groupname);
  VuGroupEntity(VU_BYTE **stream);
  VuGroupEntity(FILE *file);
  virtual ~VuGroupEntity();

  // virtual function interface
  virtual int SaveSize();
  virtual int Save(VU_BYTE **stream);
  virtual int Save(FILE *file);

  char *GroupName()     { return groupName_; }
  ushort MaxSessions()  { return sessionMax_; }
  int SessionCount() { return sessionCollection_->Count(); }

  // setters
  void SetGroupName(char *groupname);
  void SetMaxSessions(ushort max) { sessionMax_ = max; }

  virtual VU_BOOL HasTarget(VU_ID id);
  virtual VU_BOOL InTarget(VU_ID id);
  VU_BOOL SessionInGroup(VuSessionEntity *session);
  virtual VU_ERRCODE AddSession(VuSessionEntity *session);
  VU_ERRCODE AddSession(VU_ID sessionId);
  virtual VU_ERRCODE RemoveSession(VuSessionEntity *session);
  VU_ERRCODE RemoveSession(VU_ID sessionId);

  virtual VU_BOOL IsGroup(); // returns TRUE

  // event Handlers
#ifdef VU_LOW_WARNING_VERSION
  virtual VU_ERRCODE Handle(VuErrorMessage *error);
  virtual VU_ERRCODE Handle(VuPushRequest *msg);
  virtual VU_ERRCODE Handle(VuPullRequest *msg);
  virtual VU_ERRCODE Handle(VuEvent *event);
  virtual VU_ERRCODE Handle(VuFullUpdateEvent *event);
  virtual VU_ERRCODE Handle(VuPositionUpdateEvent *event);
  virtual VU_ERRCODE Handle(VuEntityCollisionEvent *event);
  virtual VU_ERRCODE Handle(VuTransferEvent *event);
  virtual VU_ERRCODE Handle(VuSessionEvent *event);
#else
  virtual VU_ERRCODE Handle(VuSessionEvent *event);
  virtual VU_ERRCODE Handle(VuFullUpdateEvent *event);
#endif VU_LOW_WARNING_VERSION

protected:
  VuGroupEntity(int type, char *groupname, VuFilter *filter=0);
  virtual VU_ERRCODE Distribute(VuSessionEntity *ent);
  virtual VU_ERRCODE InsertionCallback();
  virtual VU_ERRCODE RemovalCallback();

private:
  int LocalSize();                      // returns local bytes written

// DATA
protected:
  char *groupName_;
  ushort sessionMax_;
  VuOrderedList *sessionCollection_;

  // scratch data
  int selfIndex_;
};