/src/lib/backtracking/internal/abstract_backtracking_pool.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 38 code · 7 blank · 32 comment · 1 complexity · a0c35bc9a329b955d51f5d0cd25e0176 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class ABSTRACT_BACKTRACKING_POOL[X_ -> ABSTRACT_BACKTRACKING_POOLABLE]
  5. --
  6. -- Pools for the ABSTRACT_BACKTRACKING
  7. --
  8. feature {ANY}
  9. get_instance: X_
  10. -- Returns an instance from the current pool.
  11. local
  12. link: X_
  13. do
  14. Result := pool_of_instances.item
  15. if Result = Void then
  16. Result := get_fresh_instance
  17. else
  18. link ?= Result.pool_link
  19. pool_of_instances.set_item(link)
  20. end
  21. ensure
  22. result_not_void: Result /= Void
  23. end
  24. get_fresh_instance: X_
  25. -- Returns a freshly created instance.
  26. deferred
  27. end
  28. release_instance (inst: X_)
  29. -- Records the instance 'inst' into the current pool.
  30. do
  31. inst.set_pool_link(pool_of_instances.item)
  32. pool_of_instances.set_item(inst)
  33. ensure
  34. instance_on_top: pool_of_instances.item = inst
  35. previous_top_chained: inst.pool_link = old pool_of_instances.item
  36. end
  37. clear
  38. -- Removes all recorded instances from the current pool.
  39. do
  40. pool_of_instances.set_item(Void)
  41. end
  42. feature {}
  43. pool_of_instances: WEAK_REFERENCE[X_]
  44. -- Head of the recorded instances
  45. make
  46. -- creation
  47. do
  48. create pool_of_instances.set_item(Void)
  49. end
  50. end -- class ABSTRACT_BACKTRACKING_POOL
  51. --
  52. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  53. --
  54. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  55. -- of this software and associated documentation files (the "Software"), to deal
  56. -- in the Software without restriction, including without limitation the rights
  57. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  58. -- copies of the Software, and to permit persons to whom the Software is
  59. -- furnished to do so, subject to the following conditions:
  60. --
  61. -- The above copyright notice and this permission notice shall be included in
  62. -- all copies or substantial portions of the Software.
  63. --
  64. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  65. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  66. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  67. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  68. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  69. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  70. -- THE SOFTWARE.