home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmodf.zip / CUSTOMER.ZIP / IADD.CPP < prev    next >
Text File  |  1995-06-13  |  16KB  |  368 lines

  1. /*******************************************************************************
  2. * FILE NAME: iadd.cpp                                                          *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class(es):                                     *
  6. *    IAddress - IBM sample address part.                                       *
  7. *                                                                              *
  8. * COPYRIGHT:                                                                   *
  9. *   Licensed Materials - Property of IBM                                       *
  10. *   (C) Copyright IBM Corporation 1994, 1995                                   *
  11. *   All Rights Reserved                                                        *
  12. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  13. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  14. *                                                                              *
  15. * DISCLAIMER OF WARRANTIES:                                                    *
  16. *   The following [enclosed] code is sample code created by IBM                *
  17. *   Corporation.  This sample code is not part of any standard IBM product     *
  18. *   and is provided to you solely for the purpose of assisting you in the      *
  19. *   development of your applications.  The code is provided "AS IS",           *
  20. *   without warranty of any kind.  IBM shall not be liable for any damages     *
  21. *   arising out of your use of the sample code, even if they have been         *
  22. *   advised of the possibility of such damages.                                *
  23. *******************************************************************************/
  24.  
  25. #ifndef _IADD_
  26.   #include <iadd.hpp>
  27. #endif
  28.  
  29. #ifndef _INOTIFEV_
  30.   #include <inotifev.hpp>
  31. #endif
  32.  
  33.  
  34. #pragma export (IAddress::streetId,, 1100)
  35. const INotificationId IAddress::streetId =
  36.                      "IAddress::street";
  37. #pragma export (IAddress::cityId,, 1101)
  38. const INotificationId IAddress::cityId =
  39.                      "IAddress::city";
  40. #pragma export (IAddress::stateId,, 1102)
  41. const INotificationId IAddress::stateId =
  42.                      "IAddress::state";
  43. #pragma export (IAddress::zipId,, 1103)
  44. const INotificationId IAddress::zipId =
  45.                      "IAddress::zip";
  46.  
  47. /*------------------------------------------------------------------------------
  48. | IAddress::IAddress                                                           |
  49. |                                                                              |
  50. | Standard constructor.                                                        |
  51. ------------------------------------------------------------------------------*/
  52. #pragma export (IAddress::IAddress(),, 1104)
  53. IAddress::IAddress() : IPart ()
  54.     ,iStreet ("101 Main Street")
  55.     ,iCity ("Hometown")
  56.     ,iState ("NC")
  57.     ,iZip ("27511")
  58. {
  59.   enableNotification ();
  60. }
  61.  
  62. /*------------------------------------------------------------------------------
  63. | IAddress::IAddress                                                           |
  64. |                                                                              |
  65. | Standard copy constructor.                                                   |
  66. ------------------------------------------------------------------------------*/
  67. #pragma export (IAddress::IAddress(const IAddress&),, 1105)
  68. IAddress::IAddress (const IAddress& partCopy)
  69.   : IPart (partCopy)
  70.     ,iStreet (partCopy.street ())
  71.     ,iCity (partCopy.city ())
  72.     ,iState (partCopy.state ())
  73.     ,iZip (partCopy.zip ())
  74. {
  75.   enableNotification ();
  76. }
  77.  
  78. /*------------------------------------------------------------------------------
  79. | IAddress::IAddress                                                           |
  80. |                                                                              |
  81. | Standard operator=                                                           |
  82. ------------------------------------------------------------------------------*/
  83. #pragma export (IAddress::operator= (const IAddress&),, 1106)
  84. IAddress& IAddress::operator= (const IAddress& aIAddress)
  85. {
  86.   if (this == &aIAddress) {
  87.     return *this;
  88.   } /* endif */
  89.   setStreet(aIAddress.street());
  90.   setCity(aIAddress.city());
  91.   setState(aIAddress.state());
  92.   setZip(aIAddress.zip());
  93.   return *this;
  94. }
  95.  
  96. /*------------------------------------------------------------------------------
  97. | IAddress::~IAddress                                                          |
  98. |                                                                              |
  99. | IAddress destructor.                                                         |
  100. ------------------------------------------------------------------------------*/
  101. #pragma export (IAddress::~IAddress(),, 1107)
  102. IAddress::~IAddress()
  103. {
  104. }
  105.  
  106. /*------------------------------------------------------------------------------
  107. | IAddress::street                                                             |
  108. |                                                                              |
  109. | Return the street attribute.                                                 |
  110. ------------------------------------------------------------------------------*/
  111. #pragma export (IAddress::street() const,, 1108)
  112. IString IAddress::street () const
  113. {
  114.   return iStreet;
  115. }
  116.  
  117. /*------------------------------------------------------------------------------
  118. | IAddress::setStreet                                                          |
  119. |                                                                              |
  120. | Set the street attribute.                                                    |
  121. ------------------------------------------------------------------------------*/
  122. #pragma export (IAddress::setStreet(const IString&),, 1109)
  123. IAddress& IAddress::setStreet (const IString& aStreet)
  124. {
  125.   if (iStreet != aStreet) {
  126.     iStreet = aStreet;
  127.     IString eventData(iStreet);
  128.     notifyObservers(INotificationEvent(streetId, *this,
  129.                       true, (void*)&eventData));
  130.   } /* endif */
  131.   return *this;
  132. }
  133.  
  134. /*------------------------------------------------------------------------------
  135. | IAddress::city                                                               |
  136. |                                                                              |
  137. | Return the city attribute.                                                   |
  138. ------------------------------------------------------------------------------*/
  139. #pragma export (IAddress::city() const,, 1110)
  140. IString IAddress::city () const
  141. {
  142.   return iCity;
  143. }
  144.  
  145. /*------------------------------------------------------------------------------
  146. | IAddress::setCity                                                            |
  147. |                                                                              |
  148. | Set the city attribute.                                                      |
  149. ------------------------------------------------------------------------------*/
  150. #pragma export (IAddress::setCity(const IString&),, 1111)
  151. IAddress& IAddress::setCity (const IString& aCity)
  152. {
  153.   if (iCity != aCity) {
  154.     iCity = aCity;
  155.     IString eventData(iCity);
  156.     notifyObservers(INotificationEvent(cityId, *this,
  157.                       true, (void*)&eventData));
  158.   } /* endif */
  159.   return *this;
  160. }
  161.  
  162. /*------------------------------------------------------------------------------
  163. | IAddress::state                                                              |
  164. |                                                                              |
  165. | Return the state attribute.                                                  |
  166. ------------------------------------------------------------------------------*/
  167. #pragma export (IAddress::state() const,, 1112)
  168. IString IAddress::state () const
  169. {
  170.   return iState;
  171. }
  172.  
  173. /*------------------------------------------------------------------------------
  174. | IAddress::setState                                                           |
  175. |                                                                              |
  176. | Set the state attribute.                                                     |
  177. ------------------------------------------------------------------------------*/
  178. #pragma export (IAddress::setState(const IString&),, 1113)
  179. IAddress& IAddress::setState (const IString& aState)
  180. {
  181.   if (iState != aState) {
  182.     iState = aState;
  183.     IString eventData(iState);
  184.     notifyObservers(INotificationEvent(stateId, *this,
  185.                       true, (void*)&eventData));
  186.   } /* endif */
  187.   return *this;
  188. }
  189.  
  190. /*------------------------------------------------------------------------------
  191. | IAddress::zip                                                                |
  192. |                                                                              |
  193. | Return the zip attribute.                                                    |
  194. ------------------------------------------------------------------------------*/
  195. #pragma export (IAddress::zip() const,, 1114)
  196. IString IAddress::zip () const
  197. {
  198.   return iZip;
  199. }
  200.  
  201. /*------------------------------------------------------------------------------
  202. | IAddress::setZip                                                             |
  203. |                                                                              |
  204. | Set the zip attribute.                                                       |
  205. ------------------------------------------------------------------------------*/
  206. #pragma export (IAddress::setZip(const IString&),, 1115)
  207. IAddress& IAddress::setZip (const IString& aZip)
  208. {
  209.   if (iZip != aZip) {
  210.     iZip = aZip;
  211.     IString eventData(iZip);
  212.     notifyObservers(INotificationEvent(zipId, *this,
  213.                       true, (void*)&eventData));
  214.   } /* endif */
  215.   return *this;
  216. }
  217.  
  218. /*------------------------------------------------------------------------------
  219. | IAddress::setStreetToDefault                                                 |
  220. |                                                                              |
  221. | Perform the setStreetToDefault action.                                       |
  222. ------------------------------------------------------------------------------*/
  223. #pragma export (IAddress::setStreetToDefault(),, 1116)
  224. IAddress& IAddress::setStreetToDefault ()
  225. {
  226.   return setStreet("101 Main Street");
  227. }
  228.  
  229. /*------------------------------------------------------------------------------
  230. | IAddress::setCityToDefault                                                   |
  231. |                                                                              |
  232. | Perform the setCityToDefault action.                                         |
  233. ------------------------------------------------------------------------------*/
  234. #pragma export (IAddress::setCityToDefault(),, 1117)
  235. IAddress& IAddress::setCityToDefault ()
  236. {
  237.   return setCity("Hometown");
  238. }
  239.  
  240. /*------------------------------------------------------------------------------
  241. | IAddress::setStateToDefault                                                  |
  242. |                                                                              |
  243. | Perform the setStateToDefault action.                                        |
  244. ------------------------------------------------------------------------------*/
  245. #pragma export (IAddress::setStateToDefault(),, 1118)
  246. IAddress& IAddress::setStateToDefault ()
  247. {
  248.   return setState("NC");
  249. }
  250.  
  251. /*------------------------------------------------------------------------------
  252. | IAddress::setZipToDefault                                                    |
  253. |                                                                              |
  254. | Perform the setZipToDefault action.                                          |
  255. ------------------------------------------------------------------------------*/
  256. #pragma export (IAddress::setZipToDefault(),, 1119)
  257. IAddress& IAddress::setZipToDefault ()
  258. {
  259.   return setZip("27511");
  260. }
  261.  
  262. /*------------------------------------------------------------------------------
  263. | IAddress::setToDefault                                                       |
  264. |                                                                              |
  265. | Perform the setToDefault action.                                             |
  266. ------------------------------------------------------------------------------*/
  267. #pragma export (IAddress::setToDefault(),, 1120)
  268. IAddress& IAddress::setToDefault ()
  269. {
  270.   setStreetToDefault();
  271.   setCityToDefault();
  272.   setStateToDefault();
  273.   setZipToDefault();
  274.   return *this;
  275. }
  276.  
  277. /*------------------------------------------------------------------------------
  278. | IAddress::operator == (const IAddress & aValue)                              |
  279. |                                                                              |
  280. ------------------------------------------------------------------------------*/
  281. #pragma export (IAddress::operator == (const IAddress&) const,, 1121)
  282. Boolean IAddress::
  283.   operator == (const IAddress& aValue) const
  284. {
  285.   if (street() != aValue.street()) {
  286.     return false;
  287.   } /* endif */
  288.   if (city() != aValue.city()) {
  289.     return false;
  290.   } /* endif */
  291.   if (state() != aValue.state()) {
  292.     return false;
  293.   } /* endif */
  294.   if (zip() != aValue.zip()) {
  295.     return false;
  296.   } /* endif */
  297.   return true;
  298. }
  299.  
  300. /*------------------------------------------------------------------------------
  301. | IAddress::operator != (const IAddress & aValue)                              |
  302. |                                                                              |
  303. ------------------------------------------------------------------------------*/
  304. #pragma export (IAddress::operator != (const IAddress&) const,, 1122)
  305. Boolean IAddress::
  306.   operator != (const IAddress& aValue) const
  307. {
  308.   if (street() != aValue.street()) {
  309.     return true;
  310.   } /* endif */
  311.   if (city() != aValue.city()) {
  312.     return true;
  313.   } /* endif */
  314.   if (state() != aValue.state()) {
  315.     return true;
  316.   } /* endif */
  317.   if (zip() != aValue.zip()) {
  318.     return true;
  319.   } /* endif */
  320.   return false;
  321. }
  322.  
  323. /*------------------------------------------------------------------------------
  324. | IAddress::operator == (const IAddress * aValue)                              |
  325. |                                                                              |
  326. ------------------------------------------------------------------------------*/
  327. #pragma export (IAddress::operator == (const IAddress*) const,, 1123)
  328. Boolean IAddress::
  329.   operator == (const IAddress* aValue) const
  330. {
  331.   if (street() != aValue->street()) {
  332.     return false;
  333.   } /* endif */
  334.   if (city() != aValue->city()) {
  335.     return false;
  336.   } /* endif */
  337.   if (state() != aValue->state()) {
  338.     return false;
  339.   } /* endif */
  340.   if (zip() != aValue->zip()) {
  341.     return false;
  342.   } /* endif */
  343.   return true;
  344. }
  345.  
  346. /*------------------------------------------------------------------------------
  347. | IAddress::operator != (const IAddress * aValue)                              |
  348. |                                                                              |
  349. ------------------------------------------------------------------------------*/
  350. #pragma export (IAddress::operator != (const IAddress*) const,, 1124)
  351. Boolean IAddress::
  352.   operator != (const IAddress* aValue) const
  353. {
  354.   if (street() != aValue->street()) {
  355.     return true;
  356.   } /* endif */
  357.   if (city() != aValue->city()) {
  358.     return true;
  359.   } /* endif */
  360.   if (state() != aValue->state()) {
  361.     return true;
  362.   } /* endif */
  363.   if (zip() != aValue->zip()) {
  364.     return true;
  365.   } /* endif */
  366.   return false;
  367. }
  368.