You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Turbo Vision - Version 2.0
  3. *
  4. * Copyright (c) 1994 by Borland International
  5. * All Rights Reserved.
  6. *
  7. Modified by Robert H�hne to be used for RHIDE.
  8. *
  9. *
  10. */
  11. #if defined(Uses_TValidator) && !defined(__TValidator)
  12. #define __TValidator
  13. const ushort
  14. // TValidator Status constants
  15. vsOk = 0,
  16. vsSyntax = 1,
  17. // Validator option flags
  18. voFill = 0x0001,
  19. voTransfer = 0x0002,
  20. voOnAppend = 0x0004,
  21. voReserved = 0x00F8;
  22. typedef enum {
  23. vtDataSize,
  24. vtSetData,
  25. vtGetData
  26. } TVTransfer;
  27. class TInputLineBase;
  28. // Abstract TValidator object
  29. class TValidator : public TObject
  30. #if !defined( NO_STREAM )
  31. , protected TStreamable
  32. #endif // NO_STREAM
  33. {
  34. public:
  35. ushort Status;
  36. ushort Options;
  37. TValidator();
  38. virtual void Error() = 0;
  39. virtual Boolean IsValidInput(char *,Boolean);
  40. virtual Boolean IsValid(const char *);
  41. virtual ushort Transfer(char *,void *,TVTransfer);
  42. virtual void Format(char *source);
  43. Boolean Valid(const char *);
  44. void SetOwner(TInputLineBase *owner) { Owner = owner; }
  45. protected:
  46. TInputLineBase *Owner;
  47. #if !defined( NO_STREAM )
  48. private:
  49. virtual const char *streamableName() const
  50. { return name; }
  51. protected:
  52. TValidator( StreamableInit );
  53. public:
  54. static const char * const name;
  55. protected:
  56. virtual void write( opstream& );
  57. virtual void *read( ipstream& );
  58. #endif // NO_STREAM
  59. };
  60. class TFilterValidator : public TValidator
  61. {
  62. protected:
  63. char * ValidChars;
  64. public:
  65. TFilterValidator();
  66. TFilterValidator(const char *);
  67. ~TFilterValidator();
  68. virtual void Error();
  69. virtual Boolean IsValid(const char *);
  70. virtual Boolean IsValidInput(char *,Boolean);
  71. #if !defined( NO_STREAM )
  72. private:
  73. virtual const char *streamableName() const
  74. { return name; }
  75. protected:
  76. TFilterValidator( StreamableInit );
  77. public:
  78. static const char * const name;
  79. static TStreamable *build();
  80. protected:
  81. virtual void write( opstream& );
  82. virtual void *read( ipstream& );
  83. #endif // NO_STREAM
  84. };
  85. class TRangeValidator : public TFilterValidator
  86. {
  87. long Min,Max;
  88. public:
  89. TRangeValidator();
  90. TRangeValidator(long aMin,long aMax);
  91. virtual void Error();
  92. virtual Boolean IsValid(const char *);
  93. virtual ushort Transfer(char *,void *,TVTransfer);
  94. #if !defined( NO_STREAM )
  95. private:
  96. virtual const char *streamableName() const
  97. { return name; }
  98. protected:
  99. TRangeValidator( StreamableInit );
  100. public:
  101. static const char * const name;
  102. static TStreamable *build();
  103. protected:
  104. virtual void write( opstream& );
  105. virtual void *read( ipstream& );
  106. #endif // NO_STREAM
  107. };
  108. #if !defined( NO_STREAM )
  109. inline ipstream& operator >> ( ipstream& is, TValidator& cl )
  110. { return is >> (TStreamable&)cl; }
  111. inline ipstream& operator >> ( ipstream& is, TValidator*& cl )
  112. { return is >> (void *&)cl; }
  113. inline opstream& operator << ( opstream& os, TValidator& cl )
  114. { return os << (TStreamable&)cl; }
  115. inline opstream& operator << ( opstream& os, TValidator* cl )
  116. { return os << (TStreamable *)cl; }
  117. inline ipstream& operator >> ( ipstream& is, TFilterValidator& cl )
  118. { return is >> (TStreamable&)cl; }
  119. inline ipstream& operator >> ( ipstream& is, TFilterValidator*& cl )
  120. { return is >> (void *&)cl; }
  121. inline opstream& operator << ( opstream& os, TFilterValidator& cl )
  122. { return os << (TStreamable&)cl; }
  123. inline opstream& operator << ( opstream& os, TFilterValidator* cl )
  124. { return os << (TStreamable *)cl; }
  125. inline ipstream& operator >> ( ipstream& is, TRangeValidator& cl )
  126. { return is >> (TStreamable&)cl; }
  127. inline ipstream& operator >> ( ipstream& is, TRangeValidator*& cl )
  128. { return is >> (void *&)cl; }
  129. inline opstream& operator << ( opstream& os, TRangeValidator& cl )
  130. { return os << (TStreamable&)cl; }
  131. inline opstream& operator << ( opstream& os, TRangeValidator* cl )
  132. { return os << (TStreamable *)cl; }
  133. #endif // NO_STREAM
  134. #endif