home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / g / gina15.zip / demos / Address.C < prev    next >
C/C++ Source or Header  |  1992-02-27  |  9KB  |  248 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. //   Module      : Address.C   Version 1.8
  4. //   LastSCCS    : 7/29/91  18:00:03
  5. //   LastEdit    : "Thu Mar  7 10:53:21 1991"
  6. //   Description : 
  7. //   Author      : 
  8. //   Copyright   : GMD Schloss Birlinghoven
  9.  
  10.  
  11. #include "Address.h"
  12. #include "ArrayOb.h"
  13. #include "nihclIO.h"
  14.  
  15. #define    THIS    Address
  16. #define    BASE    Object
  17. #define    BASE_CLASSES BASE::desc()
  18.  
  19. #define    MEMBER_CLASSES String::desc(), String::desc(), String::desc(), \
  20.                        String::desc(), String::desc(), String::desc(), \
  21.                        String::desc(), String::desc(), String::desc(), \
  22.                        String::desc(), Date::desc(), Date::desc(), \
  23.                        Integer::desc()
  24.  
  25. #define VIRTUAL_BASE_CLASSES
  26.  
  27. DEFINE_CLASS(Address,1,"@(#)Address.C    1.8 7/29/91",NULL,NULL);
  28.  
  29. bool Address::operator==(const Address& a) const
  30. // Test two instances of Address for equality
  31. {
  32.     return (*the_last_name     == *a.the_last_name)
  33.     && (*the_first_names   == *a.the_first_names)
  34.     && (*the_street        == *a.the_street)
  35.     && (*the_house_number  == *a.the_house_number)
  36.     && (*the_country_code  == *a.the_country_code)
  37.     && (*the_city_code     == *a.the_city_code)
  38.     && (*the_city          == *a.the_city)
  39.     && (*the_local_area    == *a.the_local_area)
  40.     && (*the_telephone     == *a.the_telephone)
  41.     && (*the_email         == *a.the_email)
  42.     && (*the_creation_date == *a.the_creation_date)
  43.     && (*the_last_modified == *a.the_last_modified)
  44.         && (the_key_number->value()    == a.the_key_number->value());
  45. }
  46.  
  47. const Class* Address::species() const
  48. // Return a pointer to the descriptor of the species of this class
  49. {
  50.     return &classDesc;
  51. }
  52.  
  53. bool Address::isEqual(const Object& p) const
  54. // Test two objects for equality
  55. {
  56.     return p.isSpecies(classDesc) && *this==castdown(p);
  57. }
  58.  
  59. unsigned Address::hash() const
  60. // If two objects are equal (i.e., isEqual) they must have
  61. // the same hash
  62. {
  63.     return the_last_name->hash() ^ the_first_names->hash() ^
  64.            the_street->hash() ^  the_house_number->hash() ^
  65.            the_country_code->hash() ^ the_city_code->hash() ^
  66.            the_city->hash() ^  the_local_area->hash() ^
  67.            the_telephone->hash() ^ the_email->hash() ^
  68.            the_creation_date->hash() ^ the_last_modified->hash() ^
  69.            the_key_number->hash();
  70. }
  71.  
  72. #define DO_COMPARE_MEMBER(m, obj) { int r = m->compare(*(obj.m)); \
  73.                    if(r) return(r);}
  74.  
  75. int Address::compare(const Object& p) const
  76. // Compare two objects.  If *this > p return >0,
  77. // *this == p return 0, and if *this < p return <0.
  78. {
  79.     assertArgSpecies(p,classDesc,"compare");
  80.     const Address & the_obj = (const Address &)p;
  81.     DO_COMPARE_MEMBER(the_last_name, the_obj);
  82.     DO_COMPARE_MEMBER(the_first_names, the_obj);
  83.     DO_COMPARE_MEMBER(the_street, the_obj);
  84.     DO_COMPARE_MEMBER(the_house_number, the_obj);
  85.     DO_COMPARE_MEMBER(the_country_code, the_obj);
  86.     DO_COMPARE_MEMBER(the_city_code, the_obj);
  87.     DO_COMPARE_MEMBER(the_city, the_obj);
  88.     DO_COMPARE_MEMBER(the_local_area, the_obj);
  89.     DO_COMPARE_MEMBER(the_telephone, the_obj);
  90.     DO_COMPARE_MEMBER(the_email, the_obj);
  91.     DO_COMPARE_MEMBER(the_creation_date, the_obj);
  92.     DO_COMPARE_MEMBER(the_key_number, the_obj);
  93.     return the_last_modified->compare(*the_obj.the_last_modified);
  94. }
  95.  
  96. void Address::deepenShallowCopy()
  97. {
  98.     the_last_name = (String *)the_last_name->deepCopy();
  99.     the_first_names = (String *)the_first_names->deepCopy();
  100.     the_street= (String *) the_street->deepCopy();
  101.     the_house_number = (String *)the_house_number->deepCopy();
  102.     the_country_code = (String *)the_country_code->deepCopy();
  103.     the_city_code = (String *)the_city_code->deepCopy();
  104.     the_city = (String *)the_city->deepCopy();
  105.     the_local_area = (String *)the_local_area->deepCopy();
  106.     the_telephone = (String *)the_telephone->deepCopy();
  107.     the_email = (String *)the_email->deepCopy();
  108.     the_creation_date = (Date *)the_creation_date->deepCopy();
  109.     the_last_modified = (Date *)the_last_modified->deepCopy();
  110.     the_key_number = (Integer *)the_key_number->deepCopy();
  111. }
  112.  
  113. void Address::printOn(ostream& strm) const
  114. // Print this object on an ostream
  115. {
  116.     strm << endl << *the_last_name << ", " << *the_first_names << endl;
  117.     strm << *the_street << " " << *the_house_number << endl;
  118.     strm << *the_country_code << "-" << *the_city_code << " ";
  119.     strm << *the_city << " " << *the_local_area << endl;
  120.     strm << "Telephone: " << *the_telephone << endl;
  121.     strm << "Email:     " << *the_email << endl;
  122.     strm << "Created:   " << *the_creation_date << endl;
  123.     strm << "Modified:  " << *the_last_modified << endl;
  124.     strm << "Index:     " << *the_key_number << endl;
  125. }
  126.  
  127. Address::Address(OIOin& strm)
  128. : BASE(strm)
  129. {
  130.     the_last_name = String::readFrom(strm);
  131.     the_first_names = String::readFrom(strm);
  132.     the_street = String::readFrom(strm);
  133.     the_house_number = String::readFrom(strm);
  134.     the_country_code = String::readFrom(strm);
  135.     the_city_code = String::readFrom(strm);
  136.     the_city = String::readFrom(strm);
  137.     the_local_area = String::readFrom(strm);
  138.     the_telephone = String::readFrom(strm);
  139.     the_email = String::readFrom(strm);
  140.     the_creation_date = Date::readFrom(strm);
  141.     the_last_modified = Date::readFrom(strm);
  142.     the_key_number = Integer::readFrom(strm);
  143. }
  144.  
  145. void Address::storer(OIOout& strm) const
  146. {
  147.     BASE::storer(strm);
  148.     the_last_name->storeOn(strm);
  149.     the_first_names->storeOn(strm);
  150.     the_street->storeOn(strm);
  151.     the_house_number->storeOn(strm);
  152.     the_country_code->storeOn(strm);
  153.     the_city_code->storeOn(strm);
  154.     the_city->storeOn(strm);
  155.     the_local_area->storeOn(strm);
  156.     the_telephone->storeOn(strm);
  157.     the_email->storeOn(strm);
  158.     the_creation_date->storeOn(strm);
  159.     the_last_modified->storeOn(strm);
  160.     the_key_number->storeOn(strm);
  161. }
  162.  
  163. Address::Address(OIOifd& fd)
  164. : BASE(fd)
  165. {
  166.     the_last_name = String::readFrom(fd);
  167.     the_first_names = String::readFrom(fd);
  168.     the_street = String::readFrom(fd);
  169.     the_house_number = String::readFrom(fd);
  170.     the_country_code = String::readFrom(fd);
  171.     the_city_code = String::readFrom(fd);
  172.     the_city = String::readFrom(fd);
  173.     the_local_area = String::readFrom(fd);
  174.     the_telephone = String::readFrom(fd);
  175.     the_email = String::readFrom(fd);
  176.     the_creation_date = Date::readFrom(fd);
  177.     the_last_modified = Date::readFrom(fd);
  178.     the_key_number = Integer::readFrom(fd);
  179. }
  180.  
  181. void Address::storer(OIOofd& fd) const
  182. {
  183.     BASE::storer(fd);
  184.     the_last_name->storeOn(fd);
  185.     the_first_names->storeOn(fd);
  186.     the_street->storeOn(fd);
  187.     the_house_number->storeOn(fd);
  188.     the_country_code->storeOn(fd);
  189.     the_city_code->storeOn(fd);
  190.     the_city->storeOn(fd);
  191.     the_local_area->storeOn(fd);
  192.     the_telephone->storeOn(fd);
  193.     the_email->storeOn(fd);
  194.     the_creation_date->storeOn(fd);
  195.     the_last_modified->storeOn(fd);
  196.     the_key_number->storeOn(fd);
  197. }
  198.  
  199. // New constructor
  200.  
  201. Address::Address(const String* last_name, const String* first_names,
  202.          const String* street, const String* house_number,
  203.          const String* country_code, const String* city_code,
  204.          const String* city, const String* local_area,
  205.          const String* telephone, const String* email,
  206.          const Date* creation_date, const Date* last_modified,
  207.          const Integer *key_number, bool copy_members)
  208. {
  209.     the_last_name     = copy_members ? new String(*last_name) : last_name;
  210.     the_first_names   = copy_members ? new String(*first_names) : first_names;
  211.     the_street        = copy_members ? new String(*street) : street;
  212.     the_house_number  = copy_members ? new String(*house_number) : house_number;
  213.     the_country_code  = copy_members ? new String(*country_code) : country_code;
  214.     the_city_code     = copy_members ? new String(*city_code) : city_code;
  215.     the_city          = copy_members ? new String(*city) : city;
  216.     the_local_area    = copy_members ? new String(*local_area) : local_area;
  217.     the_telephone     = copy_members ? new String(*telephone) : telephone;
  218.     the_email         = copy_members ? new String(*email) : email;
  219.     the_creation_date = copy_members ? new Date(*creation_date) : creation_date;
  220.     the_last_modified = copy_members ? new Date(*last_modified) : last_modified;
  221.     the_key_number    = copy_members ? new Integer(*key_number) : key_number;
  222. }
  223.  
  224. // Destructor
  225.  
  226. Address::
  227. ~Address()
  228. {
  229.     delete the_last_name;
  230.     delete the_first_names;
  231.     delete the_street;
  232.     delete the_house_number;
  233.     delete the_country_code;
  234.     delete the_city_code;
  235.     delete the_city;
  236.     delete the_local_area;
  237.     delete the_telephone;
  238.     delete the_email;
  239.     delete the_creation_date;
  240.     delete the_last_modified;
  241.     delete the_key_number;
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248.