home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / include / ObjectTcl-1.1 / otcl / Otcl.H next >
Encoding:
C/C++ Source or Header  |  1995-06-29  |  7.7 KB  |  209 lines

  1. #ifndef OTCL_H
  2. #define OTCL_H
  3.  
  4. /*  _ __ ___ _
  5.  * | |\ /  /| |  $Id: Otcl.H,v 1.8 1995/06/16 13:04:02 deans Exp $
  6.  * | | /  / | |  Copyright (C) 1995 IXI Limited.
  7.  * |_|/__/_\|_|  IXI Limited, Cambridge, England.
  8.  *
  9.  * Component   : Otcl.H
  10.  *
  11.  * Author      : Dean Sheehan (deans@x.co.uk)
  12.  *  
  13.  * Description : Header file for the Object Tcl extensions
  14.  *
  15.  * License     :
  16.             Object Tcl License & Copyright
  17.             -----------------------------
  18.  
  19. IXI Object Tcl software, both binary and source (hereafter, Software) is copyrighted by IXI Limited (IXI), and ownership remains with IXI. 
  20.  
  21. 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. 
  22.  
  23. 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. 
  24.  
  25. 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. 
  26.  
  27. 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. 
  28.  
  29. Copyright (C) 1995, IXI Limited 
  30.  
  31. 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. 
  32.  
  33. Comments and questions are welcome and can be sent to
  34. otcl@x.co.uk 
  35.  
  36. For more information on copyright and licensing issues, contact: 
  37. Legal Department, IXI Limited, Vision Park, Cambridge CB4 4ZR,
  38. ENGLAND. 
  39.  
  40.  *
  41.  */
  42.  
  43. // Tcl Includes
  44. #include <tcl.h>
  45.  
  46. // local Includes
  47. #include "OtclError.H"
  48.  
  49. // Command Name Defines
  50. #define CLASS_INTERFACE_CMD      "otclInterface"
  51. #define CLASS_IMPLEMENTATION_CMD "otclImplementation"
  52. #define INSTANTIATE_CMD          "otclNew"
  53. #define DISCARD_CMD              "otclDelete"
  54. #define OTCL_CMD                 "otcl"
  55. #define OTCL_NOP_CMD             "_otcl_nop_"
  56.  
  57. // TO DO, where should the standard library go?
  58. #define OTCL_LIBRARY "/usr/local/lib"
  59.  
  60. // Macro Definitions
  61. #define ARGC_RANGE(lo,hi) if (argc < (lo) || argc > (hi)) 
  62. #define ARGC_MIN(lo) if (argc < (lo))
  63. #define ARGC_VALUE(val) if (argc != val)
  64.  
  65. // Public Defines
  66. #define OTCL_TRUE 1
  67. #define OTCL_FALSE 0
  68. #define OTCL_ERR_BUF_SIZE 256
  69.  
  70. // Forward Class Declarations
  71. class OtclClass;
  72. class OtclClassOtcl;
  73. class OtclClassCpp;
  74. class OtclObjMgr;
  75. class OtclObject;
  76. class OtclPart;
  77.  
  78. // Forward structure definitions
  79. struct Interp;
  80. struct Var;
  81.  
  82. // Class    : Otcl
  83. // Synopsis : The OO extension to the Tcl_Interp structure.
  84. // If a Tcl_Interp is created, using Tcl_CreateInterp, and the Otcl extension 
  85. // is required for that interpreter then instantiate an Otcl object for it.
  86. // Before the Tcl_Interp is delete, delete the Otcl object.
  87. class Otcl
  88. {
  89. public:   // Public Constructors & Destructors
  90.  
  91.    // Constructor and initialiser for the Object Tcl extension
  92.    Otcl (Tcl_Interp *, int &result, OtclObjMgr *objMgr);
  93.  
  94.    ~Otcl ();
  95.  
  96. public:   // Public Class Methods
  97.  
  98.    // The following static class methods are the Tcl command entry
  99.    // points. The ClientData for argument is actually a pointer to the
  100.    // Otcl object. The static methods pass the call on to the actual
  101.    // instance method with the same name minus the "Cmd" suffix.
  102.  
  103.    static int classInterfaceCmd (ClientData, Tcl_Interp *,
  104.                             int argc, char *argv[]);
  105.  
  106.    static int classImplementationCmd (ClientData, Tcl_Interp *,
  107.                            int argc, char *argv[]);
  108.  
  109.    static int instantiateCmd (ClientData, Tcl_Interp *,
  110.                               int argc, char *argv[]);
  111.  
  112.    static int discardCmd (ClientData, Tcl_Interp *,
  113.                           int argc, char *argv[]);
  114.  
  115.    static int otclCmd (ClientData, Tcl_Interp *,
  116.                 int argc, char *argv[]);
  117.  
  118.    static int otclNopCmd (ClientData, Tcl_Interp *,
  119.                           int argc, char *argv[]);
  120.  
  121.    static int classCmd (ClientData, Tcl_Interp *,
  122.                         int argc, char *argv[]);
  123.  
  124.    static void setTclResult(Tcl_Interp *, char *format ...);
  125.    static int setTclError(Tcl_Interp *, char *format ...);
  126.    static void addTclErrorInfo(Tcl_Interp *, char *format ...);
  127.  
  128.    // Duplicates of private Tcl functions used to manage local variables
  129.    static char *callTraces(Interp *, Var *, Var *, char *, char *, int);
  130.    static void deleteArray(Interp *, char *, Var *, int);
  131.  
  132.    static OtclObject *createObjectWrapper (OtclPart *);
  133.  
  134. public:  // Public Instance Methods
  135.  
  136.    // Used by OtclClassCpp::registerWithOtcl to register
  137.    // the Otcl bound C++ classes
  138.    void registerOtclClassCpp (OtclClassCpp *);
  139.  
  140.    OtclClass *giveOtclClass (char *className);
  141.    OtclObject *giveOtclObject (char *symRef, Tcl_Interp *, int &returnCode);
  142.  
  143.    int discard (Tcl_Interp *, char *symRef, int fromCpp);
  144.  
  145.    // A very interesting function :-) The void * is because all this
  146.    // code is generic and doesn't have a clue what the class is!
  147.    // A nasty hack, if the obref = NULL, null or 0 then the pointer
  148.    // returned will = this Otcl object!!!!!!!
  149.    void *obrefToCpp (char *obref, char *cppClassName);
  150.  
  151.    void setObjectReferenceSuffix (char *suffix);
  152.  
  153.    int instantiate (Tcl_Interp *, char *className, int argc, char *argv[]);
  154.  
  155. private: // Private Instance Methods
  156.  
  157.    int classInterface (Tcl_Interp *, int argc, char *argv[]);
  158.  
  159.    int classImplementation (Tcl_Interp *, int argc, char *argv[]);
  160.  
  161.    int instantiate (Tcl_Interp *, int argc, char *argv[]);
  162.  
  163.    int discard (Tcl_Interp *, int argc, char *argv[]);
  164.  
  165.    int otcl (Tcl_Interp *, int argc, char *argv[]);
  166.  
  167.    // Places CLASS_INTERFACE_CMD, CLASS_INTERNALS_CMD,
  168.    // CONSTRUCT_CMD and DESTRUCT_CMD in scope.
  169.    void placeCommandsInScope (Tcl_Interp *);
  170.  
  171.    // Removes the above commands from scope.
  172.    void removeCommandsFromScope (Tcl_Interp *);
  173.  
  174.    // Clear out all classes 
  175.    int clear (Tcl_Interp *);
  176.  
  177. #ifdef OTCL_DP
  178.    int remoteObject (Tcl_Interp *interp, int argc, char *argv[]);
  179.    int remoteClass (Tcl_Interp *interp, int argc, char *argv[]);
  180. #endif
  181.  
  182. private: // Private Instance Attributes
  183.  
  184.    // The available OtclClass objects keyed by their class name.
  185.    Tcl_HashTable classes;
  186.  
  187.    // Object responsible for mapping objects to Tcl commands
  188.    OtclObjMgr *objMgr;
  189.  
  190. #ifdef OTCL_DP
  191.    Tcl_HashTable remoteClasses;
  192. #endif
  193.  
  194. public:  // Public Class Attributes
  195.  
  196.    static Tcl_Interp *tclInterp;
  197.  
  198.    static Otcl *otclPtr;
  199.  
  200. };
  201.  
  202. extern "C" int
  203. Otcl_Init (Tcl_Interp *interp);
  204.  
  205. int
  206. Otcl_Main(int argc, char **argv);
  207.  
  208. #endif // OTCL_H
  209.