#include <defsregistry.hpp>
Public Member Functions | |
| template<class TAR> | |
| Iter< TAR > | candidates (const Query< TAR > &query) |
| find a sequence of "default" objects possibliy matching the query. | |
| template<class TAR> | |
| string | dump () |
| helper for diagnostics. | |
| template<class TAR> | |
| bool | forget (const P< TAR > &obj) |
| if this object is registered as "default" in some way, drop the registration. | |
| template<class TAR> | |
| bool | put (P< TAR > &obj, const Query< TAR > &query) |
| register the object as being "default" when searching something similar as designated by the given query. | |
Private Attributes | |
| Table | table_ |
Classes | |
| class | Iter |
| used for enumerating solutions More... | |
For internal use only.
Helper for organizing preconfigured default objects. Maintaines a collection of objects known or encountered as "default" for a given type. This collection is ordered by "degree of constriction", which is implemented by counting the number of predicates in the query used to define or identify each object. Accessing an object identified by a query causes the query to be resolved (executed in prolog), which may result in some additional properties of the object being bound or specified.
Definition at line 177 of file defsregistry.hpp.
| Iter<TAR> mobject::session::DefsRegistry::candidates | ( | const Query< TAR > & | query | ) | [inline] |
If there was a registration for some object of the given kind with the same query, this one will be first in the sequence. Besides, the sequence will yield all still existing registered "default" objects of this kind, ordered ascending by "degree of constriction", i.e. starting with the object registered togehter with the shortest query.
Definition at line 239 of file defsregistry.hpp.
00240 { 00241 P<TAR> dummy; 00242 Record<TAR> entry (query, dummy); 00243 typedef typename Slot<TAR>::Registry Registry; 00244 Registry& registry = Slot<TAR>::access(table_); 00245 00246 // try to get a possible direct match (same query) 00247 typename Registry::iterator pos = registry.find (entry); 00248 typename Registry::iterator end = registry.end(); 00249 00250 if (pos==end) 00251 return Iter<TAR> (registry.begin(), end); // just ennumerate contents 00252 else 00253 return Iter<TAR> (pos, registry.begin(), end); // start with direct match 00254 }
| string mobject::session::DefsRegistry::dump | ( | ) | [inline] |
Definition at line 308 of file defsregistry.hpp.
00309 { 00310 string res; 00311 util::for_each ( Slot<TAR>::access(table_) 00312 , var(res) += _1 00313 ); 00314 return res; 00315 }
| bool mobject::session::DefsRegistry::forget | ( | const P< TAR > & | obj | ) | [inline] |
Definition at line 294 of file defsregistry.hpp.
00295 { 00296 typedef typename Slot<TAR>::Registry Registry; 00297 typedef typename Record<TAR>::Search SearchFunc; 00298 00299 Registry& registry = Slot<TAR>::access(table_); 00300 return util::remove_if(registry, SearchFunc (obj)); 00301 }
| bool mobject::session::DefsRegistry::put | ( | P< TAR > & | obj, | |
| const Query< TAR > & | query | |||
| ) | [inline] |
Only a weak ref is stored.
| obj | Will be rebound, if another object is already stored. |
Definition at line 265 of file defsregistry.hpp.
00266 { 00267 Record<TAR> entry (query, obj); 00268 typedef typename Slot<TAR>::Registry Registry; 00269 typedef typename Registry::iterator RIter; 00270 00271 Registry& registry = Slot<TAR>::access(table_); 00272 RIter pos = registry.lower_bound (entry); 00273 if ( pos!=registry.end() 00274 && pos->query == query) 00275 { 00276 P<TAR> storedObj (pos->objRef.lock()); 00277 if (storedObj) 00278 return (storedObj == obj); 00279 else 00280 // use the opportunity and purge the expired entry 00281 registry.erase(pos++); 00282 } 00283 // no existing entry.... 00284 registry.insert(pos, entry); 00285 ENSURE (registry.find (entry) != registry.end()); 00286 return true; 00287 }
1.5.5