home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / LOOKVAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  4.6 KB  |  232 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1993, 1994 by Borland International, All Rights Reserved
  4. //
  5. //----------------------------------------------------------------------------
  6. #pragma hdrignore SECTION
  7. #include <owl/owlpch.h>
  8. #include <owl/validate.h>
  9. #include <owl/applicat.h>
  10. #include <owl/appdict.h>
  11. #include <owl/framewin.h>
  12.  
  13. #if !defined(SECTION) || SECTION == 1
  14.  
  15. //
  16. // TLookupValidator
  17. //
  18.  
  19. TLookupValidator::TLookupValidator()
  20. {
  21. }
  22.  
  23. bool
  24. TLookupValidator::IsValid(const char far* str)
  25. {
  26.   return Lookup(str);
  27. }
  28.  
  29. bool
  30. TLookupValidator::Lookup(const char far* /*str*/)
  31. {
  32.   return true;
  33. }
  34.  
  35. //----------------------------------------------------------------------------
  36.  
  37. //
  38. // TSortedStringArray implementation
  39. //
  40. TSortedStringArray::TSortedStringArray(int upper, int lower, int delta)
  41. :
  42.   Data(upper, lower, delta)
  43. {
  44. }
  45.  
  46. int TSortedStringArray::LowerBound() const
  47. {
  48.   return Data.LowerBound();
  49. }
  50.  
  51. int TSortedStringArray::UpperBound() const
  52. {
  53.   return Data.UpperBound();
  54. }
  55.  
  56. unsigned TSortedStringArray::ArraySize() const
  57. {
  58.   return Data.ArraySize();
  59. }
  60.  
  61. int TSortedStringArray::IsFull() const
  62. {
  63.   return Data.IsFull();
  64. }
  65.  
  66. int TSortedStringArray::IsEmpty() const
  67. {
  68.   return Data.IsEmpty();
  69. }
  70.  
  71. unsigned TSortedStringArray::GetItemsInContainer() const
  72. {
  73.   return Data.GetItemsInContainer();
  74. }
  75.  
  76. int TSortedStringArray::Add(const string& t)
  77. {
  78.   return Data.Add(t);
  79. }
  80.  
  81. int TSortedStringArray::Detach(const string& t)
  82. {
  83.   return Data.Detach(t);
  84. }
  85.  
  86. int TSortedStringArray::Detach(int loc)
  87. {
  88.   return Data.Detach(loc);
  89. }
  90.  
  91. int TSortedStringArray::Destroy(const string& t)
  92. {
  93.   return Detach(t);
  94. }
  95.  
  96. int TSortedStringArray::Destroy(int loc)
  97. {
  98.   return Detach(loc);
  99. }
  100.  
  101. int TSortedStringArray::HasMember(const string& t) const
  102. {
  103.   return Data.HasMember(t);
  104. }
  105.  
  106. int TSortedStringArray::Find(const string& t) const
  107. {
  108.   return Data.Find(t);
  109. }
  110.  
  111. string& TSortedStringArray::operator [](int loc)
  112. {
  113.   return Data[loc];
  114. }
  115.  
  116. string& TSortedStringArray::operator [](int loc) const
  117. {
  118.   return Data[loc];
  119. }
  120.  
  121. void TSortedStringArray::ForEach(IterFunc iter, void* args)
  122. {
  123.   Data.ForEach(iter, args);
  124. }
  125.  
  126. string* TSortedStringArray::FirstThat(CondFunc cond, void* args) const
  127. {
  128.   return Data.FirstThat(cond, args);
  129. }
  130.  
  131. string* TSortedStringArray::LastThat(CondFunc cond, void* args) const
  132. {
  133.   return Data.LastThat(cond, args);
  134. }
  135.  
  136. void TSortedStringArray::Flush()
  137. {
  138.   Data.Flush();
  139. }
  140.  
  141. //----------------------------------------------------------------------------
  142.  
  143. //
  144. // TStringLookupValidator
  145. //
  146.  
  147. TStringLookupValidator::TStringLookupValidator(TSortedStringArray* strings)
  148. :
  149.   TLookupValidator()
  150. {
  151.   Strings = strings ? strings : new TSortedStringArray(0, 0, 0);
  152. }
  153.  
  154. TStringLookupValidator::~TStringLookupValidator()
  155. {
  156.   delete Strings;
  157. }
  158.  
  159. void
  160. TStringLookupValidator::Error()
  161. {
  162.   TApplication* app = GetApplicationObject();
  163.   const char* msg = app->LoadString(IDS_VALNOTINLIST).c_str();
  164.   TWindow* w = GetWindowPtr(app->GetMainWindow()->GetLastActivePopup());
  165.   if (w)
  166.     w->MessageBox(msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK);
  167.   else
  168.     ::MessageBox(0, msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL);
  169. }
  170.  
  171. bool
  172. TStringLookupValidator::Lookup(const char far* str)
  173. {
  174.   if (Strings)
  175.     return Strings->HasMember(str);
  176.   return false;
  177. }
  178.  
  179. void
  180. TStringLookupValidator::NewStringList(TSortedStringArray* strings)
  181. {
  182.   delete Strings;
  183.   Strings = strings;
  184. }
  185.  
  186. #endif
  187.  
  188. #if !defined(SECTION) || SECTION == 2
  189. IMPLEMENT_STREAMABLE1(TLookupValidator, TValidator);
  190.  
  191. void*
  192. TLookupValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  193. {
  194.   ReadBaseObject((TValidator*)GetObject(), is);
  195.   return GetObject();
  196. }
  197.  
  198. void
  199. TLookupValidator::Streamer::Write(opstream& os) const
  200. {
  201.   WriteBaseObject((TValidator*)GetObject(), os);
  202. }
  203.  
  204. IMPLEMENT_STREAMABLE1(TStringLookupValidator, TLookupValidator);
  205.  
  206. void*
  207. TStringLookupValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  208. {
  209.   ReadBaseObject((TLookupValidator*)GetObject(), is);
  210.   unsigned count;
  211.   is >> count;
  212.   GetObject()->Strings = new TSortedStringArray(count, 0, 5);
  213.   for (unsigned i = 0; i < count; i++ ) {
  214.     string temp;
  215.     is >> temp;
  216.     GetObject()->Strings->Add(temp);
  217.   }
  218.   return GetObject();
  219. }
  220.  
  221. void
  222. TStringLookupValidator::Streamer::Write(opstream& os) const
  223. {
  224.   WriteBaseObject((TLookupValidator*)GetObject(), os);
  225.   unsigned count = GetObject()->Strings->GetItemsInContainer();
  226.   os << count;
  227.   for (unsigned i = 0; i < count; i++)
  228.     os << (*GetObject()->Strings)[i];
  229. }
  230.  
  231. #endif
  232.