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

  1. //****************************************************************************
  2. // IArrest Class - C++ Source File (iarrest.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 "iarrest.hpp"                 //IArrest class header
  19. #ifndef _IRESLIB_
  20. #include <ireslib.hpp>
  21. #endif
  22. #ifndef _INOTIFEV_
  23. #include <inotifev.hpp>
  24. #endif
  25. #ifndef _RAP_
  26. #include "rap.h"
  27. #endif
  28.  
  29. /****************************************************************************
  30.  * Constructors
  31.  ****************************************************************************/
  32. IArrest :: IArrest() :
  33.     dCharge(IArrest::burglary),
  34.     dStatus(IArrest::arrested),
  35.     dReport(""),
  36.     dStatusDate("")
  37. {
  38. }
  39.  
  40. /****************************************************************************
  41.  * Destructor
  42.  ****************************************************************************/
  43. IArrest :: ~IArrest()
  44. {
  45. }
  46.  
  47.  
  48. /*------------------------------------------------------------------------------
  49.  | IArrest::IArrest
  50.  |
  51.  | Standard operator=
  52.  -----------------------------------------------------------------------------*/
  53. IArrest & IArrest :: operator= (const IArrest & anArrest)
  54. {
  55.   if (this == &anArrest)
  56.     return *this;
  57.  
  58.   setCharge(anArrest.charge());
  59.   setStatus(anArrest.status());
  60.   setStatusDate(anArrest.statusDate());
  61.   setReport(anArrest.report());
  62.   return *this;
  63. }
  64.  
  65. /****************************************************************************
  66.  * Events
  67.  ****************************************************************************/
  68. INotificationId IArrest :: chargeId = "IArrest::charge";
  69. INotificationId IArrest :: statusId = "IArrest::status";
  70. INotificationId IArrest :: statusDateId = "IArrest::statusDate";
  71. INotificationId IArrest :: reportId = "IArrest::report";
  72.  
  73.  
  74. /****************************************************************************
  75.  * Attribute Access Member Functions
  76.  ****************************************************************************/
  77. /*------------------------------------------------------------------
  78.  * charge
  79.  *-----------------------------------------------------------------*/
  80. unsigned short IArrest :: charge () const
  81. {
  82.   return dCharge;
  83. }
  84.  
  85. IArrest& IArrest :: setCharge (const unsigned short iCharge)
  86. {
  87.   if (dCharge != iCharge) 
  88.   {
  89.      dCharge = iCharge;
  90.      notifyObservers(INotificationEvent(chargeId, *this, true,
  91.                                         IEventData((char *)iCharge)));
  92.   }
  93.   else
  94.      notifyObservers(INotificationEvent(chargeId, *this, false));
  95.   return *this;
  96. }
  97.  
  98. IString IArrest::chargeAsString() const
  99. {
  100.   IString sCharge;
  101.   switch (dCharge)
  102.   {
  103.      case arson:                                                  
  104.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(ARSON_STR);
  105.         break;                                                    
  106.      case accomplice_to_murder:                                             
  107.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(ACCOMPLICE_TO_MURDER_STR);
  108.         break;                                                    
  109.      case assault:                                              
  110.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(ASSAULT_STR);
  111.         break;                                                    
  112.      case assault_w_deadly_weapon:                                             
  113.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(ASSAULT_W_DEADLY_WEAPON_STR);
  114.         break;                                                    
  115.      case breaking_and_entering:                                             
  116.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(BREAKING_AND_ENTERING_STR);
  117.         break;                                                    
  118.      case burglary:                                             
  119.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(BURGLARY_STR);
  120.         break;                                                    
  121.      case DWI:                                             
  122.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(DWI_STR);
  123.         break;                                                    
  124.      case embezzlement:                                             
  125.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(EMBEZZLEMENT_STR);
  126.         break;                                                    
  127.      case fraud:                                             
  128.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(FRAUD_STR);
  129.         break;                                                    
  130.      case hijacking:                                             
  131.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(HIJACKING_STR);
  132.         break;                                                    
  133.      case hit_and_run:                                             
  134.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(HIT_AND_RUN_STR);
  135.         break;                                                    
  136.      case kidnapping:                                             
  137.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(KIDNAPPING_STR);
  138.         break;                                                    
  139.      case manslaughter:                                             
  140.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(MANSLAUGHTER_STR);
  141.         break;                                                    
  142.      case murder:                                             
  143.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(MURDER_STR);
  144.         break;                                                    
  145.      case perjury:                                             
  146.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(PERJURY_STR);
  147.         break;                                                    
  148.      case trespassing:                                             
  149.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(TRESPASSING_STR);
  150.         break;                                                    
  151.      case vandalism:
  152.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(VANDALISM_STR);
  153.         break;                                                    
  154.      case wreckless_driving:                                             
  155.         sCharge = IDynamicLinkLibrary("cppov23r").tryToLoadString(WRECKLESS_DRIVING_STR);
  156.         break;                                                    
  157.   }
  158.   return sCharge;
  159. }
  160.  
  161.  
  162. IArrest & IArrest::setChargeFromString(const IString & aCharge)
  163. {
  164.   if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(ARSON_STR))
  165.      setCharge(arson);
  166.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(ACCOMPLICE_TO_MURDER_STR))
  167.      setCharge(accomplice_to_murder);
  168.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(ASSAULT_STR))
  169.      setCharge(assault);
  170.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(ASSAULT_W_DEADLY_WEAPON_STR))
  171.      setCharge(assault_w_deadly_weapon);
  172.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(BREAKING_AND_ENTERING_STR))
  173.      setCharge(breaking_and_entering);
  174.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(BURGLARY_STR))
  175.      setCharge(burglary);
  176.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(DWI_STR))
  177.      setCharge(DWI);
  178.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(EMBEZZLEMENT_STR))
  179.      setCharge(embezzlement);
  180.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(FRAUD_STR))
  181.      setCharge(fraud);
  182.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(HIJACKING_STR))
  183.      setCharge(hijacking);
  184.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(HIT_AND_RUN_STR))
  185.      setCharge(hit_and_run);
  186.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(KIDNAPPING_STR))
  187.      setCharge(kidnapping);
  188.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(MANSLAUGHTER_STR))
  189.      setCharge(manslaughter);
  190.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(MURDER_STR))
  191.      setCharge(murder);
  192.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(PERJURY_STR))
  193.      setCharge(perjury);
  194.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(TRESPASSING_STR))
  195.      setCharge(trespassing);
  196.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(VANDALISM_STR))
  197.      setCharge(vandalism);
  198.   else if (aCharge == IDynamicLinkLibrary("cppov23r").tryToLoadString(WRECKLESS_DRIVING_STR))
  199.      setCharge(wreckless_driving);
  200.   return *this;
  201. }
  202.  
  203. /*------------------------------------------------------------------
  204.  * status
  205.  *-----------------------------------------------------------------*/
  206. unsigned short IArrest :: status () const
  207. {
  208.   return dStatus;
  209. }
  210.  
  211. IArrest& IArrest :: setStatus (const unsigned short iStatus)
  212. {
  213.   if (dStatus != iStatus)
  214.   {
  215.      dStatus = iStatus;
  216.      notifyObservers(INotificationEvent(statusId, *this, true,
  217.                                         IEventData((char *)iStatus)));
  218.   }
  219.   else
  220.      notifyObservers(INotificationEvent(statusId, *this, false));
  221.   return *this;
  222. }
  223.  
  224. IString IArrest::statusAsString() const
  225. {
  226.   IString sStatus;
  227.   switch (dStatus)
  228.   {
  229.      case acquitted:
  230.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(ACQUITTED_STR);
  231.         break;                                                    
  232.      case arrested:                                                  
  233.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(ARRESTED_STR);
  234.         break;                                                    
  235.      case arraigned:                                                  
  236.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(ARRAIGNED_STR);
  237.         break;                                                    
  238.      case convicted:                                                  
  239.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(CONVICTED_STR);
  240.         break;                                                    
  241.      case dropped:                                                  
  242.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(DROPPED_STR);
  243.         break;                                                    
  244.      case escaped:                                                  
  245.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(ESCAPED_STR);
  246.         break;                                                    
  247.      case free_on_bond:                                                  
  248.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(FREE_ON_BOND_STR);
  249.         break;                                                    
  250.      case released:                                                  
  251.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(RELEASED_STR);
  252.         break;                                                    
  253.      case released_on_parole:                                                  
  254.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(RELEASED_ON_PAROLE_STR);
  255.         break;                                                    
  256.      case under_suspicion:                                                  
  257.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(UNDER_SUSPICION_STR);
  258.         break;                                                    
  259.      case wanted:                                                  
  260.         sStatus = IDynamicLinkLibrary("cppov23r").tryToLoadString(WANTED_STR);
  261.         break;                                                    
  262.   }
  263.   return sStatus;
  264. }
  265.  
  266.  
  267. IArrest & IArrest::setStatusFromString(const IString & aStatus)
  268. {
  269.   if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(ACQUITTED_STR))
  270.      setCharge(acquitted);
  271.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(ARRESTED_STR))
  272.      setCharge(arrested);
  273.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(ARRAIGNED_STR))
  274.      setCharge(arraigned);
  275.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(CONVICTED_STR))
  276.      setCharge(convicted);
  277.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(DROPPED_STR))
  278.      setCharge(dropped);
  279.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(ESCAPED_STR))
  280.      setCharge(escaped);
  281.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(FREE_ON_BOND_STR))
  282.      setCharge(free_on_bond);
  283.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(RELEASED_STR))
  284.      setCharge(released);
  285.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(RELEASED_ON_PAROLE_STR))
  286.      setCharge(released_on_parole);
  287.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(UNDER_SUSPICION_STR))
  288.      setCharge(under_suspicion);
  289.   else if (aStatus == IDynamicLinkLibrary("cppov23r").tryToLoadString(WANTED_STR))
  290.      setCharge(wanted);
  291.   return *this;
  292. }
  293.  
  294. /*------------------------------------------------------------------
  295.  * statusDate
  296.  *-----------------------------------------------------------------*/
  297. IString IArrest :: statusDate () const
  298. {
  299.   return dStatusDate;
  300. }
  301.  
  302. IArrest & IArrest :: setStatusDate (const IString & iStatusDate)
  303. {
  304.   if (dStatusDate != iStatusDate)
  305.   {
  306.      dStatusDate = iStatusDate;            
  307.      notifyObservers(INotificationEvent(statusDateId, *this, true,
  308.                                         IEventData((char *)iStatusDate)));
  309.   }
  310.   else
  311.      notifyObservers(INotificationEvent(statusDateId, *this, false));
  312.   return *this;
  313. }
  314.  
  315.  
  316. /*------------------------------------------------------------------
  317.  * report
  318.  *-----------------------------------------------------------------*/
  319. IString IArrest :: report () const
  320. {
  321.   return dReport;
  322. }
  323.  
  324. IArrest & IArrest :: setReport (const IString & iReport)
  325. {
  326.   dReport = iReport;
  327.   notifyObservers(INotificationEvent(reportId, *this, true,
  328.                                      IEventData((char *)iReport)));
  329.   return *this;
  330. }
  331.  
  332.  
  333. /****************************************************************************
  334.  * Member Functions
  335.  ****************************************************************************/
  336. /*------------------------------------------------------------------------------
  337. | IArrest::asDebugInfo                                                         |
  338. |                                                                              |
  339. | Generate a string that identifies for debugging purposes what data           |
  340. | an IArrest  instance contains.                                               |
  341. |                                                                              |
  342. | NOTE: attributes not included:  charge, , status, statusDate and report      |
  343. | NOTE: to see what some of the values map to, see the enumerations that       |
  344. |       are defined in IArrest.hpp.                                           |
  345. ------------------------------------------------------------------------------*/
  346. IString IArrest :: asDebugInfo () const
  347. {
  348.   IString debugInfo("charge=" + IString(dCharge) + ",");
  349.   debugInfo += "status=" + IString(dStatus) + ",";
  350.   debugInfo += "StatusDate=" + dStatusDate + ",";
  351.   debugInfo += "Report=" + dReport + ",";
  352.   return debugInfo;
  353. }
  354.  
  355. /*------------------------------------------------------------------
  356.  * asString() - used to identify what gets shown in a listbox
  357.  *-----------------------------------------------------------------*/
  358. IString  IArrest :: asString() const
  359. {
  360.   return (chargeAsString() + "     " + statusAsString() + "     " + dStatusDate);
  361. }
  362.  
  363.  
  364. /**************************************************************************** 
  365.  * Operators
  366.  ****************************************************************************/
  367. /*------------------------------------------------------------------
  368.  * Operator == (const IArrest & value)
  369.  *-----------------------------------------------------------------*/
  370. Boolean 
  371.   IArrest :: operator == (const IArrest & value) const
  372. {
  373.   if (charge() != value.charge()) {
  374.     return false;
  375.   } /* endif */
  376.   if (status() != value.status()) {
  377.     return false;
  378.   } /* endif */
  379.   if (statusDate() != value.statusDate()) {
  380.     return false;
  381.   } /* endif */
  382.   return true;
  383. }
  384.  
  385. /*------------------------------------------------------------------
  386.  * Operator != (const IArrest & value)
  387.  *-----------------------------------------------------------------*/
  388. Boolean 
  389.   IArrest :: operator != (const IArrest & value) const
  390. {
  391.   if (charge() != value.charge()) {
  392.     return true;
  393.   } /* endif */
  394.   if (status() != value.status()) {
  395.     return true;
  396.   } /* endif */
  397.   if (statusDate() != value.statusDate()) {
  398.     return true;
  399.   } /* endif */
  400.   return false;
  401. }
  402.  
  403. /*------------------------------------------------------------------
  404.  * Operator == (const IArrest * value)
  405.  *-----------------------------------------------------------------*/
  406. Boolean 
  407.   IArrest :: operator == (const IArrest * value) const
  408. {
  409.   if (charge() != value->charge()) {
  410.     return false;
  411.   } /* endif */
  412.   if (status() != value->status()) {
  413.     return false;
  414.   } /* endif */
  415.   if (statusDate() != value->statusDate()) {
  416.     return false;
  417.   } /* endif */
  418.   return true;
  419. }
  420.  
  421. /*------------------------------------------------------------------
  422.  * Operator != (const IArrest * value)
  423.  *-----------------------------------------------------------------*/
  424. Boolean 
  425.   IArrest :: operator != (const IArrest * value) const
  426. {
  427.   if (charge() != value->charge()) {
  428.     return true;
  429.   } /* endif */
  430.   if (status() != value->status()) {
  431.     return true;
  432.   } /* endif */
  433.   if (statusDate() != value->statusDate()) {
  434.     return true;
  435.   } /* endif */
  436.   return false;
  437. }
  438.