home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / rapsheet / cppwv23 / iadrrmgr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  8.9 KB  |  237 lines

  1. /******************************************************************************
  2. * .FILE:        iadrrmgr.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation for the class, IAddressClientMgr               *
  5. *                                                                             *
  6. * .CLASSES:     IAddressClientMgr                                             *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #include "iadrrmgr.hpp"               //IAddressClientMgr header
  25. #include <inotifev.hpp>
  26. #include "irsltrec.hpp"               //IResultRecord header
  27. #include "iaddrrec.hpp"               //IAddressRecord header
  28.  
  29.  
  30. /*******************************************************************
  31.  * Events
  32.  *******************************************************************/
  33. INotificationId IAddressClientMgr :: parsedResultId = "IAddressClientMgr::parsedResult";
  34. INotificationId IAddressClientMgr :: resultBufferId = "IAddressClientMgr::resultBuffer";
  35. INotificationId IAddressClientMgr :: resultListId = "IAddressClientMgr::resultList";
  36. INotificationId IAddressClientMgr :: resultObjectId = "IAddressClientMgr::resultObject";
  37. INotificationId IAddressClientMgr :: resultWrapperId = "IAddressClientMgr::resultWrapper";
  38.  
  39. /*******************************************************************
  40.  * Constructors
  41.  *******************************************************************/
  42. IAddressClientMgr :: IAddressClientMgr() :
  43.         dResultBuffer(""),
  44.         dResultWrapper(0),
  45.         dResultListWrapper(new IVSequence <IAddress *>)
  46. {
  47.    enableNotification();
  48.    dResultListWrapper->enableNotification();
  49. }
  50.  
  51. /*******************************************************************
  52.  * Destructor
  53.  *******************************************************************/
  54. IAddressClientMgr :: ~IAddressClientMgr()
  55. {
  56.   ISequence<IAddress *> tempList;
  57.   IAddress *            address;
  58.  
  59. // if (dResultWrapper)
  60. //    delete dResultWrapper;
  61.   if (dResultListWrapper)
  62.   {
  63.      IVSequence<IAddress*>::Cursor cursor(*dResultListWrapper);
  64.      forCursor( cursor )
  65.        tempList.addAsFirst( dResultListWrapper->elementAt( cursor ) );
  66.  
  67.      dResultListWrapper->removeAll( );
  68.  
  69.      ISequence<IAddress*>::Cursor tempCursor( tempList );
  70.      forCursor( cursor )
  71.      {
  72.        address = tempList.elementAt ( tempCursor );
  73.        delete address;
  74.      }
  75.      tempList.removeAll( );
  76.  
  77.      delete dResultListWrapper;
  78.   }
  79. }
  80.  
  81.  
  82. /*******************************************************************
  83.  * Attribute Access Member Functions
  84.  *******************************************************************/
  85. /*------------------------------------------------------------------
  86.  * resultBuffer
  87.  *-----------------------------------------------------------------*/
  88. IString IAddressClientMgr :: resultBuffer () const
  89. {
  90.   return dResultBuffer;
  91. }
  92.  
  93. IAddressClientMgr & IAddressClientMgr ::
  94.   setResultBuffer (const IString & iResultBuffer)
  95. {
  96.   if (dResultBuffer != iResultBuffer)
  97.   {
  98.     dResultBuffer = iResultBuffer;
  99.     notifyObservers(INotificationEvent(resultBufferId, *this, true,
  100.                                IEventData((char *)iResultBuffer)));
  101.   } /* endif */
  102.   return *this;
  103. }
  104.  
  105. /*------------------------------------------------------------------
  106.  * resultList (read-only) and resultListWrapper
  107.  *-----------------------------------------------------------------*/
  108. IVSequence <IAddress *> IAddressClientMgr ::
  109.   resultList () const
  110. {
  111.   return *dResultListWrapper;
  112. }
  113.  
  114. IVSequence <IAddress *> * IAddressClientMgr ::
  115.   resultListWrapper () const
  116. {
  117.   return dResultListWrapper;
  118. }
  119.  
  120. /*------------------------------------------------------------------
  121.  * resultObject and resultWrapper (read-only)
  122.  *-----------------------------------------------------------------*/
  123. IAddress * IAddressClientMgr :: resultWrapper () const
  124. {
  125.   return dResultWrapper;
  126. }
  127.  
  128. IAddress IAddressClientMgr :: resultObject () const
  129. {
  130.   return *dResultWrapper;
  131. }
  132.  
  133.  
  134. /*******************************************************************
  135.  * Actions
  136.  *******************************************************************/
  137. /*------------------------------------------------------------------
  138.  * processResult()
  139.  *    The user controls when dResultBuffer should be processed.
  140.  *-----------------------------------------------------------------*/
  141. IAddressClientMgr & IAddressClientMgr :: processResult ()
  142. {
  143.    IAddress *         addressWrapper;
  144.    IAddressRecord     addressRec;
  145.    unsigned short     recOffset, i;
  146.    IString            buffer;
  147.  
  148.    IResultRecord resultRec(dResultBuffer);
  149.  
  150.    recOffset = 1;
  151.    for (i=0 ; i < resultRec.numResults(); i++)
  152.    {
  153.       addressWrapper = new IAddress;
  154.  
  155.       buffer = resultRec.resultData().subString(
  156.                recOffset,addressRec.size());
  157.       addressRec = buffer;
  158.  
  159.       addressWrapper->setStreet(addressRec.street());
  160.       addressWrapper->setCity(addressRec.city());
  161.       addressWrapper->setState(addressRec.state());
  162.       addressWrapper->setZip(addressRec.zip());
  163.  
  164.       addResult(addressWrapper);  //adds addressWrapper to
  165.                                   //the result list
  166.  
  167.       recOffset += addressRec.size();  //get the next addressRec
  168.    }
  169.    notifyObservers(INotificationEvent(parsedResultId, *this, false));
  170.    return *this;
  171. }
  172.  
  173. /*******************************************************************
  174.  * Class Member Functions
  175.  *******************************************************************/
  176. /*------------------------------------------------------------------
  177.  * addResult()
  178.  *-----------------------------------------------------------------*/
  179. IAddressClientMgr & IAddressClientMgr ::
  180.   addResult (IAddress * iAddressWrapper)
  181. {
  182.    if (dResultListWrapper->isEmpty())
  183.    {
  184.       setResultWrapper(iAddressWrapper);
  185.    }
  186.  
  187.    dResultListWrapper->add(iAddressWrapper);
  188.    return *this;
  189. }
  190.  
  191. /*------------------------------------------------------------------
  192.  * addResult()
  193.  *-----------------------------------------------------------------*/
  194. IAddressClientMgr & IAddressClientMgr ::
  195.   addResult (IAddress & iAddress)
  196. {
  197.    if (dResultListWrapper->isEmpty())
  198.    {
  199.       setResultWrapper(&iAddress);
  200.    }
  201.  
  202.    dResultListWrapper->add(&iAddress);
  203.    return *this;
  204. }
  205.  
  206. /*------------------------------------------------------------------
  207.  * setResultWrapper()
  208.  *-----------------------------------------------------------------*/
  209. IAddressClientMgr & IAddressClientMgr ::
  210.   setResultWrapper (IAddress * iResultWrapper)
  211. {
  212.   if (dResultWrapper != iResultWrapper)
  213.   {
  214.      if (dResultWrapper)
  215.         delete dResultWrapper;
  216.      dResultWrapper = iResultWrapper;
  217.      notifyObservers(INotificationEvent(resultObjectId, *this, false));
  218.      notifyObservers(INotificationEvent(resultWrapperId, *this, false));
  219.   }
  220.   return *this;
  221. }
  222.  
  223. /*------------------------------------------------------------------
  224.  * setResultWrapper()
  225.  *-----------------------------------------------------------------*/
  226. IAddressClientMgr & IAddressClientMgr ::
  227.   setResultWrapper (const IAddress & iResult)
  228. {
  229.   /*****************************************************************
  230.    * Have to make a copy of the IAddress object passed in since it's
  231.    * identified as being a const.  That is, the compiler won't
  232.    * allow dResultWrapper = &iResultWrapper, since it would allow
  233.    * us, via dResultWrapper, to update the IAddress object.
  234.    *****************************************************************/
  235.   return setResultWrapper(new IAddress(iResult));
  236. }
  237.