home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cpicture.zip / PARAPICT.HPP < prev    next >
C/C++ Source or Header  |  1992-04-18  |  15KB  |  377 lines

  1. /*************************************************************************
  2. **           Paradox-Like Picture Field Input Processing
  3. **************************************************************************
  4. **                                                                      **
  5. **                                                                      **
  6. **  Copyright (c) 1992  Flexible Information Systems, Inc.              **
  7. **                                                                      **
  8. **    This code may be freely used by any programmer                    **
  9. **    including royalty free inclusion in any commercial                **
  10. **    application, but any commercial rights to the source              **
  11. **    code or object files of this code is are reserved.                **
  12. **                                                                      **
  13. **    This code is supplied strictly as-is, and FIS, Inc. and the       **
  14. **    author assume no responsibility for the accuracy, use or fitness  **
  15. **    for a particular purpose                                          **
  16. **                                                                      **
  17. **      Author:         Ken Vogel                                       **
  18. **      CIS Id:         74007,564                                       **
  19. **      Filename:       parapict.hpp                                    **
  20. **      Prefix:         PPIC_                                           **
  21. **      Date:           24-Mar-92                                       **
  22. **                                                                      **
  23. **      Description:    A set of recursive C++ classes which process
  24. **                      data entry with Paradox-like picture formats.
  25. **
  26. **                      The classes in this file do not actually perform
  27. **                      any keyboard or display functions, but should be
  28. **                      integrated into a data entry system.  This allows
  29. **                      them to be used in TurboVision, Windows, etc.
  30. **
  31. **                                                                      **
  32. **************************************************************************/
  33.  
  34.  
  35. #if 0
  36.     ---->>> Revision History <<<----
  37.     ---->>> Revision History <<<----
  38. #endif
  39.  
  40.  
  41. #if defined( Uses_parapict) && !defined( __parapict)
  42. #define __parapict
  43.  
  44. // Define the Boolean class if necessary
  45. #if !True
  46. typedef enum { False, True } Boolean;
  47. #endif
  48.  
  49. /*--------------------------- Module Constants ---------------------------*/
  50. // These flags are used to indicate the state of the picture after the
  51. // character is accepted
  52. #define PPIC_cOverflow    0x01    // Character overflows to next one
  53. #define PPIC_cFull        0x02    // After taking char, field is full
  54.                                   // useful for auto-tab fields
  55.  
  56. typedef unsigned char PPIC_FlagsType;
  57.  
  58. //
  59. // These are the "internal" representations of the formatting characters.
  60. // They are defined this way to distinguish them from literals, as they
  61. // occur together in the picture strings.
  62. //
  63. // Don't change these without also changing the function PPIC_NextChar
  64. //
  65. #define PPIC_cRepetition   1
  66. #define PPIC_cOptionOpen   2
  67. #define PPIC_cOptionClose  3
  68. #define PPIC_cGroupOpen    4
  69. #define PPIC_cGroupClose   5
  70. #define PPIC_cAlternate    6
  71.  
  72. #define PPIC_cMaxSpecialChar   6  // All chars <= this are special
  73.                                   // Non-formatting indicator characters
  74.  
  75. #define PPIC_cDigit        7
  76. #define PPIC_cLetter       8
  77. #define PPIC_cUpperLetter  9
  78. #define PPIC_cAny          10
  79. #define PPIC_cUpperAny     11
  80.  
  81. #define PPIC_cMaxFormatChar 11  // All chars <= this are special characters
  82.  
  83. #define PPIC_cProbe        12    // Used to probe into string to test auto-
  84.                                 // expand of literal characters
  85.  
  86. /**************************************************************************/
  87.  
  88.  
  89. /*--------------------------- Macro Functions ---------------------------*/
  90. /**************************************************************************/
  91.  
  92.  
  93. /*--------------------------- Return Constants ---------------------------*/
  94. /**************************************************************************/
  95.  
  96.  
  97. /*--------------------------- Module Constants ---------------------------*/
  98. /**************************************************************************/
  99.  
  100.  
  101. /*--------------------------- Exported Variables -------------------------*/
  102. /**************************************************************************/
  103.  
  104.  
  105. /*--------------------------- Class Definitions -------------------------------*/
  106. class PPIC_ElementClass;
  107.  
  108. // The top-level picture class.  All interface to this function should
  109. // occur through an object of this class.
  110.  
  111. class PPIC_PictureClass
  112.   {
  113.     protected:
  114.         PPIC_ElementClass *thePicture;
  115.  
  116.     public:
  117.         // True after creation if the picture is valid & ready to go
  118.         Boolean valid;
  119.  
  120.         // The constructor for the picture parser, which accepts the input
  121.         // picture string.  Check valid after constructing to see if it
  122.         // worked.
  123.         PPIC_PictureClass (const char *PictureP);
  124.  
  125.         ~PPIC_PictureClass();
  126.  
  127.         // Process a letter (either a keypress, or one that's already
  128.         //                   in the input stream)
  129.         //
  130.         // Input:  Letter is the letter to process
  131.         //
  132.         //         IsKeypress is true if this is a keypress (enables
  133.         //         auto-fill of literal data.  False for reprocessing
  134.         //         already-typed information
  135.         //
  136.         //         DestP is a target for the resultant keys
  137.         //         MaxLength is the max # of chars which may be returned
  138.         //
  139.         // Output:
  140.         //         DestP has a characters copied into it
  141.         // Returns:
  142.         //         The # of characters copied into DestP (0 = invalid key)
  143.         //         *FlagsP is True if input is complete (after c/r)
  144.         //
  145.         int ProcessLetter( char    Letter
  146.                          , PPIC_FlagsType *FlagsP
  147.                          , Boolean IsKeypress
  148.                          , char    *DestP
  149.                          , int     MaxLength );
  150.  
  151.         // Reprocess the input string -- call this function after the user
  152.         // changes the string directory (without a backspace, etc.)
  153.         // Returns:  Ptr to the first character in the string which has
  154.         //           a problem (fails the process assignment)
  155.         //           0 if successful reparse
  156.         char *ReprocessString ( char *StringP
  157.                               , PPIC_FlagsType *FlagsP);
  158.  
  159.         // Reset the input state -- call if user restarts assignment.
  160.         void ResetState( void );
  161.   };
  162.  
  163.  
  164. // A simple list of elements.  If you are using TurboVision, you may
  165. // replace this with TNSCollection with the same effect.
  166. //
  167. class PPIC_ElementListClass
  168.   {
  169.     protected:
  170.         PPIC_ElementClass    **dElementsCPP;
  171.         int                  dCount;
  172.  
  173.     public:
  174.         PPIC_ElementListClass();
  175.         ~PPIC_ElementListClass();
  176.         PPIC_ElementClass *at (int Index);
  177.         void insert (PPIC_ElementClass *ElementP);
  178.         void forEach ( void (*actionFun)(PPIC_ElementClass *));
  179.         int getCount()
  180.             { return dCount; }
  181.   };
  182.  
  183.  
  184. // An element of a picture.  The descendants of this class implement
  185. // each of the different kinds of elements that can appear in a picture.
  186. // They can maintain state, which is used during input processing.
  187. class PPIC_ElementClass
  188.   {
  189.     public:
  190.         virtual ~PPIC_ElementClass() {}
  191.  
  192.         // Reset state to start of input
  193.         virtual void ResetState( void ) =0;
  194.  
  195.         // Process a letter (either a keypress, or one that's already
  196.         //                   in the input stream)
  197.         //
  198.         // Input:  Letter is the letter to process
  199.         //
  200.         //         IsKeypress is true if this is a keypress (enables
  201.         //         auto-fill of literal data.  False for reprocessing
  202.         //         already-typed information
  203.         //
  204.         //         DestP is a target for the resultant keys
  205.         //         MaxLength is the max # of chars which may be returned
  206.         //
  207.         // Output:
  208.         //         DestP has a characters copied into it
  209.         // Returns:
  210.         //         The # of characters copied into DestP (0 = invalid key)
  211.         //         *FlagsP is True if input is complete (field is full)
  212.         virtual int ProcessLetter( char    Letter
  213.                                      , PPIC_FlagsType *FlagsP
  214.                                      , Boolean IsKeypress
  215.                                      , char    *DestP
  216.                                      , int     MaxLength ) =0;
  217.   };
  218.  
  219. // A sequence of other picture elements.
  220. class PPIC_SequenceClass : public PPIC_ElementClass
  221.   {
  222.     protected:
  223.         // A list of other elements which make up the sequence.
  224.         PPIC_ElementListClass *dElementListCP;
  225.  
  226.         // The cursor to the current element which is "working" on input
  227.         // (This is part of the input state)
  228.         int              dCurrentEl;
  229.  
  230.     public:
  231.         // Create a sequence from a single other element
  232.         PPIC_SequenceClass ( PPIC_ElementClass  *ElementCP);
  233.  
  234.         // Add an element to the end of a sequence
  235.         void AddElement (PPIC_ElementClass *ElementCP);
  236.  
  237.         virtual ~PPIC_SequenceClass ();
  238.  
  239.         // Reset state to start of input (defined in PPIC_ElementClass)
  240.         virtual void ResetState( void );
  241.  
  242.         // Process a letter (defined in PPIC_ElementClass)
  243.         virtual int ProcessLetter( char    Letter
  244.                                      , PPIC_FlagsType *FlagsP
  245.                                      , Boolean IsKeypress
  246.                                      , char    *DestP
  247.                                      , int     MaxLength );
  248.   }; // PPIC_SequenceClass
  249.  
  250.  
  251. // An list of several alternative picture elements
  252. class PPIC_AlternateClass : public PPIC_ElementClass
  253.   {
  254.     protected:
  255.         // A list of other PPIC_ElementClass * which make up the alternatives
  256.         PPIC_ElementListClass *dAlternativeListCP;
  257.  
  258.         // The cursor to the selected element.  If it is -1, then we have
  259.         // not yet selected an element
  260.         int              dSelectedEl;
  261.  
  262.     public:
  263.         // Create an alternate from a single other element
  264.         PPIC_AlternateClass (PPIC_ElementClass  *ElementCP);
  265.  
  266.         // Add an element to the end of an alternate
  267.         void AddElement (PPIC_ElementClass *ElementCP);
  268.  
  269.         virtual ~PPIC_AlternateClass ();
  270.  
  271.         // Reset state to start of input (defined in PPIC_ElementClass)
  272.         virtual void ResetState( void );
  273.  
  274.         // Process a letter (defined in PPIC_ElementClass)
  275.         virtual int ProcessLetter( char    Letter
  276.                                      , PPIC_FlagsType *FlagsP
  277.                                      , Boolean IsKeypress
  278.                                      , char    *DestP
  279.                                      , int     MaxLength );
  280.   }; // PPIC_AlternateClass
  281.  
  282. // An optional element.  Also contains the *next* element, so we can
  283. // decide if we want to pass over ourselves or not.
  284. class PPIC_OptionalClass : public PPIC_ElementClass
  285.   {
  286.     protected:
  287.         PPIC_ElementClass  *dLeftElementCP;
  288.         PPIC_ElementClass  *dRightElementCP; // May be 0 (NULL)
  289.  
  290.         // The state is whether Left is done with it's input
  291.         enum { PPIC_fStarting
  292.              , PPIC_fLeftActive
  293.              , PPIC_fRightActive }    dState;
  294.  
  295.     public:
  296.         // Construct an option from an element and the next
  297.         PPIC_OptionalClass ( PPIC_ElementClass *LeftCP
  298.                           , PPIC_ElementClass *RightCP );
  299.         virtual ~PPIC_OptionalClass ();
  300.  
  301.         // Reset state to start of input (defined in PPIC_ElementClass)
  302.         virtual void ResetState( void );
  303.  
  304.         // Process a letter (defined in PPIC_ElementClass)
  305.         virtual int ProcessLetter( char    Letter
  306.                                      , PPIC_FlagsType *FlagsP
  307.                                      , Boolean IsKeypress
  308.                                      , char    *DestP
  309.                                      , int     MaxLength );
  310.   }; // PPIC_OptionalClass
  311.  
  312. // A string of any number of formatting characters (literals or pictures).
  313. // The reason we combine these two types of elements is because literals
  314. // behave differently if they occur immediately following formatting
  315. // characters (they must auto-fill).  If the formatting characters are
  316. // enclosed in grouping brackets {}, then they will be a separate element.
  317. class PPIC_FormatClass : public PPIC_ElementClass
  318.   {
  319.     protected:
  320.         // The formatting string.  Note that picture characters are
  321.         // represented by the constants at the beginning of the file.
  322.         char         *dFormatStringOP;
  323.  
  324.         // A pointer into the above string -- the next formatting character.
  325.         char         *dCursorP;
  326.  
  327.     public:
  328.         PPIC_FormatClass (const char *FormatStrP);
  329.         virtual ~PPIC_FormatClass ();
  330.  
  331.         // Reset state to start of input (defined in PPIC_ElementClass)
  332.         virtual void ResetState( void );
  333.  
  334.         // Process a letter (defined in PPIC_ElementClass)
  335.         // Returns the # of chars stored
  336.         virtual int ProcessLetter( char    Letter
  337.                                  , PPIC_FlagsType *FlagsP
  338.                                  , Boolean IsKeypress
  339.                                  , char    *DestP
  340.                                  , int     MaxLength );
  341.   };
  342.  
  343. // A repetition count of another element.
  344. class PPIC_RepetitionClass : public PPIC_ElementClass
  345.   {
  346.     protected:
  347.         // The number of times to repeat.  If -1, then repeat 0 or more
  348.         int          dRepeatCount;
  349.  
  350.         // The # of repetitions left (-1 = infinite)
  351.         int          dRepsLeft;
  352.  
  353.         // Are we in the middle of processing the current elmenent?
  354.         Boolean      dInProcess;
  355.  
  356.         // The element being repeated
  357.         PPIC_ElementClass *dElementCP;
  358.  
  359.     public:
  360.         PPIC_RepetitionClass (int Count, PPIC_ElementClass *ElementCP);
  361.         virtual ~PPIC_RepetitionClass ();
  362.  
  363.         // Reset state to start of input (defined in PPIC_ElementClass)
  364.         virtual void ResetState( void );
  365.  
  366.         // Process a letter (defined in PPIC_ElementClass)
  367.         virtual int ProcessLetter( char    Letter
  368.                                      , PPIC_FlagsType *FlagsP
  369.                                      , Boolean IsKeypress
  370.                                      , char    *DestP
  371.                                      , int     MaxLength );
  372.   }; // PPIC_RepetitionClass
  373.  
  374. /**************************************************************************/
  375.  
  376. #endif /* Check for AlreadyIncluded */
  377.