home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / todb101 / todb / lib / schema.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-27  |  4.0 KB  |  182 lines

  1. // ========================================================================
  2. //  TODB LIBRARY
  3. //    schema.cpp
  4. //
  5. //    Schema
  6. //
  7. //    Version: see TODB.H file
  8. //
  9. //    Copyright 1993 Christian Thérien
  10. //    All rights reserved
  11. // ========================================================================
  12.  
  13. #include "schema.h"
  14. #include <iomanip.h>
  15. #include <string.h>
  16.  
  17. //-------------------------------------------------------------------------
  18. // MakeTokenUW class
  19. //-------------------------------------------------------------------------
  20.  
  21. // make Upper case Word
  22. MakeTokenUW::MakeTokenUW()
  23. {
  24.     buf_ = NULL;
  25.     postoken_ = NULL;
  26.     length_ = 0;
  27. }
  28.  
  29. void MakeTokenUW::Put( const char * s )
  30. {
  31.     delete [] buf_;
  32.     length_ = strlen( s );
  33.     buf_ = new char[ length_ + 1 ];
  34.     strcpy( buf_, s );
  35. }
  36.  
  37. int MakeTokenUW::First( char * token )
  38. {
  39.     char seps[] = " !\"#$%&'()*+-,./:;<=>?@[\\]^_`{}|~";
  40.  
  41.     postoken_ = strtok( buf_, seps );
  42.     if ( postoken_ == NULL ) {
  43.     *token = 0;
  44.     return 0;
  45.     }
  46.     #ifdef MSC
  47.     _strupr( postoken_ );
  48.     #endif
  49.     #ifdef BCC
  50.     strupr( postoken_ );
  51.     #endif
  52.     strcpy( token, postoken_ );
  53.     return AcceptToken( token );
  54. }
  55.  
  56. int MakeTokenUW::Next( char * token )
  57. {
  58.     char seps[] = " !\"#$%&'()*+-,./:;<=>?@[\\]^_`{}|~";
  59.  
  60.     postoken_ = strtok( NULL, seps );
  61.     if ( postoken_ == NULL ) {
  62.     *token = 0;
  63.     return 0;
  64.     }
  65.     #ifdef MSC
  66.     _strupr( postoken_ );
  67.     #endif
  68.     #ifdef BCC
  69.     strupr( postoken_ );
  70.     #endif
  71.     strcpy( token, postoken_ );
  72.     return AcceptToken( token );
  73. }
  74.  
  75. // Exclude list
  76. int MakeTokenUW::AcceptToken( char * token )
  77. {
  78.     // reject single characters
  79.     if ( strlen( token ) == 1 )     return 0;
  80.  
  81.     if ( strcmp( token, "AN" ) == 0 )    return 0;
  82.     if ( strcmp( token, "THE" ) == 0 )    return 0;
  83.     if ( strcmp( token, "LA" ) == 0 )    return 0;
  84.     if ( strcmp( token, "LE" ) == 0 )    return 0;
  85.     if ( strcmp( token, "LES" ) == 0 )    return 0;
  86.  
  87.     return 1;
  88. }
  89.  
  90. //-------------------------------------------------------------------------
  91. // Count class
  92. //-------------------------------------------------------------------------
  93. // Count class implements a RECORD-ID generator.  Useful for the demo
  94. // program, this class is useless for a real life application.
  95. // On the other    hand, it give an example on using KSpersistent
  96. // class to save related data in the key set database.
  97.  
  98. Count::Count( KeyType countno ) :
  99.     KSPersistent( *ksDB, COUNT )
  100. {
  101.     LoadObject( countno );
  102. }
  103.  
  104. Count::Count() :
  105.     KSPersistent( *ksDB, COUNT )
  106. {
  107.     LoadObject( 1 );
  108. }
  109.  
  110. Count::~Count()
  111. {
  112.     ChangeObject();
  113.     SaveObject();
  114. }
  115.  
  116. void Count::SetCNote( KeyType cn )
  117. {
  118.     cnote_ = cn;
  119. }
  120.  
  121. void Count::SetVersion( String & vs )
  122. {
  123.     version_ = vs;
  124. }
  125.  
  126. Boolean Count::Dirty()
  127. {
  128.     return (Boolean)dirty_;
  129. }
  130.  
  131. void Count::SetDirty()
  132. {
  133.     dirty_ = 1;
  134. }
  135.  
  136. void Count::ResetDirty()
  137. {
  138.     dirty_ = 0;
  139. }
  140.  
  141. void Count::Read()
  142. {
  143.     ReadObject( version_ );
  144.     ReadObject( dirty_ );
  145.     ReadObject( cnote_ );
  146. }
  147.  
  148. void Count::Write()
  149. {
  150.     WriteObject( version_ );
  151.     WriteObject( dirty_ );
  152.     WriteObject( cnote_ );
  153. }
  154.  
  155. //-------------------------------------------------------------------------
  156. // BibNote class
  157. //-------------------------------------------------------------------------
  158.  
  159. BibNote::BibNote( KeyType nno ) :
  160.     IdxColl( *ksDB, BIBNOTE )
  161. {
  162.     noteno = nno;
  163. }
  164.  
  165. void BibNote::Delete()
  166. {
  167.     DeleteIdx();
  168. }
  169.  
  170. void BibNote::Index()
  171. {
  172.     IndexObject( noteno, TITLES, UW_token, title );
  173.     IndexObject( noteno, TITLES, UW_token, article_title );
  174.     IndexObject( noteno, SUBTITLES, UW_token, subtitle    );
  175.     IndexObject( noteno, SUBTITLES, UW_token, article_subtitle );
  176.     IndexObject( noteno, AUTHOR, UW_token, author );
  177.     IndexObject( noteno, PUBLISHER, UW_token, publisher );
  178.     IndexObject( noteno, KEYWORDS, UW_token, keywords );
  179.     IndexObject( noteno, DATE, UW_token, date );
  180.     IndexObject( noteno, PUB_PLACE, UW_token, publishing_place );
  181. }
  182.