[previous] [up] [next]     [contents] [index]
Next: How does xctocc work? Up: xctocc Overview Previous: xctocc Overview

What is xctocc?

xctocc reads ``.xc'' script files and generates ``.cc'' C++ files. An ``.xc'' file contains descriptions of C++ classes and functions; this information is similar to the information in a header file, but xctocc needs more specific information about parameter types and how to bundle and unbundle complex types.

Here is an example C++ header file ``points.h'':

  class IntPoint 
  {
    protected:
      int pointtype;
      int first, second;
    public:
      IntPoint(int first = 0, int second = 0);
      int First(void);
      int Second(void);
      int operator==(IntPoint *other);
  };

  class ColorIntPoint : public IntPoint
  {
    private:
      int colorid;
    public:
      ColorIntPoint(int first = 0, int second = 0, char *color = "white");
      ColorIntPoint(char *color);
      char *Color(void);
      int operator==(IntPoint *other);

      int colorbad; // Set to TRUE if the color doesn't really exist
  };

  // Dynamic type values:
  enum {
    PlainType,
    ColorType
  };

  // Color management:
  int LookupColorId(char *name);
  char *ColorNameFromId(int id);

  enum {
    WhiteColor,
    BlackColor,
    RedColor,
    GreenColor,
    BlueColor
  };

This header defines two classes: IntPoint and ColorIntPoint. Dynamic type information is stored in the pointtype member. In addition to the classes, there are two global functions.

Here is a script ``points.xc'' that generates glue code for these class and function definitions:

  #include "points.h"

  @BOOLEAN int
  @CLASSSUFFIX "%"
  @IDFIELD pointtype

  @HEADER

  @CLASSBASE IntPoint "int-point"
  @CLASSID PlainType

  @CREATOR (int=0,int=0)

  @ "first" : int First()
  @ "second" : int Second()
  @ "equal?" : bool operator==(IntPoint!)

  @END

  @CLASSBASE ColorIntPoint "color-int-point" : "int-point"
  @CLASSID ColorType

  @CREATOR (int=0,int=0,string="white")
  @CREATOR ()

  @ "color" : string Color()
  @ "equal?" : int operator==(IntPoint!)

  @IVAR r "color-bad" : bool colorbad

  @END

  @GLOBAL Colors

  @ "lookup-color-id" : int LookupColorId(string);
  @ "color-name-from-id" : string ColorNameFromId(int);

  @CONSTANT "const-white-color" : int WhiteColor
  @CONSTANT "const-black-color" : int WhiteColor
  @CONSTANT "const-red-color" : int RedColor
  @CONSTANT "const-green-color" : int GreenColor
  @CONSTANT "const-blue-color" : int BlueColor

  @END

If all class definitions were as simple as these, then xctocc would be a reasonably good (though poorly implemented) tool. Unfortunately, the presence of ``complications'' occurs more often in real C++ class libraries than was anticipated in the initial design for xctocc. Thus, the xctocc scripting language has turned into a monsterous jumble of switches and special cases. Still, until someone writes a replacement, using xctocc is typically simpler and more reliable than writing the glue code by hand.


[previous] [up] [next]     [contents] [index]
Next: How does xctocc work? Up: xctocc Overview Previous: xctocc Overview

PLT