home *** CD-ROM | disk | FTP | other *** search
-
- /********************************************
- **** Core Class V1.1 © 1993-94 Yves Schmid & Alia Development
- ****
- **** CoreHead.h
- ****
- **** Authors: Yves Schmid and Odorico von Susani
- **** Created: 15 November 1993
- **** Modified: 08 August 1994
- **** Compatible: C++
- **** Version: 1.1
- **** Description: CoreHead is the most advanced class of the Core Class package. Basically,
- **** a CoreHead is a CoreNode with various CoreLists under its control.
- **** CoreHead allows you to build complex tree structures. CoreLists under
- **** the control of a CoreHead are called entries.
- ****
- ****
- **** For example:
- ****
- ****
- **** |-CoreHead...
- **** |-CoreHead.entry0---|-CoreHead...
- **** CoreHead.entry0-----|-CoreHead...
- **** |-CoreHead...
- ****
- **** .entry1-----|-CoreHead...
- **** .entry2...
- ****
- ****
- ****
- **** A CoreHead may have as many entries as the user want (and the memory can).
- **** Each CoreHead has only one entry for a simple tree structure . If
- **** you want that a CoreHead controls different kind of data, you may
- **** want to create more than one entry. For example you can have
- **** an object which controls a list of picture, a list of sound, etc...
- ****
- **** A CoreHead with other CoreHeads under its control is called
- **** a supervisor. Each CoreHead has a pointer on his supervisor (or
- **** NULL if there is no supervisor).
- ****
- **** When you create a CoreHead you define his number of entries.
- **** Default is zero entry. If a CoreHead does not have objects under
- **** its control, it does not need entries.
- ****
- **** It is possible to place a simple CoreNode under the control
- **** of a CoreHead. However it is not very flexible because
- **** a CoreNode is not smart enough to know who its supervisor is.
- **** It means that messages cannot follow an ascendant tree. When
- **** they meet a CoreNode they are stopped.
- ****
- **** Commands may be sent in a complexe CoreHead structure. There
- **** is a flag called "CCF_EVERYWHERE" which allows you to send a command
- **** to every CoreHead in the structure from everywhere. Each CoreHead
- **** will only receive the message once! See "CoreCmd.h" to
- **** learn more about flags.
- ****
- **** You can change the supervisor of a CoreHead with
- **** the "setsupervisor" method. This method allows you to specify a pointer
- **** on the new supervisor and the entry which will receive the object.
- **** You can pass NULL to unlink your CoreHead.
- ****
- **** It is legal to add a CoreHead to a simple CoreList (not to a CoreHead) with
- **** the "setlist" method. However your object will not have a
- **** supervisor, because a CoreList is not smart enough to be a
- **** supervisor.
- ****
- **** When you duplicate a CoreHead, all object under its control in
- **** all entries are duplicated too. The duplicated CoreHead is linked
- **** to the same entry as the orignal CoreHead. Use "remove" to
- **** unlink the object.
- ****
- **** The CoreHead destructor unlinks the object from his supevisor and
- **** deletes all the objects under its control. You can delete a complexe
- **** CoreHead structure with a single call like "delete baseCoreHead".
- ****
- ****
- ****
- *************************/
-
-
- #ifndef CoreHead_H
- #define CoreHead_H
-
- #include "Core.h"
- #include "CoreNode.h"
- #include "CoreList.h"
-
-
-
- class CoreConnection;
-
- //.......................................
- // CoreHead
-
- class CoreHead: public CoreNode
- {
-
- //***********************************************************
- //.............. P U B L I C M E T H O D S.................
-
- public:
-
- CoreHead(long nentry=0); // Object unlinked
- CoreHead(CoreList *, long nentry); // Object linked to a CoreList
- CoreHead(CoreHead *, long headentry,long nentry=0); // Object under control of a CoreHead
-
-
- virtual ~CoreHead(void); // Delete all entries, sub coreheads,...
-
-
- virtual void setlist(CoreList *a); // Link to a list
- virtual void setsupervisor(CoreHead *a, long headentry=0); // Place under control of a CoreHead
-
- virtual void setsupervisor(CoreHead *a,
- long headentry,
- long listposition); // Places under control of a CoreHead "a".
- // "listposition" allows you to specify
- // an offset in the destination list.
- // Use this method to move a
- // CoreHead to a new position in its
- // list.
-
- virtual void setsamesupervisoras(CoreHead *a, Boolean insertbefore =FALSE);
- // Places under the same supervisor of the
- // CoreHead "a". If "insertbefore" is TRUE
- // object is inserted before the CoreHead "a"
- // else it is inserted after.
-
- virtual void setnentry(long nentry); // Change number of entries
-
-
- inline CoreHead *getsupervisor(void) const {return supervisor;}
- inline long getnentry(void) const {return nentry;}
- inline CoreList *getentry(long entry=0) const {if (entry<nentry) return entrytab[entry];
- else return NULL;}
-
-
-
- virtual void remove(void); // Remove this object from its list and/or its
- // supervisor.
-
- virtual Core *duplicate(void); // Duplicate. If this object has a list, the
- // duplicated object is linked to the same
- // list. Use "remove" if you want to unlink
- // the duplicated object.
-
- virtual long addentry(void); // Add a new entry.
-
- virtual void flushentry(const long entry =0); // Delete all the nodes linked to the
- // specified entry.
-
- // If you do not want to specify an entry number directly, you
- // can use the two following methods. These methods allow you to allocate
- // and free entries without having to specify an entry number. When you
- // want a new entry you call "allocentry" which returns the number of
- // the new entry. You can work with this value without having to know
- // entry position. When you don't need an entry anymore, simply
- // call "freeentry" with the value returned by "allocentry". Be sure to
- // never use a deleted entry. Note that you don't have to free entries
- // before deleting the CoreHead. CoreHead is smart enough to delete all
- // entries within his destructor.
-
- virtual long allocentry(void); // Alloc a new entry, search the best entry position
- virtual void freeentry(long entry); // Free an entry allocated by "allocentry"
-
-
- virtual void docmd(long cmd,
- short flags=0,
- void *info=NULL,
- short t=0,
- void *parent=NULL); // Send a command
-
-
- //.....................
- // CCL version 1.1, connection system
-
- virtual void connectto(CoreHead *head, long connectionID =0);
- virtual void deconnect(CoreHead *head);
-
- virtual CoreHead *getconnection(long p =0);
- virtual CoreHead *getconnection_by_id(long connectionID);
- inline long getnconnections(void) {return connections_list->getlength();}
-
- virtual void setconnection_id(CoreHead *head, long connectionID);
- virtual long getconnection_id(CoreHead *head);
-
- virtual void deconnectall(); // Deletes all of its connections
- virtual void deconnect_from_watchers(); // Deletes all watchers connections which
- // are connected to this object
-
- Boolean isconnectedto(CoreHead *head);
-
- virtual CoreHead *getwatcher(long p =0);
- inline long getnwatchers(void) {return connectwatchers_list->getlength();}
-
-
- //***********************************************************
-
-
- protected:
-
- virtual CoreList *newentry(void); // Alloc a new entry. You can override
- // this method if you want CoreHead to
- // build a superclass of CoreList.
-
- virtual void receivecmd(long cmd, void *info);
-
-
- public:
-
- //..........................................................
- // You should not call the following methods!
-
- inline CoreList *getconnections_list(void) {return connections_list;}
- inline CoreList *getconnectwatchers_list(void) {return connectwatchers_list;}
-
- virtual void copyfrom(Core *uo); // The magic duplication system (see core.h)
- virtual void sendcmd(long cmd, short flags, void *info, short t, void *parent=NULL);
- // (Don't call this method, use docmd instead. Only for internal use).
-
- //..........................................................
-
-
- private:
-
- CoreHead *supervisor; // Its supervisor or NULL
-
- CoreList **entrytab; // Objects under control, entries tab
- long nentry; // Number of entries
-
- CoreList *connections_list;
- CoreList *connectwatchers_list;
- Boolean connectalreadypassed;
- };
-
- //.................................................................
- // When you receive a CCMD_CONNECTIONDELETED and CCMD_WATCHERDELETED message,
- // the "info" field points on the following structure:
-
- struct ConnectionDeletedInfo
- {
- CoreHead *deletedobject; // The deleted object (don't try to use it)
- long connectionID; // ID of the connection
- Boolean deletemyself; // If TRUE the receiver will be deleted (default FALSE)
- };
-
- #endif
-
-