home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / rapsheet / cppwv23 / iperson.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  18.4 KB  |  564 lines

  1. /******************************************************************************
  2. * .FILE:        iperson.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation for the class, IPerson                         *
  5. *                                                                             *
  6. * .CLASSES:     IPerson                                                       *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #include "iperson.hpp"
  25. #include <inotifev.hpp>
  26. #include <ireslib.hpp>
  27. #include "rap.h"
  28.  
  29. INotificationId IPerson::addressId = "IPerson::address";
  30. INotificationId IPerson::aliasListId = "IPerson::aliasList";
  31. INotificationId IPerson::birthDateId = "IPerson::birthDate";
  32. INotificationId IPerson::eyeColorId = "IPerson::eyeColor";
  33. INotificationId IPerson::firstNameId = "IPerson::firstName";
  34. INotificationId IPerson::genderId = "IPerson::gender";
  35. INotificationId IPerson::hairColorId = "IPerson::hairColor";
  36. INotificationId IPerson::heightId = "IPerson::height";
  37. INotificationId IPerson::infoId = "IPerson::info";
  38. INotificationId IPerson::lastNameId = "IPerson::lastName";
  39. INotificationId IPerson::weightId = "IPerson::weight";
  40.  
  41. /*------------------------------------------------------------------------------
  42.  | IPerson::IPerson
  43.  |
  44.  | Standard constructor.
  45.  -----------------------------------------------------------------------------*/
  46. IPerson :: IPerson() : IStandardNotifier (),
  47.   iAddress (new IAddress()),
  48.   iAliasList (new IVSequence<IAlias *> ()),
  49.   iBirthDate (""),
  50.   iEyeColor (0),
  51.   iFirstName ("John"),
  52.   iGender (0),
  53.   iHairColor (0),
  54.   iHeight (70),
  55.   iInfo (""),
  56.   iLastName ("Smith"),
  57.   iWeight (150)
  58. {
  59.   enableNotification();
  60.   iAddress->enableNotification();
  61.   iAliasList->enableNotification();
  62. }
  63.  
  64. /*------------------------------------------------------------------------------
  65.  | IPerson::IPerson
  66.  |
  67.  | Standard copy constructor.
  68.  -----------------------------------------------------------------------------*/
  69. IPerson :: IPerson (const IPerson& partCopy)
  70.   : IStandardNotifier (partCopy),
  71.   iAddress (new IAddress (*partCopy.address())),
  72.   iAliasList (new IVSequence <IAlias *> (*partCopy.aliasList())),
  73.   iBirthDate (partCopy.birthDate()),
  74.   iEyeColor (partCopy.eyeColor()),
  75.   iFirstName (partCopy.firstName()),
  76.   iGender (partCopy.gender()),
  77.   iHairColor (partCopy.hairColor()),
  78.   iHeight (partCopy.height()),
  79.   iInfo (partCopy.info()),
  80.   iLastName (partCopy.lastName()),
  81.   iWeight (partCopy.weight())
  82. {
  83.   enableNotification();
  84.   iAddress->enableNotification();
  85.   iAliasList->enableNotification();
  86. }
  87.  
  88. /*------------------------------------------------------------------------------
  89.  | IPerson::~IPerson
  90.  |
  91.  | Empty destructor here for page tuning.
  92.  -----------------------------------------------------------------------------*/
  93. IPerson :: ~IPerson()
  94. {
  95.   ISequence<IAlias *> tempList;
  96.   IAlias *            alias;
  97.  
  98.   if (iAddress)
  99.     delete iAddress;
  100.  
  101.   if (iAliasList)
  102.   {
  103.      IVSequence <IAlias*>::Cursor cursor(*iAliasList);
  104.      forCursor( cursor )
  105.        tempList.addAsFirst( iAliasList->elementAt( cursor ) );
  106.  
  107.      iAliasList->removeAll( );
  108.  
  109.      ISequence <IAlias*>::Cursor tempCursor( tempList );
  110.      forCursor( cursor )
  111.      {
  112.        alias = tempList.elementAt ( tempCursor );
  113.        delete alias;
  114.      }
  115.      tempList.removeAll( );
  116.  
  117.      delete iAliasList;
  118.   }
  119. }
  120.  
  121. /*------------------------------------------------------------------------------
  122.  | IPerson::IPerson
  123.  |
  124.  | Standard operator=
  125.  -----------------------------------------------------------------------------*/
  126. IPerson & IPerson :: operator= (const IPerson & aPerson)
  127. {
  128.   if (this == &aPerson)
  129.     return *this;
  130.  
  131.   IStandardNotifier::operator=(aPerson);
  132.   setAddress(new IAddress (*aPerson.address()));
  133.   setAliasList(new IVSequence <IAlias*> (*aPerson.aliasList()));
  134.   setBirthDate(aPerson.birthDate());
  135.   setEyeColor(aPerson.eyeColor());
  136.   setFirstName(aPerson.firstName());
  137.   setGender(aPerson.gender());
  138.   setHairColor(aPerson.hairColor());
  139.   setHeight(aPerson.height());
  140.   setInfo(aPerson.info());
  141.   setLastName(aPerson.lastName());
  142.   setWeight(aPerson.weight());
  143.  
  144.   return *this;
  145. }
  146.  
  147. /*------------------------------------------------------------------------------
  148.  | IPerson::asString                                                           |
  149.  |                                                                             |
  150.  | Perform asString.                                                           |
  151.  | NOTE: This also identifies what data should be displayed for an             |
  152.  |       ISuspect element of a list (that maps to the 'items' attribute        |
  153.  |       of a list box).                                                       |
  154.  -----------------------------------------------------------------------------*/
  155. IString IPerson :: asString () const
  156. {
  157.   return (lastName() + ", " + firstName());
  158. }
  159.  
  160. /*------------------------------------------------------------------------------
  161. | IPerson::asDebugInfo                                                         |
  162. |                                                                              |
  163. | Generate a string that identifies for debugging purposes what data           |
  164. | an ISuspect instance contains.                                               |
  165. |                                                                              |
  166. | NOTE: attributes not included:  iInfo.                                       |
  167. | NOTE: to see what some of the values map to, see the enumerations that       |
  168. |       are defined in IPerson.hpp.                                            |
  169. ------------------------------------------------------------------------------*/
  170. IString IPerson :: asDebugInfo () const
  171. {
  172.   IString debugInfo("lName=" + iLastName + ",");
  173.   debugInfo += "fName=" + iFirstName + ",";
  174. //debugInfo += iAddress->asDebugInfo();
  175.   debugInfo += "numAlias=" + IString(iAliasList->numberOfElements()) + ",";
  176.   debugInfo += "bdate=" + IString(iBirthDate) + ",";
  177.   debugInfo += "eyeColor=" + IString(iEyeColor) + ",";
  178.   debugInfo += "gender=" + IString(iGender) + ",";
  179.   debugInfo += "hairColor=" + IString(iHairColor) + ",";
  180.   debugInfo += "height=" + IString(iHeight) + ",";
  181.   debugInfo += "weight=" + IString(iWeight) + ",";
  182.  
  183.   return debugInfo;
  184. }
  185.  
  186.  
  187. /*------------------ Attribute Get/Set Member Functions ------------------------
  188.  -----------------------------------------------------------------------------*/
  189. /*------------------------------------------------------------------------------
  190.  | address
  191.  -----------------------------------------------------------------------------*/
  192. IAddress * IPerson::address() const
  193. {
  194.   return iAddress;
  195. }
  196.  
  197. IPerson & IPerson::setAddress(IAddress * aAddress)
  198. {
  199.   if (iAddress != aAddress)
  200.   {
  201.     if (iAddress)
  202.       delete iAddress;
  203.     iAddress = new IAddress(*aAddress);
  204.     notifyObservers(INotificationEvent(IPerson::addressId, *this));
  205.   } // endif
  206.   return *this;
  207. }
  208.  
  209. /*------------------------------------------------------------------------------
  210.  | aliasList
  211.  -----------------------------------------------------------------------------*/
  212. IVSequence<IAlias *> * IPerson::aliasList() const
  213. {
  214.   return iAliasList;
  215. }
  216.  
  217. IPerson & IPerson::setAliasList(IVSequence<IAlias *> * aAliasList)
  218. {
  219.   if (iAliasList != aAliasList)
  220.   {
  221.     iAliasList->removeAll();
  222.     iAliasList->addAllFrom(*aAliasList);
  223. //  notifyObservers(INotificationEvent(IPerson::aliasListId, *this));
  224.   } // endif
  225.   return *this;
  226. }
  227.  
  228. /*------------------------------------------------------------------------------
  229.  | birthDate
  230.  -----------------------------------------------------------------------------*/
  231. IString IPerson::birthDate() const
  232. {
  233.   return iBirthDate;
  234. }
  235.  
  236. IPerson & IPerson::setBirthDate(const IString & aBirthDate)
  237. {
  238.   if (iBirthDate != aBirthDate)
  239.   {
  240.     iBirthDate = aBirthDate;
  241.     notifyObservers(INotificationEvent(IPerson::birthDateId, *this));
  242.   } // endif
  243.   return *this;
  244. }
  245.  
  246. /*------------------------------------------------------------------------------
  247.  | eyeColorAsString, eyeColor
  248.  -----------------------------------------------------------------------------*/
  249. IString IPerson::eyeColorAsString() const
  250. {
  251.   IString eyeColor;
  252.   switch (iEyeColor)
  253.   {
  254.      case blue_eyes:
  255.         eyeColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLUE_EYES_STR);
  256.         break;
  257.      case brown_eyes:
  258.         eyeColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(BROWN_EYES_STR);
  259.         break;
  260.      case green_eyes:
  261.         eyeColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(GREEN_EYES_STR);
  262.         break;
  263.      case hazel_eyes:
  264.         eyeColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(HAZEL_EYES_STR);
  265.         break;
  266.   }
  267.   return eyeColor;
  268. }
  269.  
  270. IPerson & IPerson::setEyeColorAsString(const IString & aEyeColor)
  271. {
  272.   if (aEyeColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLUE_EYES_STR))
  273.      setEyeColor(blue_eyes);
  274.   else if (aEyeColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(BROWN_EYES_STR))
  275.      setEyeColor(brown_eyes);
  276.   else if (aEyeColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(GREEN_EYES_STR))
  277.      setEyeColor(green_eyes);
  278.   else if (aEyeColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(HAZEL_EYES_STR))
  279.      setEyeColor(hazel_eyes);
  280.   return *this;
  281. }
  282.  
  283. unsigned short IPerson::eyeColor() const
  284. {
  285.   return iEyeColor;
  286. }
  287.  
  288. IPerson & IPerson::setEyeColor(const unsigned short aEyeColor)
  289. {
  290.   if (iEyeColor != aEyeColor)
  291.   {
  292.     iEyeColor = aEyeColor;
  293.     notifyObservers(INotificationEvent(IPerson::eyeColorId, *this));
  294.   } // endif
  295.   return *this;
  296. }
  297.  
  298. /*------------------------------------------------------------------------------
  299.  | firstName
  300.  -----------------------------------------------------------------------------*/
  301. IString IPerson::firstName() const
  302. {
  303.   return iFirstName;
  304. }
  305.  
  306. IPerson & IPerson::setFirstName(const IString & aFirstName)
  307. {
  308.   if (iFirstName != aFirstName)
  309.   {
  310.     iFirstName = aFirstName;
  311.     notifyObservers(INotificationEvent(IPerson::firstNameId, *this));
  312.   } // endif
  313.   return *this;
  314. }
  315.  
  316. /*------------------------------------------------------------------------------
  317.  | gender/isMale
  318.  -----------------------------------------------------------------------------*/
  319. unsigned short IPerson::gender() const
  320. {
  321.   return iGender;
  322. }
  323.  
  324. IPerson & IPerson::setGender(const unsigned short aGender)
  325. {
  326.   if (iGender != aGender)
  327.   {
  328.     iGender = aGender;
  329.     notifyObservers(INotificationEvent(IPerson::genderId, *this));
  330.   } // endif
  331.   return *this;
  332. }
  333.  
  334. Boolean IPerson::isMale() const
  335. {
  336.   Boolean gender;
  337.   if (iGender == male)
  338.     gender = true;
  339.   else
  340.     gender = false;
  341.   return gender;
  342. }
  343.  
  344. IPerson & IPerson::enableIsMale(Boolean aGender)
  345. {
  346.   if (aGender)
  347.     setGender(male);
  348.   else
  349.     setGender(female);
  350.   return *this;
  351. }
  352.  
  353. /*------------------------------------------------------------------------------
  354.  | hairColorAsString, hairColor
  355.  -----------------------------------------------------------------------------*/
  356. IString IPerson::hairColorAsString() const
  357. {
  358.   IString hairColor;
  359.   switch (iHairColor)
  360.   {
  361.      case no_hair:
  362.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(NO_HAIR_STR);
  363.         break;
  364.      case black_hair:
  365.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLACK_HAIR_STR);
  366.         break;
  367.      case blonde_hair:
  368.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLONDE_HAIR_STR);
  369.         break;
  370.      case brown_hair:
  371.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(BROWN_HAIR_STR);
  372.         break;
  373.      case grey_hair:
  374.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(GREY_HAIR_STR);
  375.         break;
  376.      case red_hair:
  377.         hairColor = IDynamicLinkLibrary("cppwv23r").tryToLoadString(RED_HAIR_STR);
  378.         break;
  379.   }
  380.   return hairColor;
  381. }
  382.  
  383. IPerson & IPerson::setHairColorAsString(const IString & aHairColor)
  384. {
  385.   if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(NO_HAIR_STR))
  386.      setHairColor(no_hair);
  387.   else if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLACK_HAIR_STR))
  388.      setHairColor(black_hair);
  389.   else if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(BLONDE_HAIR_STR))
  390.      setHairColor(blonde_hair);
  391.   else if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(BROWN_HAIR_STR))
  392.      setHairColor(brown_hair);
  393.   else if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(GREY_HAIR_STR))
  394.      setHairColor(grey_hair);
  395.   else if (aHairColor == IDynamicLinkLibrary("cppwv23r").tryToLoadString(RED_HAIR_STR))
  396.      setHairColor(red_hair);
  397.   return *this;
  398. }
  399.  
  400. unsigned short IPerson::hairColor() const
  401. {
  402.   return iHairColor;
  403. }
  404.  
  405. IPerson & IPerson::setHairColor(const unsigned short aHairColor)
  406. {
  407.   if (iHairColor != aHairColor)
  408.   {
  409.     iHairColor = aHairColor;
  410.     notifyObservers(INotificationEvent(IPerson::hairColorId, *this));
  411.   } // endif
  412.   return *this;
  413. }
  414.  
  415. /*------------------------------------------------------------------------------
  416.  | heightAsString, height
  417.  -----------------------------------------------------------------------------*/
  418. IString IPerson::heightAsString() const
  419. {
  420.   return IString(iHeight);
  421. }
  422.  
  423. IPerson & IPerson::setHeightAsString(const IString & aHeight)
  424. {
  425.   setHeight(aHeight.asUnsigned());
  426.   return *this;
  427. }
  428.  
  429. unsigned short IPerson::height() const
  430. {
  431.   return iHeight;
  432. }
  433.  
  434. IPerson & IPerson::setHeight(const unsigned short aHeight)
  435. {
  436.   if (iHeight != aHeight)
  437.   {
  438.     iHeight = aHeight;
  439.     notifyObservers(INotificationEvent(IPerson::heightId, *this));
  440.   } // endif
  441.   return *this;
  442. }
  443.  
  444. /*------------------------------------------------------------------------------
  445.  | info
  446.  -----------------------------------------------------------------------------*/
  447. IString IPerson::info() const
  448. {
  449.   return iInfo;
  450. }
  451.  
  452. IPerson & IPerson::setInfo(const IString & aInfo)
  453. {
  454.   if (iInfo != aInfo)
  455.   {
  456.     iInfo = aInfo;
  457.     notifyObservers(INotificationEvent(IPerson::infoId, *this));
  458.   } // endif
  459.   return *this;
  460. }
  461.  
  462. /*------------------------------------------------------------------------------
  463.  | lastName
  464.  -----------------------------------------------------------------------------*/
  465. IString IPerson::lastName() const
  466. {
  467.   return iLastName;
  468. }
  469.  
  470. IPerson & IPerson::setLastName(const IString & aLastName)
  471. {
  472.   if (iLastName != aLastName)
  473.   {
  474.     iLastName = aLastName;
  475.     notifyObservers(INotificationEvent(IPerson::lastNameId, *this));
  476.   } // endif
  477.   return *this;
  478. }
  479.  
  480. /*------------------------------------------------------------------------------
  481.  | weightAsString, weight
  482.  -----------------------------------------------------------------------------*/
  483. IString IPerson::weightAsString() const
  484. {
  485.   return IString(iWeight);
  486. }
  487.  
  488. IPerson & IPerson::setWeightAsString(const IString & aWeight)
  489. {
  490.   setHeight(aWeight.asUnsigned());
  491.   return *this;
  492. }
  493.  
  494. unsigned short IPerson::weight() const
  495. {
  496.   return iWeight;
  497. }
  498.  
  499. IPerson & IPerson::setWeight(const unsigned short aWeight)
  500. {
  501.   if (iWeight != aWeight)
  502.   {
  503.     iWeight = aWeight;
  504.     notifyObservers(INotificationEvent(IPerson::weightId, *this));
  505.   } // endif
  506.   return *this;
  507. }
  508.  
  509. /*------------------------------------------------------------------------------
  510.  | IPerson::operator == (const IPerson & value)
  511.  -----------------------------------------------------------------------------*/
  512. Boolean IPerson::operator == (const IPerson & value) const
  513. {
  514.   if (lastName() != value.lastName())
  515.     return false;
  516.   if (firstName() != value.firstName())
  517.     return false;
  518.   if (address() != value.address())
  519.     return false;
  520.   return true;
  521. }
  522.  
  523. /*------------------------------------------------------------------------------
  524.  | IPerson::operator != (const IPerson & value)
  525.  -----------------------------------------------------------------------------*/
  526. Boolean IPerson::operator != (const IPerson & value) const
  527. {
  528.   if (lastName() != value.lastName())
  529.     return true;
  530.   if (firstName() != value.firstName())
  531.     return true;
  532.   if (address() != value.address())
  533.     return true;
  534.   return false;
  535. }
  536.  
  537. /*------------------------------------------------------------------------------
  538.  | IPerson::operator == (const IPerson * value)
  539.  -----------------------------------------------------------------------------*/
  540. Boolean IPerson::operator == (const IPerson * value) const
  541. {
  542.   if (lastName() != value->lastName())
  543.     return false;
  544.   if (firstName() != value->firstName())
  545.     return false;
  546.   if (address() != value->address())
  547.     return false;
  548.   return true;
  549. }
  550.  
  551. /*------------------------------------------------------------------------------
  552.  | IPerson::operator != (const IPerson * value)
  553.  -----------------------------------------------------------------------------*/
  554. Boolean IPerson::operator != (const IPerson * value) const
  555. {
  556.   if (lastName() != value->lastName())
  557.     return true;
  558.   if (firstName() != value->firstName())
  559.     return true;
  560.   if (address() != value->address())
  561.     return true;
  562.   return false;
  563. }
  564.