home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / COMPILER / SAMPLE06 / GENTREE.HPP < prev    next >
Text File  |  1993-04-03  |  4KB  |  70 lines

  1. //+----------------------------------------------------------------------------+
  2. //|                                                                            |
  3. //| GENTREE.HPP                                                                |
  4. //|                                                                            |
  5. //| COPYRIGHT:                                                                 |
  6. //| ----------                                                                 |
  7. //|  Copyright (C) International Business Machines Corp., 1992,1993.           |
  8. //|                                                                            |
  9. //| DISCLAIMER OF WARRANTIES:                                                  |
  10. //| -------------------------                                                  |
  11. //|  The following [enclosed] code is sample code created by IBM Corporation.  |
  12. //|  This sample code is not part of any standard IBM product and is provided  |
  13. //|  to you solely for the purpose of assisting you in the development of      |
  14. //|  your applications.  The code is provided "AS IS", without warranty of     |
  15. //|  any kind.  IBM shall not be liable for any damages arising out of your    |
  16. //|  use of the sample code, even if they have been advised of the             |
  17. //|  possibility of such damages.                                              |
  18. //|                                                                            |
  19. //| REVISION LEVEL: 1.0                                                        |
  20. //| ---------------                                                            |
  21. //|                                                                            |
  22. //+----------------------------------------------------------------------------+
  23. //| Class Name : GenTree<T>                                                    |
  24. //|                                                                            |
  25. //| Purpose    : Create a Template Class to encapsulate TreeNode members.      |
  26. //|              This class uses the TreeData class, and is still quite        |
  27. //|              dependent on its functions.  We are slowly evolving into the  |
  28. //|              full use of templates.                                        |
  29. //|                                                                            |
  30. //| Author     : njC Sales                                                     |
  31. //| Date       : 27 October 1992                                               |
  32. //+----------------------------------------------------------------------------+
  33. #ifndef GENTREE_HPP_INCLUDED
  34. #define GENTREE_HPP_INCLUDED
  35. #include "treenode.hpp"
  36.  
  37. template <class T> class GenTree : public TreeNode
  38. {
  39.  
  40. public:
  41.    GenTree(): TreeNode(), MyData() {}
  42.    virtual ~GenTree() {}
  43.  
  44.    virtual void display()
  45.    {
  46.       printf("Data  = %s\n",(char *)MyData.getData());
  47.       printf("State = %d\n",(short)getState());
  48.    }
  49.  
  50.    GenTree(const T   &pType) :
  51.       TreeNode(), MyData(pType){}
  52.    GenTree(GenTree<T>   *pDataInTree);
  53.    GenTree(const GenTree<T>   &rDataInTree);
  54.    GenTree<T> &operator= (const GenTree<T>   &rDataInTree);
  55.  
  56. //+----------------------------------------------------------------------------+
  57. //| The following functions are not general enough, and are suitable only for  |
  58. //| the purpose of template testing.                                           |
  59. //| They assume that the datatype passed as template parm has the setData and  |
  60. //| getData methods. In general, this is not a wise assumption.                |
  61. //+----------------------------------------------------------------------------+
  62.  
  63.    virtual void SetData(void *pString) {MyData.setData(pString); }
  64.    virtual void *GetData() const       {return MyData.getData(); }
  65.  
  66. protected:
  67.    T       MyData;
  68. };
  69. #endif
  70.