home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / RAPSHEET / CPPOV23 / IADRRMGR.CPP < prev    next >
Text File  |  1995-05-22  |  8KB  |  215 lines

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