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

  1. /*******************************************************************************
  2. * FILE NAME: icompany.cpp                                                      *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   Class implementation of the class(es):                                     *
  6. *    ICompany - IBM sample company 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 _ICOMPANY_
  26.   #include <icompany.hpp>
  27. #endif
  28.  
  29. #ifndef _INOTIFEV_
  30.   #include <inotifev.hpp>
  31. #endif
  32.  
  33. #include <iadd.hpp>
  34. #include <icust.hpp>
  35.  
  36. #pragma export (ICompany::nameId,, 1300)
  37. const INotificationId ICompany::nameId =
  38.                      "ICompany::name";
  39. #pragma export (ICompany::addressId,, 1301)
  40. const INotificationId ICompany::addressId =
  41.                      "ICompany::address";
  42. #pragma export (ICompany::customerListId,, 1302)
  43. const INotificationId ICompany::customerListId =
  44.                      "ICompany::customerList";
  45. #pragma export (ICompany::phoneId,, 1303)
  46. const INotificationId ICompany::phoneId =
  47.                      "ICompany::phone";
  48. #pragma export (ICompany::customerAddedId,, 1304)
  49. const INotificationId ICompany::customerAddedId =
  50.                      "ICompany::customerAdded";
  51.  
  52. /*------------------------------------------------------------------------------
  53. | ICompany::ICompany                                                           |
  54. |                                                                              |
  55. | Standard constructor.                                                        |
  56. ------------------------------------------------------------------------------*/
  57. #pragma export (ICompany::ICompany(),, 1305)
  58. ICompany::ICompany() : IPart ()
  59.     ,iName ("XYZ")
  60.     ,iAddress (new IAddress())
  61.     ,iCustomerList (new IVSequence<ICustomer*> ())
  62.     ,iPhone ("555-1212")
  63. {
  64.   iCustomerList->addAsLast (new ICustomer("Al"));
  65.   iCustomerList->addAsLast (new ICustomer("Bob"));
  66.   iCustomerList->addAsLast (new ICustomer("Bruce"));
  67.   iCustomerList->addAsLast (new ICustomer("Dave"));
  68.   iCustomerList->addAsLast (new ICustomer("Delores"));
  69.   iCustomerList->addAsLast (new ICustomer("Diann"));
  70.   iCustomerList->addAsLast (new ICustomer("Don"));
  71.   iCustomerList->addAsLast (new ICustomer("Ed"));
  72.   iCustomerList->addAsLast (new ICustomer("Flora"));
  73.   iCustomerList->addAsLast (new ICustomer("Fred"));
  74.   iCustomerList->addAsLast (new ICustomer("George"));
  75.   iCustomerList->addAsLast (new ICustomer("Jim"));
  76.   iCustomerList->addAsLast (new ICustomer("Kat"));
  77.   iCustomerList->addAsLast (new ICustomer("Kathy"));
  78.   iCustomerList->addAsLast (new ICustomer("Ken"));
  79.   iCustomerList->addAsLast (new ICustomer("Lou"));
  80.   iCustomerList->addAsLast (new ICustomer("Mark"));
  81.   iCustomerList->addAsLast (new ICustomer("Michael"));
  82.   iCustomerList->addAsLast (new ICustomer("Morris"));
  83.   iCustomerList->addAsLast (new ICustomer("Peter"));
  84.   iCustomerList->addAsLast (new ICustomer("Rich"));
  85.   iCustomerList->addAsLast (new ICustomer("Ricky"));
  86.   iCustomerList->addAsLast (new ICustomer("Robert"));
  87.   iCustomerList->addAsLast (new ICustomer("Ron"));
  88.   iCustomerList->addAsLast (new ICustomer("Sherry"));
  89.   iCustomerList->addAsLast (new ICustomer("Steve"));
  90.   iCustomerList->addAsLast (new ICustomer("Susan"));
  91.   iCustomerList->addAsLast (new ICustomer("Terry"));
  92.   enableNotification ();
  93. }
  94.  
  95. /*------------------------------------------------------------------------------
  96. | ICompany::ICompany                                                           |
  97. |                                                                              |
  98. | Constructor with name parameter.                                             |
  99. ------------------------------------------------------------------------------*/
  100. #pragma export (ICompany::ICompany(const IString& aName),, 1306)
  101. ICompany::ICompany(const IString& aName) :
  102.   IPart (),
  103.   iName ("XYZ"),
  104.   iAddress (new IAddress()),
  105.   iCustomerList (new IVSequence<ICustomer*> ()),
  106.   iPhone ("555-1212")
  107. {
  108.   setName(aName);
  109.   enableNotification ();
  110. }
  111.  
  112. /*------------------------------------------------------------------------------
  113. | ICompany::ICompany                                                           |
  114. |                                                                              |
  115. | Standard copy constructor.                                                   |
  116. ------------------------------------------------------------------------------*/
  117. #pragma export (ICompany::ICompany(const ICompany&),, 1307)
  118. ICompany::ICompany (const ICompany& partCopy)
  119.   : IPart (partCopy)
  120.     ,iName (partCopy.name ())
  121.     ,iAddress (partCopy.address ())
  122.     ,iCustomerList (partCopy.customerList ())
  123.     ,iPhone (partCopy.phone ())
  124. {
  125.   enableNotification ();
  126. }
  127.  
  128. /*------------------------------------------------------------------------------
  129. | ICompany::ICompany                                                           |
  130. |                                                                              |
  131. | Standard operator=                                                           |
  132. ------------------------------------------------------------------------------*/
  133. #pragma export (ICompany::operator= (const ICompany&),, 1308)
  134. ICompany& ICompany::operator= (const ICompany& aICompany)
  135. {
  136.   if (this == &aICompany) {
  137.     return *this;
  138.   } /* endif */
  139.   setName(aICompany.name());
  140.   setAddress(aICompany.address());
  141.   setCustomerList(aICompany.customerList());
  142.   setPhone(aICompany.phone());
  143.   return *this;
  144. }
  145.  
  146. /*------------------------------------------------------------------------------
  147. | ICompany::~ICompany                                                          |
  148. |                                                                              |
  149. | ICompany destructor.                                                         |
  150. ------------------------------------------------------------------------------*/
  151. #pragma export (ICompany::~ICompany(),, 1309)
  152. ICompany::~ICompany()
  153. {
  154.   if (iAddress)
  155.     delete iAddress;
  156.   if (iCustomerList)
  157.     delete iCustomerList;
  158. }
  159.  
  160. /*------------------------------------------------------------------------------
  161. | ICompany::asString                                                           |
  162. |                                                                              |
  163. | Perform asString.                                                            |
  164. ------------------------------------------------------------------------------*/
  165. #pragma export (ICompany::asString() const,, 1310)
  166. IString ICompany::asString () const
  167. {
  168.   return name();
  169. }
  170.  
  171. /*------------------------------------------------------------------------------
  172. | ICompany::name                                                               |
  173. |                                                                              |
  174. | Return the name attribute.                                                   |
  175. ------------------------------------------------------------------------------*/
  176. #pragma export (ICompany::name() const,, 1311)
  177. IString ICompany::name () const
  178. {
  179.   return iName;
  180. }
  181.  
  182. /*------------------------------------------------------------------------------
  183. | ICompany::setName                                                            |
  184. |                                                                              |
  185. | Set the name attribute.                                                      |
  186. ------------------------------------------------------------------------------*/
  187. #pragma export (ICompany::setName(const IString&),, 1312)
  188. ICompany& ICompany::setName (const IString& aName)
  189. {
  190.   if (iName != aName) {
  191.     iName = aName;
  192.     IString eventData(iName);
  193.     notifyObservers(INotificationEvent(nameId, *this,
  194.                       true, (void*)&eventData));
  195.   } /* endif */
  196.   return *this;
  197. }
  198.  
  199. /*------------------------------------------------------------------------------
  200. | ICompany::address                                                            |
  201. |                                                                              |
  202. | Return the address attribute.                                                |
  203. ------------------------------------------------------------------------------*/
  204. #pragma export (ICompany::address() const,, 1313)
  205. IAddress* ICompany::address () const
  206. {
  207.   return iAddress;
  208. }
  209.  
  210. /*------------------------------------------------------------------------------
  211. | ICompany::setAddress                                                         |
  212. |                                                                              |
  213. | Set the address attribute.                                                   |
  214. ------------------------------------------------------------------------------*/
  215. #pragma export (ICompany::setAddress(const IAddress*),, 1314)
  216. ICompany& ICompany::setAddress (IAddress* aAddress)
  217. {
  218.   if (iAddress != aAddress) {
  219.     if (iAddress)
  220.       delete iAddress;
  221.     iAddress = aAddress;
  222.     notifyObservers(INotificationEvent(addressId, *this,
  223.                       true, (void*)iAddress));
  224.   } /* endif */
  225.   return *this;
  226. }
  227.  
  228. /*------------------------------------------------------------------------------
  229. | ICompany::setAddress                                                         |
  230. |                                                                              |
  231. | Set the address attribute.                                                   |
  232. ------------------------------------------------------------------------------*/
  233. #pragma export (ICompany::setAddress(const IAddress&),, 1315)
  234. ICompany& ICompany::setAddress (const IAddress& aAddress)
  235. {
  236.   return setAddress(new IAddress(aAddress));
  237. }
  238.  
  239. /*------------------------------------------------------------------------------
  240. | ICompany::customerList                                                       |
  241. |                                                                              |
  242. | Return the customerList attribute.                                           |
  243. ------------------------------------------------------------------------------*/
  244. #pragma export (ICompany::customerList() const,, 1316)
  245. IVSequence <ICustomer*> * ICompany::customerList () const
  246. {
  247.   return iCustomerList;
  248. }
  249.  
  250. /*------------------------------------------------------------------------------
  251. | ICompany::setCustomerList                                                    |
  252. |                                                                              |
  253. | Set the customerList attribute.                                              |
  254. ------------------------------------------------------------------------------*/
  255. #pragma export (ICompany::setCustomerList(const IVSequence <ICustomer*>*),, 1317)
  256. ICompany& ICompany::setCustomerList (IVSequence <ICustomer*>* aCustomerList)
  257. {
  258.   if (iCustomerList != aCustomerList) {
  259.     if (iCustomerList)
  260.       delete iCustomerList;
  261.     iCustomerList = aCustomerList;
  262.     notifyObservers(INotificationEvent(customerListId, *this,
  263.                       true, (void*)iCustomerList));
  264.   } /* endif */
  265.   return *this;
  266. }
  267.  
  268. /*------------------------------------------------------------------------------
  269. | ICompany::setCustomerList                                                    |
  270. |                                                                              |
  271. | Set the customerList attribute.                                              |
  272. ------------------------------------------------------------------------------*/
  273. #pragma export (ICompany::setCustomerList(const IVSequence <ICustomer*>&),, 1318)
  274. ICompany& ICompany::setCustomerList (const IVSequence <ICustomer*>& aCustomerList)
  275. {
  276.   return setCustomerList(new IVSequence <ICustomer*>(aCustomerList));
  277. }
  278.  
  279. /*------------------------------------------------------------------------------
  280. | ICompany::addCustomer                                                        |
  281. |                                                                              |
  282. | Perform the addCustomer action.                                              |
  283. ------------------------------------------------------------------------------*/
  284. #pragma export (ICompany::addCustomer (ICustomer* customer),, 1319)
  285. ICompany& ICompany::
  286.   addCustomer (ICustomer* customer)
  287. {
  288.   if (customerList ()) {
  289.     if (customer) {
  290.       customerList()->add (customer);
  291.       customer->enableNotification ();
  292.       notifyObservers(INotificationEvent(customerAddedId, *this,
  293.                       true, (void*)customer));
  294.     } ; /* endif */
  295.   } ; /* endif */
  296.   return *this;
  297. }
  298.  
  299. /*------------------------------------------------------------------------------
  300. | ICompany::addCustomer                                                        |
  301. |                                                                              |
  302. | Perform the addCustomer action.                                              |
  303. ------------------------------------------------------------------------------*/
  304. #pragma export (ICompany::addCustomer (const IString& aName),, 1320)
  305. ICompany& ICompany::
  306.   addCustomer (const IString& aName)
  307. {
  308.   addCustomer (new ICustomer (aName));
  309.   return *this;
  310. }
  311.  
  312. /*------------------------------------------------------------------------------
  313. | ICompany::phone                                                              |
  314. |                                                                              |
  315. | Return the phone attribute.                                                  |
  316. ------------------------------------------------------------------------------*/
  317. #pragma export (ICompany::phone() const,, 1321)
  318. IString ICompany::phone () const
  319. {
  320.   return iPhone;
  321. }
  322.  
  323. /*------------------------------------------------------------------------------
  324. | ICompany::setPhone                                                           |
  325. |                                                                              |
  326. | Set the phone attribute.                                                     |
  327. ------------------------------------------------------------------------------*/
  328. #pragma export (ICompany::setPhone(const IString&),, 1322)
  329. ICompany& ICompany::setPhone (const IString& aPhone)
  330. {
  331.   if (iPhone != aPhone) {
  332.     iPhone = aPhone;
  333.     IString eventData(iPhone);
  334.     notifyObservers(INotificationEvent(phoneId, *this,
  335.                       true, (void*)&eventData));
  336.   } /* endif */
  337.   return *this;
  338. }
  339.  
  340. /*------------------------------------------------------------------------------
  341. | ICompany::setNameToDefault                                                   |
  342. |                                                                              |
  343. | Perform the setNameToDefault action.                                         |
  344. ------------------------------------------------------------------------------*/
  345. #pragma export (ICompany::setNameToDefault(),, 1323)
  346. ICompany& ICompany::setNameToDefault ()
  347. {
  348.   return setName("IBM");
  349. }
  350.  
  351. /*------------------------------------------------------------------------------
  352. | ICompany::setAddressToDefault                                                |
  353. |                                                                              |
  354. | Perform the setAddressToDefault action.                                      |
  355. ------------------------------------------------------------------------------*/
  356. #pragma export (ICompany::setAddressToDefault(),, 1324)
  357. ICompany& ICompany::setAddressToDefault ()
  358. {
  359.   if (address())
  360.     address()->setToDefault();
  361.   return *this;
  362. }
  363.  
  364. /*------------------------------------------------------------------------------
  365. | ICompany::setPhoneToDefault                                                  |
  366. |                                                                              |
  367. | Perform the setPhoneToDefault action.                                        |
  368. ------------------------------------------------------------------------------*/
  369. #pragma export (ICompany::setPhoneToDefault(),, 1325)
  370. ICompany& ICompany::setPhoneToDefault ()
  371. {
  372.   return setPhone("555-1212");
  373. }
  374.  
  375. /*------------------------------------------------------------------------------
  376. | ICompany::setCustomerListToDefault                                           |
  377. |                                                                              |
  378. | Perform the setCustomerListToDefault action.                                 |
  379. ------------------------------------------------------------------------------*/
  380. #pragma export (ICompany::setCustomerListToDefault(),, 1326)
  381. ICompany& ICompany::setCustomerListToDefault ()
  382. {
  383.   iCustomerList->removeAll ();
  384.   iCustomerList->addAsLast (new ICustomer("Al"));
  385.   iCustomerList->addAsLast (new ICustomer("Bob"));
  386.   iCustomerList->addAsLast (new ICustomer("Bruce"));
  387.   iCustomerList->addAsLast (new ICustomer("Dave"));
  388.   iCustomerList->addAsLast (new ICustomer("Delores"));
  389.   iCustomerList->addAsLast (new ICustomer("Diann"));
  390.   iCustomerList->addAsLast (new ICustomer("Don"));
  391.   iCustomerList->addAsLast (new ICustomer("Ed"));
  392.   iCustomerList->addAsLast (new ICustomer("Flora"));
  393.   iCustomerList->addAsLast (new ICustomer("Fred"));
  394.   iCustomerList->addAsLast (new ICustomer("George"));
  395.   iCustomerList->addAsLast (new ICustomer("Jim"));
  396.   iCustomerList->addAsLast (new ICustomer("Kat"));
  397.   iCustomerList->addAsLast (new ICustomer("Kathy"));
  398.   iCustomerList->addAsLast (new ICustomer("Ken"));
  399.   iCustomerList->addAsLast (new ICustomer("Lou"));
  400.   iCustomerList->addAsLast (new ICustomer("Mark"));
  401.   iCustomerList->addAsLast (new ICustomer("Michael"));
  402.   iCustomerList->addAsLast (new ICustomer("Morris"));
  403.   iCustomerList->addAsLast (new ICustomer("Peter"));
  404.   iCustomerList->addAsLast (new ICustomer("Rich"));
  405.   iCustomerList->addAsLast (new ICustomer("Ricky"));
  406.   iCustomerList->addAsLast (new ICustomer("Robert"));
  407.   iCustomerList->addAsLast (new ICustomer("Ron"));
  408.   iCustomerList->addAsLast (new ICustomer("Sherry"));
  409.   iCustomerList->addAsLast (new ICustomer("Steve"));
  410.   iCustomerList->addAsLast (new ICustomer("Susan"));
  411.   iCustomerList->addAsLast (new ICustomer("Terry"));
  412.   return *this;
  413. }
  414.  
  415. /*------------------------------------------------------------------------------
  416. | ICompany::operator == (const ICompany & aValue)                              |
  417. |                                                                              |
  418. ------------------------------------------------------------------------------*/
  419. #pragma export (ICompany::operator == (const ICompany&) const,, 1327)
  420. Boolean ICompany::
  421.   operator == (const ICompany& aValue) const
  422. {
  423.   if (name() != aValue.name()) {
  424.     return false;
  425.   } /* endif */
  426.   if (address() != aValue.address()) {
  427.     return false;
  428.   } /* endif */
  429.   if (customerList() != aValue.customerList()) {
  430.     return false;
  431.   } /* endif */
  432.   if (phone() != aValue.phone()) {
  433.     return false;
  434.   } /* endif */
  435.   return true;
  436. }
  437.  
  438. /*------------------------------------------------------------------------------
  439. | ICompany::operator != (const ICompany & aValue)                              |
  440. |                                                                              |
  441. ------------------------------------------------------------------------------*/
  442. #pragma export (ICompany::operator != (const ICompany&) const,, 1328)
  443. Boolean ICompany::
  444.   operator != (const ICompany& aValue) const
  445. {
  446.   if (name() != aValue.name()) {
  447.     return true;
  448.   } /* endif */
  449.   if (address() != aValue.address()) {
  450.     return true;
  451.   } /* endif */
  452.   if (customerList() != aValue.customerList()) {
  453.     return true;
  454.   } /* endif */
  455.   if (phone() != aValue.phone()) {
  456.     return true;
  457.   } /* endif */
  458.   return false;
  459. }
  460.  
  461. /*------------------------------------------------------------------------------
  462. | ICompany::operator == (const ICompany * aValue)                              |
  463. |                                                                              |
  464. ------------------------------------------------------------------------------*/
  465. #pragma export (ICompany::operator == (const ICompany*) const,, 1329)
  466. Boolean ICompany::
  467.   operator == (const ICompany* aValue) const
  468. {
  469.   if (name() != aValue->name()) {
  470.     return false;
  471.   } /* endif */
  472.   if (address() != aValue->address()) {
  473.     return false;
  474.   } /* endif */
  475.   if (customerList() != aValue->customerList()) {
  476.     return false;
  477.   } /* endif */
  478.   if (phone() != aValue->phone()) {
  479.     return false;
  480.   } /* endif */
  481.   return true;
  482. }
  483.  
  484. /*------------------------------------------------------------------------------
  485. | ICompany::operator != (const ICompany * aValue)                              |
  486. |                                                                              |
  487. ------------------------------------------------------------------------------*/
  488. #pragma export (ICompany::operator != (const ICompany*) const,, 1330)
  489. Boolean ICompany::
  490.   operator != (const ICompany* aValue) const
  491. {
  492.   if (name() != aValue->name()) {
  493.     return true;
  494.   } /* endif */
  495.   if (address() != aValue->address()) {
  496.     return true;
  497.   } /* endif */
  498.   if (customerList() != aValue->customerList()) {
  499.     return true;
  500.   } /* endif */
  501.   if (phone() != aValue->phone()) {
  502.     return true;
  503.   } /* endif */
  504.   return false;
  505. }
  506.