home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / XCMDs / XCMDTools++ / xcmdStrings.h < prev    next >
Encoding:
Text File  |  1995-10-05  |  3.5 KB  |  99 lines  |  [TEXT/CWIE]

  1. //    © Paul B. Beeken, Work In Progress, 1994-5
  2. //    Knowledge Software Consulting.
  3. //
  4. //    These files are a mindlessly simple wrapper class for the
  5. //    basic XCMD operations.  Only one instance of the xcmdBase class is
  6. //    generated per XCMD call but there may be many instances of the XCMDString
  7. //    class.  I have used these classes to whip out XCMD/XFCNs within hours of
  8. //    receiving the specs.  They work great for me but I will always consider 
  9. //    suggestions.
  10. //
  11. //    Please, please, please, in the unlikely event you should use this stuff
  12. //    for some commercial application I would appreciate you contacting me.  If
  13. //    its for your own use, use away. Send email: knowsoft@ios.com
  14. //
  15. //    As always: this file is presented as is with no warrantees expressed or implied.
  16. //    Swim at your own risk, etc. etc.
  17.  
  18. #pragma    once
  19. #include    "xcmdBase.h"
  20.  
  21. #ifndef    __HYPERXCMD__
  22. #include    <HyperXCmd.h>
  23. #endif
  24.  
  25. //
  26. //    Strings form a very important basis for information exchange in
  27. //    hypercard's xcmds and xfcns.  It predates the abstract object hierarchy
  28. //    devised for AppleScript.  All information is passed using handles to 
  29. //    null terminated strings.  Hypercard is a bit schitzophrenic (as is my spelling)
  30. //  though. Many
  31. //    of the call back functions require the use of pascal type strings.  The 
  32. //    creation of a special class to handle these objects is an attempt to deal
  33. //    with this problem in a transparent way.
  34. //
  35. //    N.B. an xcmd base object must be instantiated before any of the member
  36. //    functions are called.  The xcmdBase object sets up the paramPtr which
  37. //    is the vector for the call backs.
  38. //
  39.  
  40. class    xcmdString    {
  41.  
  42.     private:
  43.         static    XCmdPtr        paramPtr;    // allocated when xcmdBase object is instantiated.
  44.  
  45.         Boolean        isPascal;            // flag as to string type.
  46.         union    {
  47.             char*        c;                // Pointer to c string.
  48.             StringPtr    p;                // Pointer to pascal string.
  49.                 }    str;
  50.     
  51.     protected:
  52.         // These functions must be used with great care.
  53.         StringPtr    pString( void );        //    Bottlenecks for string conversion
  54.         char*        cString( void );        //    Establishes type and converts if necessary
  55.         operator Handle();                    // coerce to a Handle. n.b. user must dispose if not returned to hc.
  56.     
  57.     public:
  58.     
  59.         xcmdString( Handle s );
  60.         ~xcmdString();
  61.         
  62.         // sometimes we need the string explicitly.
  63.         int        length( void )    const;
  64.         
  65.         // constructors operators for useful types:
  66.         xcmdString( const xcmdString& s );    // copy constructor
  67.         xcmdString( char* s );
  68.         xcmdString( StringPtr s );
  69.         xcmdString( Boolean v );
  70.         xcmdString( extended v );
  71.         xcmdString( unsigned long v );
  72.         xcmdString( long v, short nd );
  73.         xcmdString( long v );
  74.         xcmdString( Point pt );
  75.         xcmdString( Rect& rct );
  76.         
  77.         // coersion operators for useful types:
  78.         operator Boolean();                 // coerece to a Boolean (string is true or false)
  79.         operator Rect();                    // coerce to a Rect structure
  80.         operator Point();                    // coerce to a Point
  81.         operator long();                    // coerce to a signed long value
  82.         operator unsigned long();            // coerce to an unsigned long value
  83.         operator extended();                // coerce to an extended value
  84.         operator StringPtr();                // coerce to a pascal string ptr
  85.         operator char*();                    // coerce to a c string ptr
  86.         
  87.         // some important operators
  88.         int            contains( xcmdString& s2 );            // offset of s2 in me
  89.  
  90.         xcmdString&    operator=( const xcmdString& s2 );    // assignment
  91.         char        operator[]( const int i );
  92.         friend
  93.         xcmdString    operator&( const xcmdString& s1, const xcmdString& s2 );        // catenation
  94.         friend
  95.         Boolean     operator==( const xcmdString& s1, const xcmdString& s2 );
  96.         friend
  97.         Boolean        operator!=( const xcmdString& s1, const xcmdString& s2 );
  98.         
  99.     };