home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSSRC.ZIP / OBJECT.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  11KB  |  419 lines

  1. //
  2. // This file contains proprietary information of Borland International.
  3. // Copying or reproduction without prior written approval is prohibited.
  4. //
  5. // Copyright (c) 1990
  6. // Borland International
  7. // 1800 Scotts Valley Dr.
  8. // Scotts Valley, CA 95066
  9. // (408) 438-8400
  10. //
  11.  
  12. // Contents ----------------------------------------------------------------
  13. //
  14. //      Object::~Object
  15. //      Object::isSortable
  16. //      Object::isAssociation 
  17. //      Object::operator new
  18. //      Object::forEach
  19. //      Object::firstThat 
  20. //      Object::lastThat  
  21. //      Object::operator delete 
  22. //
  23. //      Error::~Error
  24. //      Error::isA
  25. //      Error::nameOf 
  26. //      Error::printOn
  27. //      Error::hashValue  
  28. //      Error::isEqual
  29. //
  30. //      theErrorObject
  31. //         Object::ZERO                            initializer
  32. //
  33. // Description
  34. //
  35. //
  36. // End ---------------------------------------------------------------------
  37.  
  38. // Interface Dependencies ---------------------------------------------------
  39.  
  40. #ifndef __OBJECT_H
  41. #include <object.h>
  42. #endif
  43.  
  44. // End Interface Dependencies ------------------------------------------------
  45.  
  46.  
  47. Object::~Object()
  48.  
  49. // Summary -----------------------------------------------------------------
  50. //
  51. //      Default destructor for an object.  Doesn't do much, but it
  52. //      forces all classes derived from Object to have virtual
  53. //      destructors, which is essential for proper cleanup.  It also
  54. //      provides a good place for setting breakpoints, because every
  55. //      time an object gets destroyed, this function will be called.
  56. //
  57. // End ---------------------------------------------------------------------
  58. {
  59. }
  60. // End Destructor Object::~Object //
  61.  
  62.  
  63. // Member Function //
  64.  
  65. int Object::isSortable() const
  66.  
  67. // Summary -----------------------------------------------------------------
  68. //
  69. //      indicates whether the object defines comparison operators
  70. //
  71. // Parameters
  72. //
  73. //      none
  74. //
  75. // Remarks
  76. //
  77. //      A basic Object is not sortable
  78. //
  79. // End ---------------------------------------------------------------------
  80. {
  81.     return 0;
  82. }
  83. // End Member Function Object::isSortable //
  84.  
  85.  
  86. // Member Function //
  87.  
  88. int Object::isAssociation() const
  89.  
  90. // Summary -----------------------------------------------------------------
  91. //
  92. //      indicates whether the object is derived from class Association
  93. //
  94. // Parameters
  95. //
  96. //      none
  97. //
  98. // Remarks
  99. //
  100. //      A basic Object is not derived from class Association
  101. //
  102. // End ---------------------------------------------------------------------
  103. {
  104.     return 0;
  105. }
  106. // End Member Function Object::isAssociation //
  107.  
  108.  
  109. // Member Function //
  110.  
  111. void *Object::operator new( size_t s )
  112.  
  113. // Summary -----------------------------------------------------------------
  114. //
  115. //      replacement for the standard operator new().  Returns ZERO
  116. //      if attempted allocation fails.
  117. //
  118. // Parameters
  119. //
  120. //      s
  121. //
  122. //      number of bytes to allocate
  123. //
  124. // Functional Description
  125. //
  126. //      we call the global operator new() and check whether it succeeded.
  127. //      If it succeeded, we return the block that it allocated.  If it
  128. //      failed, we return ZERO.
  129. //
  130. // End ---------------------------------------------------------------------
  131. {
  132.     void *allocated = ::operator new( s );
  133.     if( allocated == 0 )
  134.         return ZERO;
  135.     else
  136.         return allocated;
  137. }
  138. // End Member Function Object::operator new //
  139.  
  140.  
  141. // Member Function //
  142.  
  143. void Object::forEach( iterFuncType actionPtr, void *paramListPtr )
  144.  
  145. // Summary -----------------------------------------------------------------
  146. //
  147. //      Calls the given iterator function on this object.
  148. //
  149. // Parameters
  150. //
  151. //      actionPtr
  152. //
  153. //      Pointer to the action routine which is to be called for this object.
  154. //
  155. //      paramListPtr
  156. //
  157. //      Pointer to the list of parameters which will be passed along to
  158. //      the action routine.
  159. //
  160. // Functional Description
  161. //
  162. //      We call the given function, passing our object and the list of
  163. //      parameters that was given to us.
  164. //
  165. // Remarks
  166. //
  167. //  warnings:
  168. //      The action routine must have a prototype of the form:
  169. //          void action( Object&, void * );
  170. //
  171. // End ---------------------------------------------------------------------
  172. {
  173.     ( *actionPtr )( *this, paramListPtr );
  174. }
  175. // End Member Function Object::forEach //
  176.  
  177.  
  178. // Member Function //
  179.  
  180. Object& Object::firstThat( condFuncType testFuncPtr, void *paramListPtr ) const
  181.  
  182. // Summary -----------------------------------------------------------------
  183. //
  184. //      Calls the given conditional test function on this object.
  185. //
  186. // Parameters
  187. //
  188. //      testFuncPtr
  189. //
  190. //      Pointer to the conditional test routine which is to be called 
  191. //      for this object.
  192. //
  193. //      paramListPtr
  194. //
  195. //      Pointer to the list of parameters which will be passed along to
  196. //      the conditional test routine.
  197. //
  198. // Return Value
  199. //
  200. //      Returns this if the this satisfies the condition.  Returns
  201. //      NOOBJECT otherwise.
  202. //
  203. // Functional Description
  204. //
  205. //      We call the given function, passing our object and the list of
  206. //      parameters that was given to us.  If the function returns
  207. //      a 1, we return this object, otherwise we return NOOBJECT.
  208. //
  209. // Remarks
  210. //
  211. //  warnings:
  212. //      The conditional test routine must have a prototype of the form:
  213. //          int test( Object&, void * );
  214. //      The conditional test routine must return 1 if the given object
  215. //      satisfies the condition.
  216. //
  217. // End ---------------------------------------------------------------------
  218. {
  219.     if( ( *testFuncPtr )( *this, paramListPtr ) )
  220.     {
  221.         return( *this );
  222.     }
  223.     else // our object doesn't satisfy the condition //
  224.     {
  225.         return( NOOBJECT );
  226.     }
  227. }
  228. // End Member Function Object::firstThat //
  229.  
  230.  
  231. // Member Function //
  232.  
  233. Object& Object::lastThat( condFuncType testFuncPtr, void *paramListPtr ) const
  234.  
  235. // Summary -----------------------------------------------------------------
  236. //
  237. //      Calls the given conditional test function on this object.  For
  238. //      non-container objects, lastThat is the same as firstThat.
  239. //
  240. // Parameters
  241. //
  242. //      testFuncPtr
  243. //
  244. //      Pointer to the conditional test routine which is to be called 
  245. //      for this object.
  246. //
  247. //      paramListPtr
  248. //
  249. //      Pointer to the list of parameters which will be passed along to
  250. //      the conditional test routine.
  251. //
  252. // Functional Description
  253. //
  254. //      We call the firstThat function.
  255. //
  256. // Remarks
  257. //
  258. //  warnings:
  259. //      The conditional test routine must have a prototype of the form:
  260. //          int test( Object&, void * );
  261. //      The conditional test routine must return 1 if the given object
  262. //      satisfies the condition.
  263. //
  264. // End ---------------------------------------------------------------------
  265. {
  266.     return Object::firstThat( testFuncPtr, paramListPtr );
  267. }
  268. // End Member Function Object::lastThat //
  269.  
  270.  
  271. // Destructor //
  272.  
  273. Error::~Error()
  274.  
  275. // Description -------------------------------------------------------------
  276. //
  277. //      We can't really destroy theErrorObject.
  278. //
  279. // End ---------------------------------------------------------------------
  280. {
  281. }
  282. // End Destructor Error::~Error //
  283.  
  284.  
  285. // Member Function //
  286.  
  287. void Error::operator delete( void * )
  288.  
  289. // Summary -----------------------------------------------------------------
  290. //
  291. //      Can't delete an Error object... so we pretend that we did.
  292. //
  293. // End ---------------------------------------------------------------------
  294. {
  295. }
  296. // End Member Function Error::operator delete //
  297.  
  298. // Member Function //
  299.  
  300. classType Error::isA() const
  301.  
  302. // Summary -----------------------------------------------------------------
  303. //
  304. //         Returns the class type of the error object.
  305. //
  306. // End ---------------------------------------------------------------------
  307. {
  308.     return errorClass; 
  309. }
  310. // End Member Function Error::isA //
  311.  
  312.  
  313. // Member Function //
  314.  
  315. char *Error::nameOf() const
  316.  
  317. // Summary -----------------------------------------------------------------
  318. //
  319. //         Returns a pointer to the character string "Error."
  320. //
  321. // End ---------------------------------------------------------------------
  322. {
  323.     return "Error";
  324. }
  325. // End Member Function Error::nameOf //
  326.  
  327.  
  328. // Member Function //
  329.  
  330. void Error::printOn( ostream& outputStream ) const
  331.  
  332. // Summary -----------------------------------------------------------------
  333. //
  334. //      Error class override of the usual printOn.  Since there isn't
  335. //      really any object to print, we emit an appropriate message.
  336. //
  337. // Parameters
  338. //
  339. //     outputStream
  340. //     The stream on which to display the formatted contents of the object.
  341. //
  342. // End ---------------------------------------------------------------------
  343. {
  344.     outputStream << "Error\n";
  345. }
  346. // End Member Function Error::printOn //
  347.  
  348.  
  349. // Member Function //
  350.  
  351. hashValueType   Error::hashValue() const
  352.  
  353. // Summary -----------------------------------------------------------------
  354. //
  355. //      Returns the value for use when hashing an error object.
  356. //      There should be only one object of class Error, so it's ok
  357. //      to return the same value every time.
  358. //
  359. // End ---------------------------------------------------------------------
  360. {
  361.     return ERROR_CLASS_HASH_VALUE;
  362. }
  363. // End Member Function Error::hashValue //
  364.  
  365.  
  366. // Member Function //
  367.  
  368. int Error::isEqual ( const Object& testObject ) const
  369.  
  370. // Summary -----------------------------------------------------------------
  371. //
  372. //      Determines whether the given object is theErrorObject.
  373. //
  374. // Parameters
  375. //
  376. //      testObject
  377. //
  378. //      The object we are testing against theErrorObject.
  379. //
  380. // Return Value
  381. //
  382. //      Returns 1 if the given object is theErrorObject, 0 otherwise.
  383. //
  384. // Functional Description
  385. //
  386. //      The only way we get called here is if this is a pointer to 
  387. //      theErrorObject.  We test the address of our given object to see
  388. //      if it is the address of theErrorObject.
  389. //
  390. // End ---------------------------------------------------------------------
  391. {
  392.     return &testObject == this;
  393. }
  394. // End Member Function Error::isEqual //
  395.  
  396.  
  397. // Variable //
  398.  
  399. Error    theErrorObject;
  400.  
  401. // Description -------------------------------------------------------------
  402. //
  403. //      Defines a dummy object to which Object::ZERO will point.  We only
  404. //      need this so we don't ever try to dereference a null pointer.
  405. //
  406. // End ---------------------------------------------------------------------
  407.  
  408.  
  409. // Initializer //
  410.  
  411. Object *Object::ZERO = (Object *)&theErrorObject;
  412.  
  413. // Description -------------------------------------------------------------
  414. //
  415. //      Initializes Object::ZERO.   We wait to do this here because we
  416. //      have to get theErrorObject defined before we initialize Object::ZERO.
  417. //
  418. // End ---------------------------------------------------------------------
  419.