home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / Name.C < prev    next >
C/C++ Source or Header  |  1992-11-20  |  2KB  |  78 lines

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