home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Animation Class Library / CCL / Core Class Library V1.1c / Headers / Core.h next >
Encoding:
Text File  |  1994-08-06  |  7.8 KB  |  233 lines  |  [TEXT/MPCC]

  1.  
  2. /********************************************
  3.  **** Core Class V1.1 © 1993-94 Yves Schmid & Alia Development
  4.  ****
  5.  **** Core.h
  6.  ****
  7.  **** Authors:        Yves Schmid and Odorico von Susani 
  8.  **** Created:      09 November 1993
  9.  **** Modified:     08 August 1994
  10.  **** Version:      1.1
  11.  **** Compatible:   C++
  12.  ****
  13.  **** Description:  Core is the base class of the Core Class system. A
  14.  ****                class which uses the Core Class facilities must be
  15.  ****                a super class of the Core class.
  16.  ****
  17.  ****                Here follows a description of the fundamental aspects
  18.  ****                of the the Core class:
  19.  ****
  20.  ****                • The Core class defines a heritage level.  The constructor
  21.  ****                of the Core class sets this level to zero. The constructor
  22.  ****                of a superclass must call the "newlevel" method which
  23.  ****                adds one to the heritage level. Then, when all the constructors
  24.  ****                of a class have been called, it is possible to know
  25.  ****                the heritage level of each object. It is used by the
  26.  ****                duplication methods.
  27.  ****
  28.  ****                • A message system which allows every object to receive or send
  29.  ****                commands. A message must be sent with the method "docmd".
  30.  ****                A protected method "sendcmd" is used to send the message
  31.  ****                to other objects linked with the receiver. The method
  32.  ****                "receivecmd" must be used to receive messages. You can
  33.  ****                override this method to intercept messages. See "CoreCmd.h"
  34.  ****                for more informations.
  35.  ****
  36.  ****                • A tracking error system has been implemented in the Core
  37.  ****                class. A variable is reserved in each Core object to keep
  38.  ****                trace of errors. Errors must not be defined by the
  39.  ****                user, they are all predefined in "CoreErrors.h". The constructor
  40.  ****                of the Core class clears the error variable. If the constructor
  41.  ****                of a superclass has a problem, he can add the error to his
  42.  ****                object using the "adderror" method.
  43.  ****                After constructing an object, you must check the
  44.  ****                error flag.
  45.  ****                Some methods in the Core Class system return errors. If a
  46.  ****                method does not return errors, you must not check the error
  47.  ****                flags, because they are not initialised by this kind of method.
  48.  ****                Read the documentation to know if a method returns errors or not.
  49.  ****
  50.  ****                • An object duplication system has been implemented too. Each
  51.  ****                object can easily be duplicated using this system. The Core class
  52.  ****                has a "duplicate" function which must be overrided by
  53.  ****                superclass. When an object is duplicated, the "copyfrom" method
  54.  ****                is called to import the data from the object which must be duplicated.
  55.  ****                To allow a superclass to be duplicated you must override the
  56.  ****                "duplicate" and "copyfrom" methods. The "copyfrom" method uses
  57.  ****                the heritage level of the received object to check if both objects
  58.  ****                are of the same level.
  59.  ****
  60.  ****
  61.  ****                   For example:
  62.  ****
  63.  ****                       class Abc: public Core
  64.  ****                       {
  65.  ****                           int a,b,c;    // A class with three variables
  66.  ****
  67.  ****                           public:
  68.  ****
  69.  ****                           void copyfrom(Core *uo);
  70.  ****                           Core *duplicate(void);
  71.  ****                       };
  72.  ****
  73.  ****                       Core *Abc::duplicate(void)
  74.  ****                       {
  75.  ****                           Abc *abc;
  76.  ****
  77.  ****                           clearerror();   // clear error flags
  78.  ****
  79.  ****                           abc = new Abc;  // Build a new object
  80.  ****
  81.  ****                           if (abc)        // Memory please?
  82.  ****                           {
  83.  ****                               abc->copyfrom(this);    // Copy data to new
  84.  ****                                                       // object
  85.  ****
  86.  ****                               importerror(abc);       // Import error flags
  87.  ****                           }
  88.  ****                           else adderror(CERR_NOMEMORY);   // No memory
  89.  ****
  90.  ****                           return abc; // return duplicated object
  91.  ****                       }
  92.  ****
  93.  ****                       void Abc::copyfrom(Core *uo)
  94.  ****                       {
  95.  ****                           clearerror();   // Clear error flags
  96.  ****
  97.  ****                           Core::copyfrom(uo);      
  98.  ****                                                    // Call the "copyfrom"
  99.  ****                                                    // method of the subclass to
  100.  ****                                                    // copy each level of the object.
  101.  ****                                                    // The last superclass is
  102.  ****                                                    // determined by the heritage
  103.  ****                                                    // level or the "copyfrom"
  104.  ****                                                    // virtual method called.
  105.  ****
  106.  ****
  107.  ****                           if (geterror()) return; // Something went wrong with the subclass.
  108.  ****                                                   // Stop the duplication procedure.
  109.  ****
  110.  ****                           if (uo->getlevel()>=getlevel()) // Check if the
  111.  ****                           {                               // received object has
  112.  ****                                                           // the same level as
  113.  ****                                                           // object.
  114.  ****
  115.  ****                               a=((Abc*)uo)->a;  // Copy data, yeaaa!!!
  116.  ****                               b=((Abc*)uo)->b;
  117.  ****                               c=((Abc*)uo)->c;
  118.  ****                           }
  119.  ****                       }
  120.  ****
  121.  ****
  122.  ****
  123.  ****
  124.  *************************/
  125.  
  126.  
  127. #ifndef Core_H
  128. #define Core_H
  129.  
  130.  
  131. #include "CoreCmd.h"
  132. #include "CoreErrors.h"
  133.  
  134. #include <stdio.h>
  135.  
  136. //.......................................
  137. // Core
  138.  
  139. #ifndef Boolean
  140. #define Boolean unsigned char
  141. #endif
  142.  
  143. #ifndef FALSE
  144. #define FALSE 0
  145. #endif
  146.  
  147. #ifndef TRUE
  148. #define TRUE 1
  149. #endif
  150.  
  151.  
  152. class Core
  153. {
  154.  
  155.     //***********************************************************
  156.     //.............. P U B L I C   M E T H O D S.................
  157.  
  158.     public:
  159.  
  160.     Core(void);
  161.     virtual ~Core(void);    // Destructor must be virtual!
  162.  
  163.  
  164.     inline short getlevel(void) const {return level;}  // Return the heritage level
  165.  
  166.  
  167.     virtual Core *duplicate(void);             // Duplicate this object
  168.     
  169.  
  170.     virtual void docmd(long cmd,
  171.                                short flags=0,
  172.                                void *info=NULL,
  173.                                short t=0,
  174.                                void *parent=NULL); // Send a command
  175.  
  176.  
  177.  
  178.     inline short geterror(void) const {return errorcode;} // Return the error state
  179.  
  180.  
  181.     //***********************************************************
  182.  
  183.  
  184.     protected:
  185.  
  186.     inline void newlevel(void) {level++;}   // A new heritage level, should be called by
  187.                                             // the constructor.
  188.  
  189.  
  190.     inline void clearerror(void) {errorcode = CERR_OK;}     // Clear error state
  191.     void adderror(short a, char *stringinfo =NULL);            // Add a new error
  192.  
  193.     virtual void receivecmd(long cmd, void *info); // The object has received
  194.                                                    // a new command.
  195.  
  196.     // This method import the error state of another object into this object.
  197.     // It is useful when a method works with an other object and
  198.     // you want to merge the result of this work with the result of the
  199.     // method.
  200.  
  201.     inline void importerror(const Core *uo) {errorcode|=uo->geterror();}
  202.  
  203.  
  204.     public:
  205.  
  206.     //..........................................................
  207.     // You should not call the following methods!
  208.  
  209.     virtual void sendcmd(long cmd,
  210.                          short flags=0,
  211.                          void *info=NULL,
  212.                          short t=0,
  213.                          void *parent=NULL); // Send command (only for internal use)
  214.  
  215.  
  216.  
  217.  
  218.     virtual void copyfrom(Core *uo);           // Copy the contents of uo into this object.
  219.                                               // Should only be called in "duplicate".
  220.  
  221.  
  222.     //...........................................................
  223.  
  224.     private:
  225.  
  226.     short level;          // Heritage level of this object
  227.     long  errorcode;      // Error flags
  228.     
  229. };
  230.  
  231.  
  232. #endif
  233.