home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-06 | 7.8 KB | 233 lines | [TEXT/MPCC] |
-
- /********************************************
- **** Core Class V1.1 © 1993-94 Yves Schmid & Alia Development
- ****
- **** Core.h
- ****
- **** Authors: Yves Schmid and Odorico von Susani
- **** Created: 09 November 1993
- **** Modified: 08 August 1994
- **** Version: 1.1
- **** Compatible: C++
- ****
- **** Description: Core is the base class of the Core Class system. A
- **** class which uses the Core Class facilities must be
- **** a super class of the Core class.
- ****
- **** Here follows a description of the fundamental aspects
- **** of the the Core class:
- ****
- **** • The Core class defines a heritage level. The constructor
- **** of the Core class sets this level to zero. The constructor
- **** of a superclass must call the "newlevel" method which
- **** adds one to the heritage level. Then, when all the constructors
- **** of a class have been called, it is possible to know
- **** the heritage level of each object. It is used by the
- **** duplication methods.
- ****
- **** • A message system which allows every object to receive or send
- **** commands. A message must be sent with the method "docmd".
- **** A protected method "sendcmd" is used to send the message
- **** to other objects linked with the receiver. The method
- **** "receivecmd" must be used to receive messages. You can
- **** override this method to intercept messages. See "CoreCmd.h"
- **** for more informations.
- ****
- **** • A tracking error system has been implemented in the Core
- **** class. A variable is reserved in each Core object to keep
- **** trace of errors. Errors must not be defined by the
- **** user, they are all predefined in "CoreErrors.h". The constructor
- **** of the Core class clears the error variable. If the constructor
- **** of a superclass has a problem, he can add the error to his
- **** object using the "adderror" method.
- **** After constructing an object, you must check the
- **** error flag.
- **** Some methods in the Core Class system return errors. If a
- **** method does not return errors, you must not check the error
- **** flags, because they are not initialised by this kind of method.
- **** Read the documentation to know if a method returns errors or not.
- ****
- **** • An object duplication system has been implemented too. Each
- **** object can easily be duplicated using this system. The Core class
- **** has a "duplicate" function which must be overrided by
- **** superclass. When an object is duplicated, the "copyfrom" method
- **** is called to import the data from the object which must be duplicated.
- **** To allow a superclass to be duplicated you must override the
- **** "duplicate" and "copyfrom" methods. The "copyfrom" method uses
- **** the heritage level of the received object to check if both objects
- **** are of the same level.
- ****
- ****
- **** For example:
- ****
- **** class Abc: public Core
- **** {
- **** int a,b,c; // A class with three variables
- ****
- **** public:
- ****
- **** void copyfrom(Core *uo);
- **** Core *duplicate(void);
- **** };
- ****
- **** Core *Abc::duplicate(void)
- **** {
- **** Abc *abc;
- ****
- **** clearerror(); // clear error flags
- ****
- **** abc = new Abc; // Build a new object
- ****
- **** if (abc) // Memory please?
- **** {
- **** abc->copyfrom(this); // Copy data to new
- **** // object
- ****
- **** importerror(abc); // Import error flags
- **** }
- **** else adderror(CERR_NOMEMORY); // No memory
- ****
- **** return abc; // return duplicated object
- **** }
- ****
- **** void Abc::copyfrom(Core *uo)
- **** {
- **** clearerror(); // Clear error flags
- ****
- **** Core::copyfrom(uo);
- **** // Call the "copyfrom"
- **** // method of the subclass to
- **** // copy each level of the object.
- **** // The last superclass is
- **** // determined by the heritage
- **** // level or the "copyfrom"
- **** // virtual method called.
- ****
- ****
- **** if (geterror()) return; // Something went wrong with the subclass.
- **** // Stop the duplication procedure.
- ****
- **** if (uo->getlevel()>=getlevel()) // Check if the
- **** { // received object has
- **** // the same level as
- **** // object.
- ****
- **** a=((Abc*)uo)->a; // Copy data, yeaaa!!!
- **** b=((Abc*)uo)->b;
- **** c=((Abc*)uo)->c;
- **** }
- **** }
- ****
- ****
- ****
- ****
- *************************/
-
-
- #ifndef Core_H
- #define Core_H
-
-
- #include "CoreCmd.h"
- #include "CoreErrors.h"
-
- #include <stdio.h>
-
- //.......................................
- // Core
-
- #ifndef Boolean
- #define Boolean unsigned char
- #endif
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
-
- class Core
- {
-
- //***********************************************************
- //.............. P U B L I C M E T H O D S.................
-
- public:
-
- Core(void);
- virtual ~Core(void); // Destructor must be virtual!
-
-
- inline short getlevel(void) const {return level;} // Return the heritage level
-
-
- virtual Core *duplicate(void); // Duplicate this object
-
-
- virtual void docmd(long cmd,
- short flags=0,
- void *info=NULL,
- short t=0,
- void *parent=NULL); // Send a command
-
-
-
- inline short geterror(void) const {return errorcode;} // Return the error state
-
-
- //***********************************************************
-
-
- protected:
-
- inline void newlevel(void) {level++;} // A new heritage level, should be called by
- // the constructor.
-
-
- inline void clearerror(void) {errorcode = CERR_OK;} // Clear error state
- void adderror(short a, char *stringinfo =NULL); // Add a new error
-
- virtual void receivecmd(long cmd, void *info); // The object has received
- // a new command.
-
- // This method import the error state of another object into this object.
- // It is useful when a method works with an other object and
- // you want to merge the result of this work with the result of the
- // method.
-
- inline void importerror(const Core *uo) {errorcode|=uo->geterror();}
-
-
- public:
-
- //..........................................................
- // You should not call the following methods!
-
- virtual void sendcmd(long cmd,
- short flags=0,
- void *info=NULL,
- short t=0,
- void *parent=NULL); // Send command (only for internal use)
-
-
-
-
- virtual void copyfrom(Core *uo); // Copy the contents of uo into this object.
- // Should only be called in "duplicate".
-
-
- //...........................................................
-
- private:
-
- short level; // Heritage level of this object
- long errorcode; // Error flags
-
- };
-
-
- #endif
-