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