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