home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / VALIDATE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  5.3 KB  |  211 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993, 1993 by Borland International
  3. //   source\owl\validate.h
  4. //----------------------------------------------------------------------------
  5. #if !defined(__OWL_VALIDATE_H)
  6. #define __OWL_VALIDATE_H
  7.  
  8. #if !defined(__OWL_WINDOW_H)
  9.   #include <owl\window.h>
  10. #endif
  11. #if !defined(__CLASSLIB_ARRAYS_H)
  12.   #include <classlib\arrays.h>
  13. #endif
  14. #if !defined(__OWL_BITSET_H)
  15.   #include <owl\bitset.h>
  16. #endif
  17. #include <owl\validate.rh>
  18.  
  19. //
  20. // Validator option flags
  21. //
  22. enum TValidatorOptions {
  23.   voFill     =  0x0001,
  24.   voTransfer =  0x0002,
  25.   voOnAppend =  0x0004,
  26.   voReserved =  0x00F8
  27. };
  28.  
  29. //
  30. // class TValidator
  31. // ----- ----------
  32. //
  33. class _OWLCLASS TValidator : public TStreamableBase {
  34.   public:
  35.     class _OWLCLASS_RTL TXValidator : TXOwl {
  36.       public:
  37.         TXValidator(UINT resId = IDS_VALIDATORSYNTAX);
  38.     };
  39.  
  40.     TValidator();
  41.     virtual ~TValidator();
  42.  
  43.     virtual void Error();
  44.     virtual BOOL IsValidInput(char far* str, BOOL suppressFill);
  45.     virtual BOOL IsValid(const char far* str);
  46.     virtual UINT Transfer(char far* str, void* buffer, TTransferDirection direction);
  47.  
  48.     // Checks input against validator for completeness. Never modifies input.
  49.     // Calls error if not valid.
  50.     //
  51.     BOOL         Valid(const char far* str)
  52.                   {if (!IsValid(str)) {Error(); return FALSE;} return TRUE;}
  53.  
  54.     BOOL         HasOption(int option) {return Options & option;}
  55.     void         SetOption(int option) {Options |= WORD(option);}
  56.     void         UnsetOption(int option) {Options &= WORD(~option);}
  57.  
  58.   protected:
  59.     WORD   Options;
  60.     
  61.   DECLARE_STREAMABLE(_OWLCLASS, TValidator, 1);
  62. };
  63.  
  64. //
  65. // TPXPictureValidator result type
  66. //
  67. enum TPicResult {
  68.   prComplete,
  69.   prIncomplete,
  70.   prEmpty,
  71.   prError,
  72.   prSyntax,
  73.   prAmbiguous,
  74.   prIncompNoFill
  75. };
  76.  
  77. //
  78. // class TPXPictureValidator
  79. // ----- -------------------
  80. //
  81. class _OWLCLASS TPXPictureValidator : public TValidator {
  82.   public:
  83.     TPXPictureValidator(const char far* pic, BOOL autoFill=FALSE);
  84.  
  85.     //
  86.     // override TValidator's virtuals
  87.     //
  88.     void         Error();
  89.     BOOL         IsValidInput(char far* str, BOOL suppressFill);
  90.     BOOL         IsValid(const char far* str);
  91.  
  92.     virtual TPicResult Picture(char far* input, BOOL autoFill=FALSE);
  93.  
  94.   protected:
  95.     string       Pic;
  96.  
  97.   private:
  98.     BOOL         IsComplete(TPicResult rslt);
  99.     BOOL         IsIncomplete(TPicResult rslt);
  100.     void         ToGroupEnd(UINT termCh, UINT& i);
  101.     BOOL         SkipToComma(UINT termCh, UINT& i);
  102.     UINT         CalcTerm(UINT termCh, UINT i);
  103.     TPicResult   Iteration(char far* input, UINT termCh, UINT& i, UINT& j);
  104.     TPicResult   Group(char far* input, UINT termCh, UINT& i, UINT& j);
  105.     TPicResult   CheckComplete(UINT termCh, UINT& i, TPicResult rslt);
  106.  
  107.     TPicResult   Scan(char far* input, UINT termCh, UINT& i, UINT& j);
  108.     TPicResult   Process(char far* input, UINT termCh, UINT& i, UINT& j);
  109.     BOOL         SyntaxCheck();
  110.  
  111.   DECLARE_STREAMABLE(_OWLCLASS, TPXPictureValidator, 1);
  112. };
  113.  
  114. //
  115. // class TFilterValidator
  116. // ----- ----------------
  117. //
  118. class _OWLCLASS TFilterValidator : public TValidator {
  119.   public:
  120.     TFilterValidator(const TCharSet& validChars);
  121.  
  122.     //
  123.     // override TValidator's virtuals
  124.     //
  125.     void         Error();
  126.     BOOL         IsValid(const char far* str);
  127.     BOOL         IsValidInput(char far* str, BOOL suppressFill);
  128.  
  129.   protected:
  130.     TCharSet     ValidChars;
  131.  
  132.   DECLARE_STREAMABLE(_OWLCLASS, TFilterValidator, 1);
  133. };
  134.  
  135. //
  136. // class TRangeValidator
  137. // ----- ---------------
  138. //
  139. class _OWLCLASS TRangeValidator : public TFilterValidator {
  140.   public:
  141.     TRangeValidator(long min, long max);
  142.  
  143.     //
  144.     // override TValidator's virtuals
  145.     //
  146.     void         Error();
  147.     BOOL         IsValid(const char far* str);
  148.     UINT         Transfer(char far* str, void* buffer, TTransferDirection direction);
  149.  
  150.   protected:
  151.     long   Min;
  152.     long   Max;
  153.  
  154.   DECLARE_STREAMABLE(_OWLCLASS, TRangeValidator, 1);
  155. };
  156.  
  157. //
  158. // class TLookupValidator
  159. // ----- ----------------
  160. //
  161. class _OWLCLASS TLookupValidator : public TValidator {
  162.   public:
  163.     TLookupValidator();
  164.  
  165.     //
  166.     // override TValidator's virtuals
  167.     //
  168.     BOOL         IsValid(const char far* str);
  169.  
  170.     // virtual lookup of a string
  171.     virtual BOOL Lookup(const char far* str);
  172.  
  173.   DECLARE_STREAMABLE(_OWLCLASS, TLookupValidator, 1);
  174. };
  175.  
  176. //
  177. // type TSortedStringArray
  178. // ---- ------------------
  179. //
  180. typedef TSArrayAsVector<string> TSortedStringArray;
  181.  
  182. //
  183. // class TStringLookupValidator
  184. // ----- ----------------------
  185. //
  186. class _OWLCLASS TStringLookupValidator : public TLookupValidator {
  187.   public:
  188.     TStringLookupValidator(TSortedStringArray* strings);
  189.    ~TStringLookupValidator();
  190.  
  191.     //
  192.     // override TValidator's virtuals
  193.     //
  194.     void         Error();
  195.  
  196.     //
  197.     // override TLookupValidator's virtuals
  198.     //
  199.     BOOL         Lookup(const char far* str);
  200.  
  201.     void         NewStringList(TSortedStringArray* strings);
  202.  
  203.   protected:
  204.     TSortedStringArray* Strings;
  205.  
  206.   DECLARE_STREAMABLE(_OWLCLASS, TStringLookupValidator, 1);
  207. };
  208.  
  209.  
  210. #endif  // __OWL_VALIDATE_H
  211.