home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / tvision / validate.h < prev    next >
C/C++ Source or Header  |  1998-01-19  |  8KB  |  299 lines

  1. /*
  2.  * validate.h
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #if defined(Uses_TValidator) && !defined(__TValidator)
  13. #define __TValidator
  14.  
  15. // TValidator Status constants
  16.  
  17. static const int
  18.   vsOk     =  0,
  19.   vsSyntax =  1,      // Error in the syntax of either a TPXPictureValidator
  20.                       // or a TDBPictureValidator
  21.  
  22. // Validator option flags
  23.   voFill     =  0x0001,
  24.   voTransfer =  0x0002,
  25.   voReserved =  0x00FC;
  26.  
  27. // TVTransfer constants
  28.  
  29.  
  30. enum TVTransfer {vtDataSize, vtSetData, vtGetData};
  31.  
  32. // Abstract TValidator object
  33.  
  34.  
  35. class TValidator : public TObject, public TStreamable
  36. {
  37. public:
  38.     TValidator();
  39.     virtual void error();
  40.     virtual Boolean isValidInput(char* s, Boolean suppressFill);
  41.     virtual Boolean isValid(const char* s);
  42.     virtual ushort transfer(char *s, void* buffer, TVTransfer flag);
  43.     Boolean validate(const char* s);
  44.  
  45.     ushort status;
  46.     ushort options;
  47.  
  48. protected:
  49.     TValidator( StreamableInit );
  50.     virtual void write( opstream& os );
  51.     virtual void* read( ipstream& is );
  52.  
  53. private:
  54.     virtual const char *streamableName() const  {return name;};
  55.  
  56. public:
  57.     static TStreamable *build();
  58.     static const char * const name;
  59. };
  60.  
  61. #endif
  62.  
  63.  
  64. #if defined(Uses_TPXPictureValidator) && !defined(__TPXPictureValidator)
  65. #define __TPXPictureValidator
  66.  
  67. // TPXPictureValidator result type
  68.  
  69. enum TPicResult {prComplete, prIncomplete, prEmpty, prError, prSyntax,
  70.     prAmbiguous, prIncompNoFill};
  71.  
  72. // TPXPictureValidator
  73.  
  74.  
  75. class TPXPictureValidator : public TValidator
  76. {
  77.  
  78.     static const char * errorMsg;
  79.  
  80. public:
  81.     TPXPictureValidator(const char* aPic, Boolean autoFill);
  82.     ~TPXPictureValidator();
  83.     virtual void error();
  84.     virtual Boolean isValidInput(char* s, Boolean suppressFill);
  85.     virtual Boolean isValid(const char* s);
  86.     virtual TPicResult picture(char* input, Boolean autoFill);
  87.  
  88.  
  89. protected:
  90.     TPXPictureValidator( StreamableInit );
  91.     virtual void write( opstream& os );
  92.     virtual void* read( ipstream& is );
  93.  
  94.     char* pic;
  95.  
  96. private:
  97.     void consume(char ch, char* input);
  98.     void toGroupEnd(int& i, int termCh);
  99.     Boolean skipToComma(int termCh);
  100.     int calcTerm(int);
  101.     TPicResult iteration(char* input, int termCh);
  102.     TPicResult group(char* input, int termCh);
  103.     TPicResult checkComplete(TPicResult rslt, int termCh);
  104.     TPicResult scan(char* input, int termCh);
  105.     TPicResult process(char* input, int termCh);
  106.     Boolean syntaxCheck();
  107.     virtual const char *streamableName() const  {return name;};
  108.  
  109.     int index, jndex;
  110.  
  111. public:
  112.     static TStreamable *build();
  113.     static const char * const name;
  114. };
  115.  
  116. inline ipstream& operator >> ( ipstream& is, TValidator& v )
  117.     { return is >> (TStreamable&)v; }
  118. inline ipstream& operator >> ( ipstream& is, TValidator*& v )
  119.     { return is >> (void *&)v; }
  120.  
  121. inline opstream& operator << ( opstream& os, TValidator& v )
  122.     { return os << (TStreamable&)v; }
  123. inline opstream& operator << ( opstream& os, TValidator* v )
  124.     { return os << (TStreamable *)v; }
  125.  
  126. #endif
  127.  
  128.  
  129. #if defined(Uses_TFilterValidator) && !defined(__TFilterValidator)
  130. #define __TFilterValidator
  131.  
  132. // TFilterValidator
  133.  
  134. class TFilterValidator : public TValidator
  135. {
  136.  
  137.     static const char * errorMsg;
  138.  
  139. public:
  140.     TFilterValidator(const char* aValidChars);
  141.     ~TFilterValidator();
  142.     virtual void error();
  143.     virtual Boolean isValidInput(char* s, Boolean suppressFill);
  144.     virtual Boolean isValid(const char* s);
  145.  
  146. protected:
  147.     TFilterValidator( StreamableInit );
  148.     virtual void write( opstream& os);
  149.     virtual void* read( ipstream& is );
  150.  
  151.     char* validChars;
  152.  
  153. private:
  154.     virtual const char *streamableName() const  {return name;};
  155.  
  156. public:
  157.     static TStreamable *build();
  158.     static const char * const name;
  159. };
  160.  
  161. inline ipstream& operator >> ( ipstream& is, TFilterValidator& v )
  162.     { return is >> (TStreamable&)v; }
  163. inline ipstream& operator >> ( ipstream& is, TFilterValidator*& v )
  164.     { return is >> (void *&)v; }
  165.  
  166. inline opstream& operator << ( opstream& os, TFilterValidator& v )
  167.     { return os << (TStreamable&)v; }
  168. inline opstream& operator << ( opstream& os, TFilterValidator* v )
  169.     { return os << (TStreamable *)v; }
  170.  
  171. #endif
  172.  
  173.  
  174. #if defined(Uses_TRangeValidator) && !defined(__TRangeValidator)
  175. #define __TRangeValidator
  176.  
  177. // TRangeValidator
  178.  
  179.  
  180. class TRangeValidator : public TFilterValidator
  181. {
  182.  
  183.     static const char * validUnsignedChars;
  184.     static const char * validSignedChars;
  185.     static const char * errorMsg;
  186.  
  187. public:
  188.     TRangeValidator(long aMin, long aMax);
  189.     virtual void error();
  190.     virtual Boolean isValid(const char* s);
  191.     virtual ushort transfer(char* s, void* buffer, TVTransfer flag);
  192.  
  193. protected:
  194.     long min;
  195.     long max;
  196.  
  197.     TRangeValidator( StreamableInit );
  198.     virtual void write( opstream& os );
  199.     virtual void* read( ipstream& is );
  200.  
  201. private:
  202.     virtual const char *streamableName() const  {return name;};
  203.  
  204. public:
  205.     static TStreamable *build();
  206.     static const char * const name;
  207.  
  208. };
  209.  
  210. inline ipstream& operator >> ( ipstream& is, TRangeValidator& v )
  211.     { return is >> (TStreamable&)v; }
  212. inline ipstream& operator >> ( ipstream& is, TRangeValidator*& v )
  213.     { return is >> (void *&)v; }
  214.  
  215. inline opstream& operator << ( opstream& os, TRangeValidator& v )
  216.     { return os << (TStreamable&)v; }
  217. inline opstream& operator << ( opstream& os, TRangeValidator* v )
  218.     { return os << (TStreamable *)v; }
  219.  
  220. #endif
  221.  
  222. #if defined(Uses_TLookupValidator) && !defined(__TLookupValidator)
  223. #define __TLookupValidator
  224.  
  225. // TLookupValidator
  226.  
  227. class TLookupValidator : public TValidator
  228. {
  229. public:
  230.     TLookupValidator() {};
  231.     virtual Boolean isValid(const char* s);
  232.     virtual Boolean lookup(const char* s);
  233.     static TStreamable *build();
  234.     static const char * const name;
  235. protected:
  236.     TLookupValidator( StreamableInit );
  237. private:
  238.     virtual const char *streamableName() const  {return name;};
  239. };
  240.  
  241. inline ipstream& operator >> ( ipstream& is, TLookupValidator& v )
  242.     { return is >> (TStreamable&)v; }
  243. inline ipstream& operator >> ( ipstream& is, TLookupValidator*& v )
  244.     { return is >> (void *&)v; }
  245.  
  246. inline opstream& operator << ( opstream& os, TLookupValidator& v )
  247.     { return os << (TStreamable&)v; }
  248. inline opstream& operator << ( opstream& os, TLookupValidator* v )
  249.     { return os << (TStreamable *)v; }
  250.  
  251. #endif
  252.  
  253.  
  254. #if defined(Uses_TStringLookupValidator) && !defined(__TStringLookupValidator)
  255. #define __TStringLookupValidator
  256.  
  257. // TStringLookupValidator
  258.  
  259. class TStringLookupValidator : public TLookupValidator
  260. {
  261.  
  262.     static const char * errorMsg;
  263.  
  264. public:
  265.     TStringLookupValidator(TStringCollection* aStrings);
  266.     ~TStringLookupValidator();
  267.     virtual void error();
  268.     virtual Boolean lookup(const char* s);
  269.  
  270. protected:
  271.     TStringLookupValidator( StreamableInit );
  272.     virtual void write( opstream& os );
  273.     virtual void* read( ipstream& is );
  274.  
  275.     TStringCollection* strings;
  276.  
  277. private:
  278.     virtual const char *streamableName() const  {return name;};
  279.  
  280. public:
  281.     void newStringList(TStringCollection* aStrings);
  282.     static TStreamable *build();
  283.     static const char * const name;
  284. };
  285.  
  286.  
  287. inline ipstream& operator >> ( ipstream& is, TStringLookupValidator& v )
  288.     { return is >> (TStreamable&)v; }
  289. inline ipstream& operator >> ( ipstream& is, TStringLookupValidator*& v )
  290.     { return is >> (void *&)v; }
  291.  
  292. inline opstream& operator << ( opstream& os, TStringLookupValidator& v )
  293.     { return os << (TStreamable&)v; }
  294. inline opstream& operator << ( opstream& os, TStringLookupValidator* v )
  295.     { return os << (TStreamable *)v; }
  296.  
  297.  
  298. #endif
  299.