home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / parody / key.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.1 KB  |  54 lines

  1. // ------------- key.cpp
  2.  
  3. #include "parody.h"
  4.  
  5. // ============================================
  6. // base Key class member functions
  7. // ============================================
  8.  
  9. Key::Key(NodeNbr fa) : LinkedListEntry(NULL)
  10. {
  11.     fileaddr = fa;
  12.     lowernode = 0;
  13.     relatedclass = -1;
  14.     classid = 0;
  15.     indexno = 0;
  16.     if (Persistent::thispers != NULL)    {
  17.         // --- register the key with the object being built
  18.         object = Persistent::thispers;
  19.         AppendListEntry(&object->keys);
  20.         classid = object->objhdr.classid;
  21.         indexno = object->indexcount++;
  22.     }
  23. }
  24.  
  25. // ------ overloaded =
  26. Key& Key::operator=(Key& key)
  27. {
  28.     if (this != &key)    {
  29.         fileaddr = key.fileaddr;
  30.         lowernode = key.lowernode;
  31.         indexno = key.indexno;
  32.         classid = key.classid;
  33.         relatedclass = key.relatedclass;
  34.     }
  35.     return *this;
  36. }
  37.  
  38. // --------- a key declares itself primary
  39. void Key::PrimaryKey()
  40. {
  41.     if (indexno != 0 && Persistent::thispers != NULL)    {
  42.         DeleteListEntry();
  43.         PrependListEntry();
  44.         Key *key = (Key *) NextListEntry();
  45.         while (key != NULL)    {
  46.             if (++(key->indexno) == indexno)
  47.                 break;
  48.             key = (Key *)(key->NextListEntry());
  49.         }
  50.         indexno = 0;
  51.         Persistent::thispers->RecordObject();
  52.     }
  53. }
  54.