home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / name.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-19  |  1.6 KB  |  77 lines

  1. /*
  2.  * Name.C - methods for space efficient name storage.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include "Name.h"
  19. #include "Hash.h"
  20.  
  21. implementList(rcStringList, rcStringPtr);
  22. implementList(NameList, NamePtr);
  23.  
  24. //___________________________________________________________ Name
  25.  
  26. rcStringList* Name::GlobalNameSpace = new rcStringList(100);
  27.  
  28. // the string name will be copied 
  29. Name::Name(const char* name)
  30. {
  31.   index_ = addname(name);
  32. }
  33.  
  34. // the string name will be copied 
  35. Name::Name(const rcString* name)
  36. {
  37.   index_ = addname(name->chars());
  38. }
  39.  
  40. const Name& Name::operator=(const Name& aName)
  41. {
  42.   index_ = aName.index_;
  43.   return *this;
  44. }
  45.  
  46. Name::operator const char*() const
  47. {
  48.   return GlobalNameSpace->item(index_)->chars();
  49. }
  50.  
  51. long Name::addname(const char* name)
  52. {
  53.   int found = 0;
  54.   register long i;
  55.   
  56.   // is the name already in the list?
  57.   for (i=0; i<GlobalNameSpace->count(); i++) 
  58.     if (*GlobalNameSpace->item(i) == name) {
  59.       found = 1;
  60.       break;
  61.     }
  62.  
  63.   // not in the list yet -> append it
  64.   if (!found) 
  65.     GlobalNameSpace->append(new rcString(name));
  66.  
  67.   return i;
  68. }
  69.  
  70. ostream& operator<<(ostream& os, const Name& aName)
  71. {
  72.   return os << (const char*) aName;
  73. }
  74.  
  75.  
  76.  
  77.