@@ -10,12 +10,53 @@ class BaseRegistry:
1010 """
1111
1212 def __init__ (self ):
13- self ._on_loaded_funcs = []
13+ self .file_map = {}
14+ self .file_meta = {}
1415
15- def on_loaded ( self , func ):
16- """Register functions to call when all data is loaded"""
17- self ._on_loaded_funcs . append ( func )
16+ @ property
17+ def count ( self ):
18+ return len ( self .file_map )
1819
19- def _on_loaded (self ):
20- for func in self ._on_loaded_funcs :
21- func ()
20+ def load (self , path , ** kwargs ):
21+ """Loads a resource or return existing one"""
22+ raise NotImplementedError ()
23+
24+ def load_deferred (self , path , ** kwargs ):
25+ """Register a resource for deferred loading"""
26+ raise NotImplementedError ()
27+
28+ def load_pool (self ):
29+ """Load all resource in the pool"""
30+ raise NotImplementedError ()
31+
32+ def delete (self , obj , destroy = False ):
33+ """
34+ Remove an object from the pool.
35+ This only removes the reference and will not actually destroy the object itself
36+ """
37+ for path , data in self .file_map .items ():
38+ if data == obj :
39+ del self .file_map [path ]
40+ del self .file_meta [path ]
41+ if destroy :
42+ self ._destroy (obj )
43+ break
44+
45+ def _destroy (self , obj ):
46+ """Destroys the object"""
47+ raise NotImplementedError ()
48+
49+ def flush (self , destroy = False ):
50+ """Delete all resources"""
51+ for obj in list (self .file_map .values ()):
52+ self .delete (obj , destroy = destroy )
53+
54+ def _find_last_of (self , file_path , finders ):
55+ """Find the last occurance of the file in finders"""
56+ found_path = None
57+ for finder in finders :
58+ path = finder .find (file_path )
59+ if path :
60+ found_path = path
61+
62+ return found_path
0 commit comments