PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

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