home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / istrgen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  3.2 KB  |  107 lines

  1. /*******************************************************************************
  2. * FILE NAME: istrgen.cpp                                                       *
  3. *                                                                              *
  4. * DESCRIPTION:                                                                 *
  5. *   This file contains the implementation of classes/functions declared        *
  6. *   in istrgen.hpp.                                                            *
  7. *                                                                              *
  8. * COPYRIGHT:                                                                   *
  9. *   IBM Open Class Library                                                     *
  10. *   (C) Copyright International Business Machines Corporation 1992, 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. *******************************************************************************/
  16. #include <istrgen.hpp>
  17.  
  18.  
  19. template <class T>
  20.   IStringGeneratorMemberFn<T> ::
  21.     IStringGeneratorMemberFn ( IString ( T :: *member )( ) )
  22.     : memberFunction( member )
  23. {
  24. }
  25.  
  26. template <class T>
  27.   IStringGeneratorMemberFn<T> ::
  28.    ~IStringGeneratorMemberFn ( )
  29. {
  30. }
  31.  
  32. template <class T>
  33.   IString  IStringGeneratorMemberFn<T> :: stringFor ( const T& object )
  34. {
  35.   T *  pobject = (T *)&object;
  36.   return (pobject->*memberFunction)( );
  37. }
  38.  
  39. template <class T, class U>
  40.   IStringGeneratorRefMemberFn<T,U> ::
  41.     IStringGeneratorRefMemberFn ( IString ( U :: *member )( ) )
  42.     : memberFunction( member )
  43. {
  44. }
  45.  
  46. template <class T, class U>
  47.   IStringGeneratorRefMemberFn<T,U> ::
  48.    ~IStringGeneratorRefMemberFn ( )
  49. {
  50. }
  51.  
  52. template <class T, class U>
  53.   IString  IStringGeneratorRefMemberFn<T,U> :: stringFor ( const T& object )
  54. {
  55.   return  (object->*memberFunction)( );
  56. }
  57.  
  58.  
  59. template <class Element>
  60.   IStringGenerator<Element> ::
  61.     IStringGenerator( const IReference < IStringGeneratorFn<Element> >&
  62.                          generatorFunction )
  63.     : fgeneratorFunction( generatorFunction )
  64. {
  65.   if ( fgeneratorFunction )
  66.     fgeneratorFunction->addRef( );
  67. }
  68.  
  69.  
  70. template <class Element>
  71.   IStringGenerator<Element> ::
  72.     IStringGenerator( const IStringGenerator<Element>&
  73.                          stringGenerator )
  74.     : fgeneratorFunction( stringGenerator.fgeneratorFunction )
  75. {
  76. }
  77.  
  78.  
  79. template <class Element>
  80.   IStringGenerator<Element>&
  81.     IStringGenerator<Element> ::
  82.       operator=( const IStringGenerator<Element>&
  83.                     stringGenerator )
  84. {
  85.   fgeneratorFunction = stringGenerator.fgeneratorFunction;
  86.   return *this;
  87. }
  88.  
  89.  
  90. template <class Element>
  91.   IStringGenerator<Element> :: ~IStringGenerator ( )
  92. {
  93. }
  94.  
  95.  
  96. template <class Element>
  97.   IString IStringGenerator<Element> ::
  98.     stringFor ( const Element& element ) const
  99. {
  100.  
  101.   return fgeneratorFunction
  102.             ? fgeneratorFunction->stringFor( element )
  103.             : element->asString()     //This assumes an Element==Object*
  104.             ;
  105. }
  106.  
  107.