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

  1. /******************************************************************************
  2. * .FILE:        isuspect.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation for the class, ISuspect                        *
  5. *                                                                             *
  6. * .CLASSES:     ISuspect                                                      *
  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 "isuspect.hpp"
  25. #include <inotifev.hpp>
  26. #include <itrace.hpp>
  27.  
  28. /****************************************************************************
  29.  * Static Member Data Initializations
  30.  ****************************************************************************/
  31. const unsigned short ISuspect :: defaultMugId = 7;
  32. const IDynamicLinkLibrary ISuspect :: mugLib("cppwv23r");
  33.  
  34. INotificationId ISuspect::arrestListId = "ISuspect::arrestList";
  35. INotificationId ISuspect::bookNumberId = "ISuspect::bookNumber";
  36. INotificationId ISuspect::hasMoleId = "ISuspect::hasMole";
  37. INotificationId ISuspect::hasScarId = "ISuspect::hasScar";
  38. INotificationId ISuspect::hasTattooId = "ISuspect::hasTattoo";
  39. INotificationId ISuspect::MOId = "ISuspect::mO";
  40. INotificationId ISuspect::moleDescId = "ISuspect::moleDesc";
  41. INotificationId ISuspect::mugFrontId = "ISuspect::mugFront";
  42. INotificationId ISuspect::mugLeftId = "ISuspect::mugLeft";
  43. INotificationId ISuspect::mugRightId = "ISuspect::mugRight";
  44. INotificationId ISuspect::scarDescId = "ISuspect::scarDesc";
  45. INotificationId ISuspect::tattooDescId = "ISuspect::tattooDesc";
  46.  
  47. /*------------------------------------------------------------------------------
  48. | ISuspect::ISuspect                                                           |
  49. |                                                                              |
  50. | Standard constructor.                                                        |
  51. ------------------------------------------------------------------------------*/
  52. ISuspect :: ISuspect() : IPerson (),
  53.   iArrestList (new IVSequence <IArrest *> ()),
  54.   iBookNumber (0),
  55.   iHasMole (0),
  56.   iHasScar (0),
  57.   iHasTattoo (0),
  58.   iMO (""),
  59.   iMoleDesc (""),
  60.   iMugFront (defaultMugId),
  61.   iMugLeft (defaultMugId),
  62.   iMugRight (defaultMugId),
  63.   iScarDesc (""),
  64.   iTattooDesc ("")
  65. {
  66.   enableNotification();
  67.   iArrestList->enableNotification();
  68. }
  69.  
  70. /*------------------------------------------------------------------------------
  71. | ISuspect::ISuspect                                                           |
  72. |                                                                              |
  73. | Standard copy constructor.                                                   |
  74. ------------------------------------------------------------------------------*/
  75. ISuspect :: ISuspect (const ISuspect & partCopy)
  76.   : IPerson (partCopy),
  77.   iArrestList (new IVSequence <IArrest *> (*partCopy.arrestList())),
  78.   iBookNumber (partCopy.bookNumber()),
  79.   iHasMole (partCopy.hasMole()),
  80.   iHasScar (partCopy.hasScar()),
  81.   iHasTattoo (partCopy.hasTattoo()),
  82.   iMO (partCopy.MO()),
  83.   iMoleDesc (partCopy.moleDesc()),
  84.   iMugFront (partCopy.mugFront()),
  85.   iMugLeft (partCopy.mugLeft()),
  86.   iMugRight (partCopy.mugRight()),
  87.   iScarDesc (partCopy.scarDesc()),
  88.   iTattooDesc (partCopy.tattooDesc())
  89. {
  90.   enableNotification ();
  91.   iArrestList->enableNotification();
  92. }
  93.  
  94. /*------------------------------------------------------------------------------
  95. | ISuspect::~ISuspect                                                          |
  96. |                                                                              |
  97. | Empty destructor here for page tuning.                                       |
  98. ------------------------------------------------------------------------------*/
  99. ISuspect :: ~ISuspect()
  100. {
  101.   ISequence<IArrest *> tempList;
  102.   IArrest *            arrest;
  103.  
  104.   if (iArrestList)
  105.   {
  106.      IVSequence<IArrest*>::Cursor cursor(*iArrestList);
  107.      forCursor( cursor )
  108.        tempList.addAsFirst( iArrestList->elementAt( cursor ) );
  109.  
  110.      iArrestList->removeAll( );
  111.  
  112.      ISequence<IArrest*>::Cursor tempCursor( tempList );
  113.      forCursor( cursor )
  114.      {
  115.        arrest = tempList.elementAt ( tempCursor );
  116.        delete arrest;
  117.      }
  118.      tempList.removeAll( );
  119.  
  120.      delete iArrestList;
  121.   }
  122. }
  123.  
  124. /*------------------------------------------------------------------------------
  125.  | ISuspect::ISuspect
  126.  |
  127.  | Standard operator=
  128.  -----------------------------------------------------------------------------*/
  129. ISuspect & ISuspect :: operator= (const ISuspect & aSuspect)
  130. {
  131.   if (this == &aSuspect)
  132.     return *this;
  133.  
  134.   IPerson::operator=(aSuspect);
  135.   setArrestList (new IVSequence <IArrest *> (*aSuspect.arrestList()));
  136.   setBookNumber (aSuspect.bookNumber());
  137.   enableHasMole (aSuspect.hasMole());
  138.   enableHasScar (aSuspect.hasScar());
  139.   enableHasTattoo (aSuspect.hasTattoo());
  140.   setMO (aSuspect.MO());
  141.   setMoleDesc (aSuspect.moleDesc());
  142.   setMugFront (aSuspect.mugFront());
  143.   setMugLeft (aSuspect.mugLeft());
  144.   setMugRight (aSuspect.mugRight());
  145.   setScarDesc (aSuspect.scarDesc());
  146.   setTattooDesc (aSuspect.tattooDesc());
  147.  
  148.   return *this;
  149. }
  150.  
  151. /*------------------------------------------------------------------------------
  152. | ISuspect::asString                                                           |
  153. |                                                                              |
  154. | Perform asString.                                                            |
  155. | NOTE: This also identifies what data should be displayed for an              |
  156. |       ISuspect element of a list (that maps to the 'items' attribute         |
  157. |       of a list box).                                                        |
  158. ------------------------------------------------------------------------------*/
  159. IString ISuspect :: asString () const
  160. {
  161.   return (IString(bookNumber()));
  162. }
  163.  
  164. /*------------------------------------------------------------------------------
  165. | ISuspect::asDebugInfo                                                        |
  166. |                                                                              |
  167. | Generate a string that identifies for debugging purposes what data           |
  168. | an ISuspect instance contains.                                               |
  169. |                                                                              |
  170. | NOTE: attributes not included:  iMO, iHasMoleDesc, iHasScarDesc, and         |
  171. |       iHasTattooDesc.                                                        |
  172. ------------------------------------------------------------------------------*/
  173. IString ISuspect :: asDebugInfo () const
  174. {
  175.   IString debugInfo("bookNum=" + IString(iBookNumber) + ",");
  176.   debugInfo += IPerson::asDebugInfo();
  177.   debugInfo += "numArrest=" + IString(iArrestList->numberOfElements()) + ".";
  178.   debugInfo += "hasMole=" + IString(iHasMole) + ",";
  179.   debugInfo += "hasScar=" + IString(iHasScar) + ",";
  180.   debugInfo += "hasTattoo=" + IString(iHasTattoo) + ",";
  181.   debugInfo += "mugLeft=" + IString(iMugLeft) + ",";
  182.   debugInfo += "mugFront=" + IString(iMugFront) + ",";
  183.   debugInfo += "mugRight=" + IString(iMugRight) + ",";
  184.  
  185.   return debugInfo;
  186. }
  187.  
  188.  
  189. /*------------------ Attribute Get/Set Member Functions ------------------------
  190.  -----------------------------------------------------------------------------*/
  191. /*------------------------------------------------------------------------------
  192.  | arrestList
  193.  -----------------------------------------------------------------------------*/
  194. IVSequence<IArrest *> * ISuspect::arrestList() const
  195. {
  196.   return iArrestList;
  197. }
  198.  
  199. ISuspect & ISuspect::setArrestList(IVSequence<IArrest *> * aArrestList)
  200. {
  201.   if (iArrestList != aArrestList)
  202.   {
  203.     iArrestList->removeAll();
  204.     iArrestList->addAllFrom(*aArrestList);
  205.     notifyObservers(INotificationEvent(ISuspect::arrestListId, *this));
  206.   } // endif
  207.   return *this;
  208. }
  209.  
  210. /*------------------------------------------------------------------------------
  211.  | bookNumber
  212.  -----------------------------------------------------------------------------*/
  213. IString ISuspect::bookNumberAsString() const
  214. {
  215.   return IString(iBookNumber);
  216. }
  217.  
  218. ISuspect & ISuspect::setBookNumberAsString(const IString & aBookNumber)
  219. {
  220.   setBookNumber(aBookNumber.asUnsigned());
  221.   return *this;
  222. }
  223.  
  224. unsigned long ISuspect::bookNumber() const
  225. {
  226.   return iBookNumber;
  227. }
  228.  
  229. ISuspect & ISuspect::setBookNumber(const unsigned long aBookNumber)
  230. {
  231.   if (iBookNumber != aBookNumber)
  232.   {
  233.     iBookNumber = aBookNumber;
  234.     notifyObservers(INotificationEvent(ISuspect::bookNumberId, *this));
  235.   } // endif
  236.   return *this;
  237. }
  238.  
  239. /*------------------------------------------------------------------------------
  240.  | hasMole
  241.  -----------------------------------------------------------------------------*/
  242. Boolean ISuspect::hasMole() const
  243. {
  244.   return iHasMole;
  245. }
  246.  
  247. ISuspect & ISuspect::enableHasMole(Boolean enable)
  248. {
  249.   if (iHasMole != enable)
  250.   {
  251.     iHasMole = enable;
  252.     notifyObservers(INotificationEvent(ISuspect::hasMoleId, *this));
  253.   } // endif
  254.   return *this;
  255. }
  256.  
  257. /*------------------------------------------------------------------------------
  258.  | hasScar
  259.  -----------------------------------------------------------------------------*/
  260. Boolean ISuspect::hasScar() const
  261. {
  262.   return iHasScar;
  263. }
  264.  
  265. ISuspect & ISuspect::enableHasScar(Boolean enable)
  266. {
  267.   if (iHasScar != enable)
  268.   {
  269.     iHasScar = enable;
  270.     notifyObservers(INotificationEvent(ISuspect::hasScarId, *this));
  271.   } // endif
  272.   return *this;
  273. }
  274.  
  275. /*------------------------------------------------------------------------------
  276.  | hasTattoo
  277.  -----------------------------------------------------------------------------*/
  278. Boolean ISuspect::hasTattoo() const
  279. {
  280.   return iHasTattoo;
  281. }
  282.  
  283. ISuspect & ISuspect::enableHasTattoo(Boolean enable)
  284. {
  285.   if (iHasTattoo != enable)
  286.   {
  287.     iHasTattoo = enable;
  288.     notifyObservers(INotificationEvent(ISuspect::hasTattooId, *this));
  289.   } // endif
  290.   return *this;
  291. }
  292.  
  293. /*------------------------------------------------------------------------------
  294.  | MO
  295.  -----------------------------------------------------------------------------*/
  296. IString ISuspect::MO() const
  297. {
  298.   return iMO;
  299. }
  300.  
  301. ISuspect & ISuspect::setMO(const IString & aMO)
  302. {
  303.   if (iMO != aMO)
  304.   {
  305.     iMO = aMO;
  306.     notifyObservers(INotificationEvent(ISuspect::MOId, *this));
  307.   } // endif
  308.   return *this;
  309. }
  310.  
  311. /*------------------------------------------------------------------------------
  312.  | moleDesc
  313.  -----------------------------------------------------------------------------*/
  314. IString ISuspect::moleDesc() const
  315. {
  316.   return iMoleDesc;
  317. }
  318.  
  319. ISuspect & ISuspect::setMoleDesc(const IString & aMoleDesc)
  320. {
  321.   if (iMoleDesc != aMoleDesc)
  322.   {
  323.     iMoleDesc = aMoleDesc;
  324.     notifyObservers(INotificationEvent(ISuspect::moleDescId, *this));
  325.   } // endif
  326.   return *this;
  327. }
  328.  
  329. /*------------------------------------------------------------------------------
  330.  | mugFront
  331.  -----------------------------------------------------------------------------*/
  332. unsigned short ISuspect::mugFront() const
  333. {
  334.   return iMugFront;
  335. }
  336.  
  337. ISuspect & ISuspect::setMugFront(const unsigned short aMugFront)
  338. {
  339.   if (iMugFront != aMugFront)
  340.   {
  341.     iMugFront = aMugFront;
  342.     notifyObservers(INotificationEvent(ISuspect::mugFrontId, *this));
  343.   } // endif
  344.   return *this;
  345. }
  346.  
  347. IBitmapHandle ISuspect::mugFrontAsHandle() const
  348. {
  349.   IBitmapHandle aHandle;
  350.  
  351.   aHandle = mugLib.tryToLoadBitmap(iMugFront);
  352.   if (aHandle == 0)   //couldn't load bitmap, use default bitmap
  353.   {
  354.      ITRACE_DEVELOP("Couldn't load the bitmap " +
  355.                     IString(iMugFront) + " from the DLL cppwv23r.");
  356.      aHandle = mugLib.loadBitmap(defaultMugId);   //exception occurs, if fails
  357.   }
  358.  
  359.   return aHandle;
  360. }
  361.  
  362. /*------------------------------------------------------------------------------
  363.  | mugLeft
  364.  -----------------------------------------------------------------------------*/
  365. unsigned short ISuspect::mugLeft() const
  366. {
  367.   return iMugLeft;
  368. }
  369.  
  370. ISuspect & ISuspect::setMugLeft(const unsigned short aMugLeft)
  371. {
  372.   if (iMugLeft != aMugLeft)
  373.   {
  374.     iMugLeft = aMugLeft;
  375.     notifyObservers(INotificationEvent(ISuspect::mugLeftId, *this));
  376.   } // endif
  377.   return *this;
  378. }
  379.  
  380. IBitmapHandle ISuspect::mugLeftAsHandle() const
  381. {
  382.   IBitmapHandle aHandle;
  383.  
  384.   aHandle = mugLib.tryToLoadBitmap(iMugLeft);
  385.   if (aHandle == 0)   //couldn't load bitmap, use default bitmap
  386.   {
  387.      ITRACE_DEVELOP("Couldn't load the bitmap " +
  388.                     IString(iMugLeft) + " from the DLL cppwv23r.");
  389.      aHandle = mugLib.loadBitmap(defaultMugId);   //exception occurs, if fails
  390.   }
  391.  
  392.   return aHandle;
  393. }
  394.  
  395. /*------------------------------------------------------------------------------
  396.  | mugRight
  397.  -----------------------------------------------------------------------------*/
  398. unsigned short ISuspect::mugRight() const
  399. {
  400.   return iMugRight;
  401. }
  402.  
  403. ISuspect & ISuspect::setMugRight(const unsigned short aMugRight)
  404. {
  405.   if (iMugRight != aMugRight)
  406.   {
  407.     iMugRight = aMugRight;
  408.     notifyObservers(INotificationEvent(ISuspect::mugRightId, *this));
  409.   } // endif
  410.   return *this;
  411. }
  412.  
  413. IBitmapHandle ISuspect::mugRightAsHandle() const
  414. {
  415.   IBitmapHandle aHandle;
  416.  
  417.   aHandle = mugLib.tryToLoadBitmap(iMugRight);
  418.   if (aHandle == 0)   //couldn't load bitmap, use default bitmap
  419.   {
  420.      ITRACE_DEVELOP("Couldn't load the bitmap " +
  421.                     IString(iMugRight) + " from the DLL cppwv23r.");
  422.      aHandle = mugLib.loadBitmap(defaultMugId);   //exception occurs, if fails
  423.   }
  424.  
  425.   return aHandle;
  426. }
  427.  
  428. /*------------------------------------------------------------------------------
  429.  | scarDesc
  430.  -----------------------------------------------------------------------------*/
  431. IString ISuspect::scarDesc() const
  432. {
  433.   return iScarDesc;
  434. }
  435.  
  436. ISuspect & ISuspect::setScarDesc(const IString & aScarDesc)
  437. {
  438.   if (iScarDesc != aScarDesc)
  439.   {
  440.     iScarDesc = aScarDesc;
  441.     notifyObservers(INotificationEvent(ISuspect::scarDescId, *this));
  442.   } // endif
  443.   return *this;
  444. }
  445.  
  446. /*------------------------------------------------------------------------------
  447.  | tattooDesc
  448.  -----------------------------------------------------------------------------*/
  449. IString ISuspect::tattooDesc() const
  450. {
  451.   return iTattooDesc;
  452. }
  453.  
  454. ISuspect & ISuspect::setTattooDesc(const IString & aTattooDesc)
  455. {
  456.   if (iTattooDesc != aTattooDesc)
  457.   {
  458.     iTattooDesc = aTattooDesc;
  459.     notifyObservers(INotificationEvent(ISuspect::tattooDescId, *this));
  460.   } // endif
  461.   return *this;
  462. }
  463.  
  464. /*------------------------------------------------------------------------------
  465.  | ISuspect::operator == (const ISuspect & value)
  466.  -----------------------------------------------------------------------------*/
  467. Boolean ISuspect::operator == (const ISuspect & value) const
  468. {
  469.   if (bookNumber() != value.bookNumber())
  470.     return false;
  471.   return true;
  472. }
  473.  
  474. /*------------------------------------------------------------------------------
  475.  | ISuspect::operator != (const ISuspect & value)
  476.  -----------------------------------------------------------------------------*/
  477. Boolean ISuspect::operator != (const ISuspect & value) const
  478. {
  479.   if (bookNumber() != value.bookNumber())
  480.     return true;
  481.   return false;
  482. }
  483.  
  484. /*------------------------------------------------------------------------------
  485.  | ISuspect::operator == (const ISuspect * value)
  486.  -----------------------------------------------------------------------------*/
  487. Boolean ISuspect::operator == (const ISuspect * value) const
  488. {
  489.   if (bookNumber() != value->bookNumber())
  490.     return false;
  491.   return true;
  492. }
  493.  
  494. /*------------------------------------------------------------------------------
  495.  | ISuspect::operator != (const ISuspect * value)
  496.  -----------------------------------------------------------------------------*/
  497. Boolean ISuspect::operator != (const ISuspect * value) const
  498. {
  499.   if (bookNumber() != value->bookNumber())
  500.     return true;
  501.   return false;
  502. }
  503.