home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / RAPSHEET / CPPOV23 / ISUSPECT.CPP < prev    next >
Text File  |  1995-05-22  |  18KB  |  507 lines

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