home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / LOOKVAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  2.5 KB  |  121 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //   source\owl\lookval.cpp
  4. //----------------------------------------------------------------------------
  5. #pragma hdrignore SECTION
  6. #include <owl\owlpch.h>
  7. #include <owl\validate.h>
  8. #include <owl\applicat.h>
  9. #include <classlib\objstrm.h>
  10.  
  11. #if !defined(SECTION) || SECTION == 1
  12.  
  13. //
  14. // TLookupValidator
  15. //
  16.  
  17. TLookupValidator::TLookupValidator()
  18. {
  19. }
  20.  
  21. BOOL
  22. TLookupValidator::IsValid(const char far* str)
  23. {
  24.   return Lookup(str);
  25. }
  26.  
  27. BOOL
  28. TLookupValidator::Lookup(const char far* /*str*/)
  29. {
  30.   return TRUE;
  31. }
  32.  
  33. //
  34. // TStringLookupValidator
  35. //
  36.  
  37. TStringLookupValidator::TStringLookupValidator(TSortedStringArray* strings)
  38.   : TLookupValidator()
  39. {
  40.   Strings = strings ? strings : new TSortedStringArray(0, 0, 0);
  41. }
  42.  
  43. TStringLookupValidator::~TStringLookupValidator()
  44. {
  45.   delete Strings;
  46. }
  47.  
  48. void
  49. TStringLookupValidator::Error()
  50. {
  51.   ::MessageBox(0, string(*GetApplicationObject(), IDS_VALNOTINLIST).c_str(),
  52.              GetApplicationObject()->GetName(),
  53.              MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
  54. }
  55.  
  56. BOOL
  57. TStringLookupValidator::Lookup(const char far* str)
  58. {
  59.   if (Strings)
  60.     return Strings->HasMember(str);
  61.   return FALSE;
  62. }
  63.  
  64. void
  65. TStringLookupValidator::NewStringList(TSortedStringArray* strings)
  66. {
  67.   delete Strings;
  68.   Strings = strings;
  69. }
  70.  
  71.  
  72. #endif
  73.  
  74. #if !defined(SECTION) || SECTION == 2
  75. IMPLEMENT_STREAMABLE1(TLookupValidator, TValidator);
  76.  
  77. void*
  78. TLookupValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  79. {
  80.   ReadBaseObject((TValidator*)GetObject(), is);
  81.   return GetObject();
  82. }
  83.  
  84. void
  85. TLookupValidator::Streamer::Write(opstream& os) const
  86. {
  87.   WriteBaseObject((TValidator*)GetObject(), os);
  88. }
  89.  
  90.  
  91.  
  92. IMPLEMENT_STREAMABLE1(TStringLookupValidator, TLookupValidator);
  93.  
  94. void*
  95. TStringLookupValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  96. {
  97.   ReadBaseObject((TLookupValidator*)GetObject(), is);
  98.   unsigned count;
  99.   is >> count;
  100.   GetObject()->Strings = new TSortedStringArray(count, 0, 5);
  101.   for (unsigned i = 0; i < count; i++ ) {
  102.     string temp;
  103.     is >> temp;
  104.     GetObject()->Strings->Add(temp);
  105.   }
  106.   return GetObject();
  107. }
  108.  
  109. void
  110. TStringLookupValidator::Streamer::Write(opstream& os) const
  111. {
  112.   WriteBaseObject((TLookupValidator*)GetObject(), os);
  113.   unsigned count = GetObject()->Strings->GetItemsInContainer();
  114.   os << count;
  115.   for (unsigned i = 0; i < count; i++)
  116.     os << (*GetObject()->Strings)[i];
  117. }
  118.  
  119.  
  120. #endif
  121.