home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv7.zip / VACPP / IBMCPP / smarts / DTS / ANIMAL / ANIMAL.HH < prev    next >
Text File  |  1995-06-02  |  2KB  |  59 lines

  1. %PROLOG%
  2.  
  3. #include <som.hh>
  4.  
  5. #ifndef ANIMAL_HH
  6. #define ANIMAL_HH
  7. /*
  8.  * Declare the Animal base class and the methods and instance
  9.  * data that it introduces.  The class uses the _Export keyword
  10.  * because, like most SOM classes, its implementation will be in a DLL.
  11.  * When applied to a DTS class, _Export causes all the right
  12.  * external symbols to be exported without naming them in a DEF file.
  13.  *
  14.  * The public interface is
  15.  *  a nested type  "enum provocation"
  16.  *  an overridable method reactTo(provocation)
  17.  *  a public data member  name
  18.  *  a constructor with a single char* parameter.
  19.  *  a destructor
  20.  *  an instance counter.  It will count instances of Animal and
  21.  *     all its subclasses.
  22.  *
  23.  * Since the constructor has default values for all its (one) parameters,
  24.  * it doubles as a default constructor.
  25.  *
  26.  * Public instance data is supported by DTS, and clients can directly
  27.  * access the "name" instance variable of an Animal, as long as the
  28.  * object involved is not a remote (DSOM) object.
  29.  * DSOM only supports method invocation but not direct data access.
  30.  *
  31.  * To allow for that case, we tell the compiler to create a public attribute
  32.  * (pair of get/set methods) for "name", and to let the actual instance data
  33.  * (or "backing data") also be public.  In DSOM programs, this header
  34.  * should be wrapped by
  35.  *        #pragma SOMNoDataDirect(on)
  36.  *        #include "animal.hh"
  37.  *        #pragma SOMNoDataDirect(pop)
  38.  * which will force use of the get/set methods.  In non-DSOM programs, the
  39.  * public data is directly accessed.
  40.  */
  41.  
  42. class _Export Animal : public SOMObject {
  43.    public:
  44.     enum provocation { pet, tickle, pinch, vex_mightily };
  45.  
  46.     virtual void reactTo(provocation p);
  47.     char* name;
  48.     Animal(char* name = "theBeast");
  49.     virtual ~Animal();
  50.  
  51.    private:
  52.     short timesProvoked;
  53.    public:
  54.     static int numberOfAnimals;
  55.  
  56.    #pragma SOMAttribute(name, publicdata)
  57. };
  58. #endif
  59.