Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.46 KB | None | 0 0
  1. note
  2. description: "[
  3. Project-wide universal properties.
  4. This class is an ancestor to all developer-written classes.
  5. ANY may be customized for individual projects or teams.
  6. ]"
  7. library: "Free implementation of ELKS library"
  8. status: "See notice at end of class."
  9. legal: "See notice at end of class."
  10. date: "$Date: 2013-01-25 11:49:00 -0800 (Fri, 25 Jan 2013) $"
  11. revision: "$Revision: 92134 $"
  12.  
  13. class
  14. ANY
  15.  
  16. create
  17. default_create
  18.  
  19. feature -- Access
  20.  
  21. generator: STRING_8
  22. -- Name of current object's generating class
  23. -- (base class of the type of which it is a direct instance)
  24. external
  25. "built_in"
  26. ensure
  27. generator_not_void: Result /= Void
  28. generator_not_empty: not Result.is_empty
  29. end
  30.  
  31. generating_type: TYPE [detachable like Current]
  32. -- Type of current object
  33. -- (type of which it is a direct instance)
  34. do
  35. Result := {detachable like Current}
  36. ensure
  37. generating_type_not_void: Result /= Void
  38. end
  39.  
  40. feature -- Status report
  41.  
  42. conforms_to (other: ANY): BOOLEAN
  43. -- Does type of current object conform to type
  44. -- of `other' (as per Eiffel: The Language, chapter 13)?
  45. require
  46. other_not_void: other /= Void
  47. external
  48. "built_in"
  49. end
  50.  
  51. same_type (other: ANY): BOOLEAN
  52. -- Is type of current object identical to type of `other'?
  53. require
  54. other_not_void: other /= Void
  55. external
  56. "built_in"
  57. ensure
  58. definition: Result = (conforms_to (other) and other.conforms_to (Current))
  59. end
  60.  
  61. feature -- Comparison
  62.  
  63. is_equal (other: like Current): BOOLEAN
  64. -- Is `other' attached to an object considered
  65. -- equal to current object?
  66. require
  67. other_not_void: other /= Void
  68. external
  69. "built_in"
  70. ensure
  71. symmetric: Result implies other ~ Current
  72. consistent: standard_is_equal (other) implies Result
  73. end
  74.  
  75. frozen standard_is_equal (other: like Current): BOOLEAN
  76. -- Is `other' attached to an object of the same type
  77. -- as current object, and field-by-field identical to it?
  78. require
  79. other_not_void: other /= Void
  80. external
  81. "built_in"
  82. ensure
  83. same_type: Result implies same_type (other)
  84. symmetric: Result implies other.standard_is_equal (Current)
  85. end
  86.  
  87. frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
  88. -- Are `a' and `b' either both void or attached
  89. -- to objects considered equal?
  90. do
  91. if a = Void then
  92. Result := b = Void
  93. else
  94. Result := b /= Void and then a.is_equal (b)
  95. end
  96. ensure
  97. definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
  98. end
  99.  
  100. frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
  101. -- Are `a' and `b' either both void or attached to
  102. -- field-by-field identical objects of the same type?
  103. -- Always uses default object comparison criterion.
  104. do
  105. if a = Void then
  106. Result := b = Void
  107. else
  108. Result := b /= Void and then a.standard_is_equal (b)
  109. end
  110. ensure
  111. definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
  112. end
  113.  
  114. frozen is_deep_equal (other: like Current): BOOLEAN
  115. -- Are `Current' and `other' attached to isomorphic object structures?
  116. require
  117. other_not_void: other /= Void
  118. external
  119. "built_in"
  120. ensure
  121. shallow_implies_deep: standard_is_equal (other) implies Result
  122. same_type: Result implies same_type (other)
  123. symmetric: Result implies other.is_deep_equal (Current)
  124. end
  125.  
  126. frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
  127. -- Are `a' and `b' either both void
  128. -- or attached to isomorphic object structures?
  129. do
  130. if a = Void then
  131. Result := b = Void
  132. else
  133. Result := b /= Void and then a.is_deep_equal (b)
  134. end
  135. ensure
  136. shallow_implies_deep: standard_equal (a, b) implies Result
  137. both_or_none_void: (a = Void) implies (Result = (b = Void))
  138. same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
  139. symmetric: Result implies deep_equal (b, a)
  140. end
  141.  
  142. feature -- Duplication
  143.  
  144. frozen twin: like Current
  145. -- New object equal to `Current'
  146. -- twin calls copy; to change copying/twinning semantics, redefine copy.
  147. external
  148. "built_in"
  149. ensure
  150. twin_not_void: Result /= Void
  151. is_equal: Result ~ Current
  152. end
  153.  
  154. copy (other: like Current)
  155. -- Update current object using fields of object attached
  156. -- to `other', so as to yield equal objects.
  157. require
  158. other_not_void: other /= Void
  159. type_identity: same_type (other)
  160. external
  161. "built_in"
  162. ensure
  163. is_equal: Current ~ other
  164. end
  165.  
  166. frozen standard_copy (other: like Current)
  167. -- Copy every field of `other' onto corresponding field
  168. -- of current object.
  169. require
  170. other_not_void: other /= Void
  171. type_identity: same_type (other)
  172. external
  173. "built_in"
  174. ensure
  175. is_standard_equal: standard_is_equal (other)
  176. end
  177.  
  178. frozen clone (other: detachable ANY): like other
  179. obsolete "Use `twin' instead."
  180. -- Void if `other' is void; otherwise new object
  181. -- equal to `other'
  182. --
  183. -- For non-void `other', clone calls copy;
  184. -- to change copying/cloning semantics, redefine copy.
  185. do
  186. if other /= Void then
  187. Result := other.twin
  188. end
  189. ensure
  190. equal: Result ~ other
  191. end
  192.  
  193. frozen standard_clone (other: detachable ANY): like other
  194. obsolete "Use `standard_twin' instead."
  195. -- Void if `other' is void; otherwise new object
  196. -- field-by-field identical to `other'.
  197. -- Always uses default copying semantics.
  198. do
  199. if other /= Void then
  200. Result := other.standard_twin
  201. end
  202. ensure
  203. equal: standard_equal (Result, other)
  204. end
  205.  
  206. frozen standard_twin: like Current
  207. -- New object field-by-field identical to `other'.
  208. -- Always uses default copying semantics.
  209. external
  210. "built_in"
  211. ensure
  212. standard_twin_not_void: Result /= Void
  213. equal: standard_equal (Result, Current)
  214. end
  215.  
  216. frozen deep_twin: like Current
  217. -- New object structure recursively duplicated from Current.
  218. external
  219. "built_in"
  220. ensure
  221. deep_twin_not_void: Result /= Void
  222. deep_equal: deep_equal (Current, Result)
  223. end
  224.  
  225. frozen deep_clone (other: detachable ANY): like other
  226. obsolete "Use `deep_twin' instead."
  227. -- Void if `other' is void: otherwise, new object structure
  228. -- recursively duplicated from the one attached to `other'
  229. do
  230. if other /= Void then
  231. Result := other.deep_twin
  232. end
  233. ensure
  234. deep_equal: deep_equal (other, Result)
  235. end
  236.  
  237. frozen deep_copy (other: like Current)
  238. -- Effect equivalent to that of:
  239. -- copy (`other' . deep_twin)
  240. require
  241. other_not_void: other /= Void
  242. do
  243. copy (other.deep_twin)
  244. ensure
  245. deep_equal: deep_equal (Current, other)
  246. end
  247.  
  248. feature {NONE} -- Retrieval
  249.  
  250. frozen internal_correct_mismatch
  251. -- Called from runtime to perform a proper dynamic dispatch on `correct_mismatch'
  252. -- from MISMATCH_CORRECTOR.
  253. local
  254. l_msg: STRING_8
  255. l_exc: EXCEPTIONS
  256. do
  257. if attached {MISMATCH_CORRECTOR} Current as l_corrector then
  258. l_corrector.correct_mismatch
  259. else
  260. create l_msg.make_from_string ("Mismatch: ")
  261. create l_exc
  262. l_msg.append (generating_type.name)
  263. l_exc.raise_retrieval_exception (l_msg)
  264. end
  265. end
  266.  
  267. feature -- Output
  268.  
  269. Io: STD_FILES
  270. -- Handle to standard file setup
  271. once
  272. create Result
  273. Result.set_output_default
  274. ensure
  275. io_not_void: Result /= Void
  276. end
  277.  
  278. out: STRING_8
  279. -- New string containing terse printable representation
  280. -- of current object
  281. do
  282. Result := tagged_out
  283. ensure
  284. out_not_void: Result /= Void
  285. end
  286.  
  287. frozen tagged_out: STRING_8
  288. -- New string containing terse printable representation
  289. -- of current object
  290. external
  291. "built_in"
  292. ensure
  293. tagged_out_not_void: Result /= Void
  294. end
  295.  
  296. print (o: detachable ANY)
  297. -- Write terse external representation of `o'
  298. -- on standard output.
  299. do
  300. if o /= Void then
  301. Io.put_string (o.out)
  302. end
  303. end
  304.  
  305. feature -- Platform
  306.  
  307. Operating_environment: OPERATING_ENVIRONMENT
  308. -- Objects available from the operating system
  309. once
  310. create Result
  311. ensure
  312. operating_environment_not_void: Result /= Void
  313. end
  314.  
  315. feature {NONE} -- Initialization
  316.  
  317. default_create
  318. -- Process instances of classes with no creation clause.
  319. -- (Default: do nothing.)
  320. do
  321. end
  322.  
  323. feature -- Basic operations
  324.  
  325. default_rescue
  326. -- Process exception for routines with no Rescue clause.
  327. -- (Default: do nothing.)
  328. do
  329. end
  330.  
  331. frozen do_nothing
  332. -- Execute a null action.
  333. do
  334. end
  335.  
  336. frozen default: detachable like Current
  337. -- Default value of object's type
  338. do
  339. end
  340.  
  341. frozen default_pointer: POINTER
  342. -- Default value of type `POINTER'
  343. -- (Avoid the need to write `p'.default for
  344. -- some `p' of type `POINTER'.)
  345. do
  346. end
  347.  
  348. frozen as_attached: attached like Current
  349. -- Attached version of Current
  350. -- (Can be used during transitional period to convert
  351. -- non-void-safe classes to void-safe ones.)
  352. do
  353. Result := Current
  354. end
  355.  
  356. invariant
  357. reflexive_equality: standard_is_equal (Current)
  358. reflexive_conformance: conforms_to (Current)
  359.  
  360. note
  361. copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
  362. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  363. source: "[
  364. Eiffel Software
  365. 5949 Hollister Ave., Goleta, CA 93117 USA
  366. Telephone 805-685-1006, Fax 805-685-6869
  367. Website http://www.eiffel.com
  368. Customer support http://support.eiffel.com
  369. ]"
  370.  
  371. end -- class ANY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement