home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / COMPILER / AUTHORS / TREEDATA.CPP < prev    next >
Text File  |  1993-04-03  |  5KB  |  92 lines

  1. //+----------------------------------------------------------------------------+
  2. //| TREEDATA.CPP                                                               |
  3. //|                                                                            |
  4. //| COPYRIGHT:                                                                 |
  5. //| ----------                                                                 |
  6. //|  Copyright (C) International Business Machines Corp., 1992,1993.           |
  7. //|                                                                            |
  8. //| DISCLAIMER OF WARRANTIES:                                                  |
  9. //| -------------------------                                                  |
  10. //|  The following [enclosed] code is sample code created by IBM Corporation.  |
  11. //|  This sample code is not part of any standard IBM product and is provided  |
  12. //|  to you solely for the purpose of assisting you in the development of      |
  13. //|  your applications.  The code is provided "AS IS", without warranty of     |
  14. //|  any kind.  IBM shall not be liable for any damages arising out of your    |
  15. //|  use of the sample code, even if they have been advised of the             |
  16. //|  possibility of such damages.                                              |
  17. //|                                                                            |
  18. //| REVISION LEVEL: 1.0                                                        |
  19. //| ---------------                                                            |
  20. //|                                                                            |
  21. //+----------------------------------------------------------------------------+
  22. //| Class Name  : TREEDATA                                                     |
  23. //| Purpose     : This class encapulates the data part of a TreeNode.          |
  24. //|               This 'encapsulation' is necessary because the 'data' portion |
  25. //|               could really be 'data', but it could also be another         |
  26. //|               TreeNode.                                                    |
  27. //| Usage note  : Methods in this class are accessible from friends and        |
  28. //|               relations only. You cannot instantiate from this class.      |
  29. //| Author      : njC Sales                                                    |
  30. //| Date        : 27 October 1992                                              |
  31. //+----------------------------------------------------------------------------+
  32.  
  33. #include "treedata.hpp"
  34.  
  35. //+----------------------------------------------------------------------------+
  36. //| Define constructor with a void * argument, ie. anything but a TreeNode,    |
  37. //| ie. a user-defined type (known only to the user).                          |
  38. //+----------------------------------------------------------------------------+
  39. TreeData::TreeData(void *pString)
  40. {
  41.    if (pString == NULL)
  42.       myData=  NULL;
  43.    else
  44.       myData= pString;
  45. }
  46.  
  47. //+----------------------------------------------------------------------------+
  48. //| Define constructor with a TreeNode * argument.                             |
  49. //| This data type is our creation.                                            |
  50. //+----------------------------------------------------------------------------+
  51. TreeData::TreeData(TreeData *pTreeData)
  52. {
  53.    if (pTreeData == NULL)
  54.       myData= NULL;
  55.    else
  56.       myData= pTreeData;
  57. }
  58.  
  59. //+----------------------------------------------------------------------------+
  60. //| Define a copy constructor.                                                 |
  61. //| We will implement only a shallow copy until a deep copy is required.       |
  62. //+----------------------------------------------------------------------------+
  63. TreeData::TreeData(const TreeData &tData)
  64. {
  65.    myData= tData.myData;
  66. }
  67.  
  68. //+----------------------------------------------------------------------------+
  69. //| Define the destructor.                                                     |
  70. //| Since we don't allocate anything, we just do a quick return and let the    |
  71. //| compiler clean up after us.                                                |
  72. //+----------------------------------------------------------------------------+
  73. TreeData::~TreeData() {}
  74.  
  75. //+----------------------------------------------------------------------------+
  76. //| Define the assignment operator                                             |
  77. //+----------------------------------------------------------------------------+
  78. TreeData &TreeData::operator= (const TreeData &tData)
  79. {
  80.    if (this != &tData)
  81.       myData= tData.myData;
  82.    return *this;
  83. }
  84.  
  85. //+----------------------------------------------------------------------------+
  86. //| Define a display in the default case where the data is a string.           |
  87. //+----------------------------------------------------------------------------+
  88. void TreeData::display()
  89. {
  90.    printf("Data  = %s\n",(char *)myData);
  91. }
  92.