home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / vbsample / iadd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  15.9 KB  |  371 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) for C++                                               *
  10. *   (C) Copyright International Business Machines Corporation 1991, 1996       *
  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.   Inherited::operator=(aIAddress);
  92.   setStreet(aIAddress.street());
  93.   setCity(aIAddress.city());
  94.   setState(aIAddress.state());
  95.   setZip(aIAddress.zip());
  96.   return *this;
  97. }
  98.  
  99. /*------------------------------------------------------------------------------
  100. | IAddress::~IAddress                                                          |
  101. |                                                                              |
  102. | IAddress destructor.                                                         |
  103. ------------------------------------------------------------------------------*/
  104. #pragma export (IAddress::~IAddress(),, 1107)
  105. IAddress::~IAddress()
  106. {
  107. }
  108.  
  109. /*------------------------------------------------------------------------------
  110. | IAddress::street                                                             |
  111. |                                                                              |
  112. | Return the street attribute.                                                 |
  113. ------------------------------------------------------------------------------*/
  114. #pragma export (IAddress::street() const,, 1108)
  115. IString IAddress::street () const
  116. {
  117.   return iStreet;
  118. }
  119.  
  120. /*------------------------------------------------------------------------------
  121. | IAddress::setStreet                                                          |
  122. |                                                                              |
  123. | Set the street attribute.                                                    |
  124. ------------------------------------------------------------------------------*/
  125. #pragma export (IAddress::setStreet(const IString&),, 1109)
  126. IAddress& IAddress::setStreet (const IString& aStreet)
  127. {
  128.   if (iStreet != aStreet) {
  129.     iStreet = aStreet;
  130.     IString eventData(iStreet);
  131.     notifyObservers(INotificationEvent(streetId, *this,
  132.                       true, (void*)&eventData));
  133.   } /* endif */
  134.   return *this;
  135. }
  136.  
  137. /*------------------------------------------------------------------------------
  138. | IAddress::city                                                               |
  139. |                                                                              |
  140. | Return the city attribute.                                                   |
  141. ------------------------------------------------------------------------------*/
  142. #pragma export (IAddress::city() const,, 1110)
  143. IString IAddress::city () const
  144. {
  145.   return iCity;
  146. }
  147.  
  148. /*------------------------------------------------------------------------------
  149. | IAddress::setCity                                                            |
  150. |                                                                              |
  151. | Set the city attribute.                                                      |
  152. ------------------------------------------------------------------------------*/
  153. #pragma export (IAddress::setCity(const IString&),, 1111)
  154. IAddress& IAddress::setCity (const IString& aCity)
  155. {
  156.   if (iCity != aCity) {
  157.     iCity = aCity;
  158.     IString eventData(iCity);
  159.     notifyObservers(INotificationEvent(cityId, *this,
  160.                       true, (void*)&eventData));
  161.   } /* endif */
  162.   return *this;
  163. }
  164.  
  165. /*------------------------------------------------------------------------------
  166. | IAddress::state                                                              |
  167. |                                                                              |
  168. | Return the state attribute.                                                  |
  169. ------------------------------------------------------------------------------*/
  170. #pragma export (IAddress::state() const,, 1112)
  171. IString IAddress::state () const
  172. {
  173.   return iState;
  174. }
  175.  
  176. /*------------------------------------------------------------------------------
  177. | IAddress::setState                                                           |
  178. |                                                                              |
  179. | Set the state attribute.                                                     |
  180. ------------------------------------------------------------------------------*/
  181. #pragma export (IAddress::setState(const IString&),, 1113)
  182. IAddress& IAddress::setState (const IString& aState)
  183. {
  184.   if (iState != aState) {
  185.     iState = aState;
  186.     IString eventData(iState);
  187.     notifyObservers(INotificationEvent(stateId, *this,
  188.                       true, (void*)&eventData));
  189.   } /* endif */
  190.   return *this;
  191. }
  192.  
  193. /*------------------------------------------------------------------------------
  194. | IAddress::zip                                                                |
  195. |                                                                              |
  196. | Return the zip attribute.                                                    |
  197. ------------------------------------------------------------------------------*/
  198. #pragma export (IAddress::zip() const,, 1114)
  199. IString IAddress::zip () const
  200. {
  201.   return iZip;
  202. }
  203.  
  204. /*------------------------------------------------------------------------------
  205. | IAddress::setZip                                                             |
  206. |                                                                              |
  207. | Set the zip attribute.                                                       |
  208. ------------------------------------------------------------------------------*/
  209. #pragma export (IAddress::setZip(const IString&),, 1115)
  210. IAddress& IAddress::setZip (const IString& aZip)
  211. {
  212.   if (iZip != aZip) {
  213.     iZip = aZip;
  214.     IString eventData(iZip);
  215.     notifyObservers(INotificationEvent(zipId, *this,
  216.                       true, (void*)&eventData));
  217.   } /* endif */
  218.   return *this;
  219. }
  220.  
  221. /*------------------------------------------------------------------------------
  222. | IAddress::setStreetToDefault                                                 |
  223. |                                                                              |
  224. | Perform the setStreetToDefault action.                                       |
  225. ------------------------------------------------------------------------------*/
  226. #pragma export (IAddress::setStreetToDefault(),, 1116)
  227. IAddress& IAddress::setStreetToDefault ()
  228. {
  229.   return setStreet("101 Main Street");
  230. }
  231.  
  232. /*------------------------------------------------------------------------------
  233. | IAddress::setCityToDefault                                                   |
  234. |                                                                              |
  235. | Perform the setCityToDefault action.                                         |
  236. ------------------------------------------------------------------------------*/
  237. #pragma export (IAddress::setCityToDefault(),, 1117)
  238. IAddress& IAddress::setCityToDefault ()
  239. {
  240.   return setCity("Hometown");
  241. }
  242.  
  243. /*------------------------------------------------------------------------------
  244. | IAddress::setStateToDefault                                                  |
  245. |                                                                              |
  246. | Perform the setStateToDefault action.                                        |
  247. ------------------------------------------------------------------------------*/
  248. #pragma export (IAddress::setStateToDefault(),, 1118)
  249. IAddress& IAddress::setStateToDefault ()
  250. {
  251.   return setState("NC");
  252. }
  253.  
  254. /*------------------------------------------------------------------------------
  255. | IAddress::setZipToDefault                                                    |
  256. |                                                                              |
  257. | Perform the setZipToDefault action.                                          |
  258. ------------------------------------------------------------------------------*/
  259. #pragma export (IAddress::setZipToDefault(),, 1119)
  260. IAddress& IAddress::setZipToDefault ()
  261. {
  262.   return setZip("27511");
  263. }
  264.  
  265. /*------------------------------------------------------------------------------
  266. | IAddress::setToDefault                                                       |
  267. |                                                                              |
  268. | Perform the setToDefault action.                                             |
  269. ------------------------------------------------------------------------------*/
  270. #pragma export (IAddress::setToDefault(),, 1120)
  271. IAddress& IAddress::setToDefault ()
  272. {
  273.   setStreetToDefault();
  274.   setCityToDefault();
  275.   setStateToDefault();
  276.   setZipToDefault();
  277.   return *this;
  278. }
  279.  
  280. /*------------------------------------------------------------------------------
  281. | IAddress::operator == (const IAddress & aValue)                              |
  282. |                                                                              |
  283. ------------------------------------------------------------------------------*/
  284. #pragma export (IAddress::operator == (const IAddress&) const,, 1121)
  285. Boolean IAddress::
  286.   operator == (const IAddress& aValue) const
  287. {
  288.   if (street() != aValue.street()) {
  289.     return false;
  290.   } /* endif */
  291.   if (city() != aValue.city()) {
  292.     return false;
  293.   } /* endif */
  294.   if (state() != aValue.state()) {
  295.     return false;
  296.   } /* endif */
  297.   if (zip() != aValue.zip()) {
  298.     return false;
  299.   } /* endif */
  300.   return true;
  301. }
  302.  
  303. /*------------------------------------------------------------------------------
  304. | IAddress::operator != (const IAddress & aValue)                              |
  305. |                                                                              |
  306. ------------------------------------------------------------------------------*/
  307. #pragma export (IAddress::operator != (const IAddress&) const,, 1122)
  308. Boolean IAddress::
  309.   operator != (const IAddress& aValue) const
  310. {
  311.   if (street() != aValue.street()) {
  312.     return true;
  313.   } /* endif */
  314.   if (city() != aValue.city()) {
  315.     return true;
  316.   } /* endif */
  317.   if (state() != aValue.state()) {
  318.     return true;
  319.   } /* endif */
  320.   if (zip() != aValue.zip()) {
  321.     return true;
  322.   } /* endif */
  323.   return false;
  324. }
  325.  
  326. /*------------------------------------------------------------------------------
  327. | IAddress::operator == (const IAddress * aValue)                              |
  328. |                                                                              |
  329. ------------------------------------------------------------------------------*/
  330. #pragma export (IAddress::operator == (const IAddress*) const,, 1123)
  331. Boolean IAddress::
  332.   operator == (const IAddress* aValue) const
  333. {
  334.   if (street() != aValue->street()) {
  335.     return false;
  336.   } /* endif */
  337.   if (city() != aValue->city()) {
  338.     return false;
  339.   } /* endif */
  340.   if (state() != aValue->state()) {
  341.     return false;
  342.   } /* endif */
  343.   if (zip() != aValue->zip()) {
  344.     return false;
  345.   } /* endif */
  346.   return true;
  347. }
  348.  
  349. /*------------------------------------------------------------------------------
  350. | IAddress::operator != (const IAddress * aValue)                              |
  351. |                                                                              |
  352. ------------------------------------------------------------------------------*/
  353. #pragma export (IAddress::operator != (const IAddress*) const,, 1124)
  354. Boolean IAddress::
  355.   operator != (const IAddress* aValue) const
  356. {
  357.   if (street() != aValue->street()) {
  358.     return true;
  359.   } /* endif */
  360.   if (city() != aValue->city()) {
  361.     return true;
  362.   } /* endif */
  363.   if (state() != aValue->state()) {
  364.     return true;
  365.   } /* endif */
  366.   if (zip() != aValue->zip()) {
  367.     return true;
  368.   } /* endif */
  369.   return false;
  370. }
  371.