home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / ObjectTcl-1.1 / OtclClass.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  9.8 KB  |  288 lines

  1. #ifndef OTCL_CLASS_H
  2. #define OTCL_CLASS_H
  3.  
  4. /*  _ __ ___ _
  5.  * | |\ /  /| |  $Id: OtclClass.H,v 1.6 1995/05/09 16:14:26 deans Exp $
  6.  * | | /  / | |  Copyright (C) 1995 IXI Limited.
  7.  * |_|/__/_\|_|  IXI Limited, Cambridge, England.
  8.  *
  9.  * Component   : OtclClass.H
  10.  *
  11.  * Author      : Dean Sheehan (deans@x.co.uk)
  12.  *  
  13.  * Description : Header file for OtclClass class that modells classes of
  14.  *               objects in Object Tcl.
  15.  *
  16.  * License     :
  17.             Object Tcl License & Copyright
  18.             -----------------------------
  19.  
  20. IXI Object Tcl software, both binary and source (hereafter, Software) is copyrighted by IXI Limited (IXI), and ownership remains with IXI. 
  21.  
  22. IXI grants you (herafter, Licensee) a license to use the Software for academic, research and internal business purposes only, without a fee. Licensee may distribute the binary and source code (if required) to third parties provided that the copyright notice and this statement appears on all copies and that no charge is associated with such copies. 
  23.  
  24. Licensee may make derivative works. However, if Licensee distributes any derivative work based on or derived from the Software, then Licensee will (1) notify IXI regarding its distribution of the derivative work, and (2) clearly notify users that such derivative work is a modified version and not the original IXI Object Tcl distributed by IXI. IXI strongly recommends that Licensee provide IXI the right to incorporate such modifications into future releases of the Software under these license terms. 
  25.  
  26. Any Licensee wishing to make commercial use of the Software should contact IXI, to negotiate an appropriate license for such commercial use. Commercial use includes (1) integration of all or part of the source code into a product for sale or license by or on behalf of Licensee to third parties, or (2) distribution of the binary code or source code to third parties that need it to utilize a commercial product sold or licensed by or on behalf of Licensee. 
  27.  
  28. IXI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. IXI SHALL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER SUFFERED BY THE USERS OF THIS SOFTWARE. 
  29.  
  30. Copyright (C) 1995, IXI Limited 
  31.  
  32. By using or copying this Software, Licensee agrees to abide by the copyright law and all other applicable laws of England and the U.S., including, but not limited to, export control laws, and the terms of this license. IXI shall have the right to terminate this license immediately by written notice upon Licensee's breach of, or non-compliance with, any of its terms. Licensee may be held legally responsible for any copyright infringement that is caused or encouraged by Licensee's failure to abide by the terms of this license. 
  33.  
  34. Comments and questions are welcome and can be sent to
  35. otcl@x.co.uk 
  36.  
  37. For more information on copyright and licensing issues, contact: 
  38. Legal Department, IXI Limited, Vision Park, Cambridge CB4 4ZR,
  39. ENGLAND. 
  40.  
  41.  *
  42.  */
  43.  
  44. // Tcl Includes
  45. #include <tcl.h>
  46.  
  47. // Local Includes
  48. #include "Otcl.H"
  49.  
  50. // Public Defines
  51. #define MAX_SUPERCLASSES 3
  52. #define OTCL_CLASS_VARIABLE_NAME "_otcl_class_"
  53.  
  54. // Command Name Defines
  55. #define INSTANCE_METHOD_INTERFACE_CMD      "method"
  56. #define CLASS_METHOD_INTERFACE_CMD         "classMethod"
  57. #define CONSTRUCTOR_INTERFACE_CMD          "constructor"
  58. #define INSTANCE_METHOD_IMPLEMENTATION_CMD "method"
  59. #define CLASS_METHOD_IMPLEMENTATION_CMD    "classMethod"
  60. #define INSTANCE_ATTRIBUTE_CMD             "attribute"
  61. #define CLASS_ATTRIBUTE_CMD                "classAttribute"
  62. #define CONSTRUCTOR_IMPLEMENTATION_CMD     "constructor"
  63. #define DESTRUCTOR_IMPLEMENTATION_CMD      "destructor"
  64.  
  65. // Forward Class Declaration
  66. class OtclConstructorMethod;
  67. class OtclDestructorMethod;
  68. class OtclInstanceMethod;
  69. class OtclObject;
  70. class OtclPart;
  71. class OtclObjMgr;
  72.  
  73. // Class    : OtclClass
  74. // Synopsis : An abstract class to hold Otcl class declarations
  75. class OtclClass
  76. {
  77. public:   // Public Constructor & Destructor
  78.  
  79.    OtclClass (char *name);
  80.  
  81.    virtual ~OtclClass ();
  82.  
  83. public:   // Public Instance Methods
  84.  
  85.    virtual int shouldDelete (void) = 0;
  86.  
  87.    virtual int isComplete (void) = 0;
  88.  
  89.    char *giveName (void);
  90.  
  91.    virtual OtclPart *instantiatePart (Tcl_Interp *, int *returnCode,
  92.                                       int argc, char *argv[], OtclObject *,
  93.                                       OtclPart **partPtr) = 0;
  94.  
  95.    int instantiate (Tcl_Interp *, int, char *[], OtclObjMgr *);
  96.  
  97.    virtual int classMethod (Tcl_Interp *, int argc, char *argv[]) = 0;
  98.  
  99. protected:  // Protected Instance Attributes
  100.  
  101.    // The class name
  102.    char *name;
  103. };
  104.  
  105. class OtclClassOtcl : public OtclClass
  106. {
  107. public:   // Prublic Constructor & Destructor
  108.  
  109.    OtclClassOtcl (char *name, Otcl *parent);
  110.  
  111.    virtual ~OtclClassOtcl ();
  112.  
  113. public:   // Public Instance Methods
  114.  
  115.    int classMethod (Tcl_Interp *, int, char *[]);
  116.  
  117.    int parseInterface (Tcl_Interp *interp, int argc, char *argv[]);
  118.  
  119.    int parseImplementation (Tcl_Interp *interp, int argc, char *argv[]);
  120.  
  121.    int giveIndexOfSuperclass (char *name);
  122.  
  123.    OtclClass *giveSuperclass (int i);
  124.  
  125.    int shouldDelete (void);
  126.  
  127.    OtclPart *instantiatePart (Tcl_Interp *interp, int *returnCode,
  128.                               int argc, char *argv[], OtclObject *,
  129.                               OtclPart **partPtr);
  130.  
  131.    void instantiateInstanceAttributes(Tcl_HashTable *, Tcl_Interp *);
  132.  
  133.    // Sets up a new call frame in the interp and sets up
  134.    // the class attributes
  135.    void createClassScope (Tcl_Interp *);
  136.    void destroyClassScope (Tcl_Interp *);
  137.  
  138.    OtclConstructorMethod *giveConstructorMethod (void);
  139.    OtclDestructorMethod *giveDestructorMethod (void);
  140.    OtclInstanceMethod *giveInstanceMethod (char *name);
  141.  
  142.    int isComplete (void);
  143.  
  144. public:   // Public Class Methods
  145.  
  146.    static int instanceMethodInterfaceCmd (ClientData, Tcl_Interp *,
  147.                                           int argc, char *argv[]);
  148.  
  149.    static int classMethodInterfaceCmd (ClientData, Tcl_Interp *,
  150.                                        int argc, char *argv[]);
  151.  
  152.    static int constructorInterfaceCmd (ClientData, Tcl_Interp *,
  153.                                        int argc, char *argv[]);
  154.  
  155.    static int instanceMethodImplementationCmd (ClientData, Tcl_Interp *,
  156.                                                int argc, char *argv[]);
  157.  
  158.    static int classMethodImplementationCmd (ClientData, Tcl_Interp *,
  159.                                             int argc, char *argv[]);
  160.  
  161.    static int constructorImplementationCmd (ClientData, Tcl_Interp *,
  162.                                             int argc, char *argv[]);
  163.  
  164.    static int destructorImplementationCmd (ClientData, Tcl_Interp *,
  165.                                            int argc, char *argv[]);
  166.  
  167.    static int instanceAttributeCmd (ClientData, Tcl_Interp *,
  168.                                     int argc, char *argv[]);
  169.  
  170.    static int classAttributeCmd (ClientData, Tcl_Interp *,
  171.                                  int argc, char *argv[]);
  172.  
  173.    static int classCmd (ClientData, Tcl_Interp *,
  174.                         int argc, char *argv[]);
  175.  
  176. private:  // Private Instance Methods
  177.  
  178.    int validMethodName (char *);
  179.  
  180.    int instanceMethodInterface (Tcl_Interp *, int argc, char *argv[]);
  181.  
  182.    int classMethodInterface (Tcl_Interp *, int argc, char *argv[]);
  183.  
  184.    int constructorInterface (Tcl_Interp *, int argc, char *argv[]);
  185.  
  186.    void placeInterfaceCommandsInScope (Tcl_Interp *);
  187.  
  188.    void removeInterfaceCommandsFromScope (Tcl_Interp *);
  189.  
  190.    int parseIsAList (Tcl_Interp *, char *classList);
  191.  
  192.    void placeImplementationCommandsInScope (Tcl_Interp *);
  193.  
  194.    void removeImplementationCommandsFromScope (Tcl_Interp *);
  195.  
  196.    int instanceMethodImplementation (Tcl_Interp *, int argc, char *argv[]);
  197.  
  198.    int classMethodImplementation (Tcl_Interp *, int argc, char *argv[]);
  199.  
  200.    int constructorImplementation (Tcl_Interp *, int argc, char *argv[]);
  201.  
  202.    int destructorImplementation (Tcl_Interp *, int argc, char *argv[]);
  203.  
  204.    int instanceAttribute (Tcl_Interp *, int argc, char *argv[]);
  205.  
  206.    int classAttribute (Tcl_Interp *, int argc, char *argv[]); 
  207.  
  208.    void addClassCommand (Tcl_Interp *);
  209.  
  210. private:  // Private Instance Methods
  211.  
  212.    int checkClassCompleteness (Tcl_Interp *);
  213.  
  214. private:  // Private Instance Attributes
  215.  
  216.    // Pointer to OtclClass for each superclass.
  217.    OtclClass *superclass[MAX_SUPERCLASSES];
  218.    int noOfSuperclasses;
  219.  
  220.    // Hash table of OtclInstanceMethods objects (private & public)
  221.    Tcl_HashTable instanceMethods;
  222.    Tcl_HashTable classMethods;
  223.  
  224.    OtclConstructorMethod *otclConstructorMethod;
  225.  
  226.    OtclDestructorMethod *otclDestructorMethod;
  227.  
  228.    // Hash table of OtclAttribute objects
  229.    Tcl_HashTable classAttributes;
  230.  
  231.    // Hash table of OtclAttributeTemplate objects
  232.    Tcl_HashTable instanceAttributeTemplates;
  233.  
  234.    Otcl *otcl;
  235.  
  236.    // OTCL_TRUE if the clas is fully described, false otherwise.
  237.    int complete;
  238.  
  239.    // Records the old commands from the interp during the processing
  240.    // of an interface or implementation body script
  241.    static Tcl_HashTable commandTable;
  242. };
  243.  
  244. class OtclClassCpp : public OtclClass
  245. {
  246. public:   // Public Constructors & Destructors
  247.  
  248.    OtclClassCpp (char *name);
  249.  
  250.    virtual ~OtclClassCpp ();
  251.  
  252. public:   // Public Instance Methods
  253.  
  254.    int shouldDelete (void);
  255.  
  256.    OtclPart *instantiatePart (Tcl_Interp *interp, int *returnCode,
  257.                               int argc, char *argv[], OtclObject *,
  258.                               OtclPart **partPtr);
  259.  
  260.    int isComplete (void);
  261.  
  262.    int classMethod (Tcl_Interp *, int, char *[]) = 0;
  263.  
  264. public:  // Public Class Methods
  265.  
  266.    static void registerWithOtcl (Otcl *);
  267.  
  268. private:  // Private Class Attributes
  269.  
  270.    // Maintains a list of all instances of OtclClassCpp
  271.    static OtclClassCpp *head;
  272.    static OtclClassCpp *tail;
  273.  
  274. private:  // Private Instance Attributes
  275.  
  276.    // Points to next OtclClassCpp object on list maintained
  277.    // by head and tail class attributes.
  278.    OtclClassCpp *next;
  279. };
  280.  
  281. // Inline Code 
  282. inline char *OtclClass::giveName (void)
  283. {
  284.    return name;
  285. }
  286.  
  287. #endif // OTCL_CLASS_H
  288.