7 #ifndef __core_Catalog_h__ 8 #define __core_Catalog_h__ 10 #define FE_CAT_SPEC(name, description) name 11 #define FE_CAT(name) name 33 bool operator==(
const Remove &other)
const {
return true; }
55 U32 catalogSize(
void)
const;
61 String catalogKey(U32 index)
const;
74 String a_pattern=
".*")
const;
83 void catalogProperties(
String a_name,
91 BWORD cataloged(
String a_name,
97 BWORD catalogedAny(
String a_name)
const;
100 void catalogClear(
void);
109 BWORD a_shallow=FALSE);
163 const fe_type_info& catalogTypeInfo(
String a_name,
179 BWORD catalogTypeIs(
String a_name,
217 const T& catalogOrDefault(
String a_name,
String a_property,
218 const T& a_default)
const;
220 const T& catalogOrDefault(
String a_name,
221 const T& a_default)
const 222 {
return catalogOrDefault(a_name,
223 "value",a_default); }
234 String a_property=
"value")
const;
244 I32 catalogBytes(
String a_name,
257 BWORD catalogSet(
String a_name,
260 BWORD catalogSet(
String a_name,
262 {
return catalogSet(a_name,
278 BWORD catalogSet(
String a_name,
295 BWORD catalogSet(
String a_name,
298 const U8* a_pRawBytes,
311 T& catalogOrException(
String a_name,
322 bool catalogLookup(
const String a_name,
325 bool catalogLookup(
const String a_name,
327 {
return catalogLookup(a_name,
"value",
331 void catalogMoveToEnd(
String a_name);
334 void catalogRemove(
String a_name);
342 void catalogDump(
void)
const;
349 T& createInstance(
String a_name,
350 String a_property=
"value");
352 std::map< String, InstanceMap > m_instanceMapMap;
353 std::map< I32, String > m_orderMap;
360 if(!catalogedAny(a_name))
362 m_orderMap[++m_highest]=a_name;
364 T& rT=m_instanceMapMap[a_name][a_property].create<T>(typeMaster());
366 Counted::trackReference(&rT,
this,
"Catalog "+FE_TYPESTRING(T));
374 if(!cataloged(a_name,a_property))
376 return createInstance<T>(a_name,a_property);
378 return m_instanceMapMap[a_name][a_property].cast<T>();
384 if(!cataloged(a_name,a_property))
386 createInstance<T>(a_name,a_property)=a_default;
388 return m_instanceMapMap[a_name][a_property].cast<T>();
393 const T& a_default)
const 395 std::map<String, InstanceMap>::const_iterator it=
396 m_instanceMapMap.find(a_name);
397 if(it==m_instanceMapMap.end())
402 const std::map<String, Instance>& instanceMap=it->second;
404 std::map<String, Instance>::const_iterator it2=
405 instanceMap.find(a_property);
406 if(it2==instanceMap.end())
411 return it2->second.cast<T>();
417 std::map<String, InstanceMap>::const_iterator it=
418 m_instanceMapMap.find(a_name);
419 if(it==m_instanceMapMap.end())
421 feX(
"Catalog::catalogOrException",
422 (
"missing key '" + a_name +
"'").c_str());
425 const std::map<String, Instance>& instanceMap=it->second;
427 std::map<String, Instance>::const_iterator it2=
428 instanceMap.find(a_property);
429 if(it2==instanceMap.end())
431 feX(
"Catalog::catalogOrException",
432 (
"missing property '" + a_property +
433 "' for '" + a_name +
"'").c_str());
436 return it2->second.cast<T>();
443 createInstance< sp<Component> >(a_name,a_property);
445 rspComponent=a_spComponent;
447 return a_spComponent;
452 if(!catalogedAny(a_name))
454 m_orderMap[++m_highest]=a_name;
456 return m_instanceMapMap[a_name][a_property];
462 if(!catalogedAny(a_name))
464 m_orderMap[++m_highest]=a_name;
466 m_instanceMapMap[a_name][a_property]=instance;
467 return m_instanceMapMap[a_name][a_property];
473 std::map<String, InstanceMap>::const_iterator it=
474 m_instanceMapMap.find(a_name);
475 if(it==m_instanceMapMap.end())
477 return getTypeId<void>();
480 const std::map<String, Instance>& instanceMap=it->second;
482 std::map<String, Instance>::const_iterator it2=
483 instanceMap.find(a_property);
484 if(it2==instanceMap.end())
486 return getTypeId<void>();
489 const Instance& rInstance=it2->second;
490 return rInstance.type()->typeinfo().ref();
497 if(!cataloged(a_name,a_property))
501 const Instance& rInstance=m_instanceMapMap.at(a_name).at(a_property);
504 if(spBaseType.isNull())
506 feX(
"Catalog::catalogTypeName",
"invalid Instance");
510 String typeName=rInstance.type()->typeinfo().ref().name();
512 std::list<String> typeNames;
513 typeMaster()->reverseLookup(spBaseType,typeNames);
514 if(typeNames.size()>0)
516 typeName= *(typeNames.begin());
526 return (catalogTypeInfo(a_name,a_property)==getTypeId<T>());
531 std::map<String, InstanceMap>::const_iterator it=
532 m_instanceMapMap.find(a_name);
534 return it!=m_instanceMapMap.end();
539 std::map<String, InstanceMap>::const_iterator it=
540 m_instanceMapMap.find(a_name);
542 return it!=m_instanceMapMap.end() &&
543 it->second.find(a_property) != it->second.end();
548 for(std::map< I32, String >::iterator it = m_orderMap.begin();
549 it != m_orderMap.end(); it++)
551 if(it->second==a_name)
553 m_orderMap.erase(it->first);
554 m_orderMap[++m_highest]=a_name;
563 std::map<String, InstanceMap>::iterator i_name=
564 m_instanceMapMap.find(a_name);
566 if(i_name!=m_instanceMapMap.end())
569 for(std::map< String, Instance >::iterator i_prop=rInstanceMap.begin();
570 i_prop!=rInstanceMap.end(); i_prop++)
572 Counted::untrackReference(i_prop->second.data(),
this);
576 m_instanceMapMap.erase(a_name);
578 for(std::map< I32, String >::iterator it = m_orderMap.begin();
579 it != m_orderMap.end(); it++)
581 if(it->second==a_name)
583 m_orderMap.erase(it->first);
591 std::map<String, InstanceMap>::iterator i_name=
592 m_instanceMapMap.find(a_name);
594 if(i_name!=m_instanceMapMap.end())
598 std::map<String, Instance>::const_iterator i_prop=
599 rInstanceMap.find(a_property);
600 if(i_prop!=rInstanceMap.end())
603 Counted::untrackReference(i_prop->second.data(),
this);
605 rInstanceMap.erase(a_property);
613 for(std::map< String, InstanceMap >::iterator i_name=
614 m_instanceMapMap.begin(); i_name!=m_instanceMapMap.end(); i_name++)
617 for(std::map< String, Instance >::iterator i_prop=rInstanceMap.begin();
618 i_prop!=rInstanceMap.end(); i_prop++)
620 Counted::untrackReference(i_prop->second.data(),
this);
624 m_instanceMapMap.clear();
628 class FE_DL_EXPORT SafeCatalog:
634 virtual ~SafeCatalog(
void) {}
sp< Component > catalogComponent(String implementation, String a_name, String a_property="value")
Returns a component entry of the given property for the given name.
Definition: Catalog.cc:213
BWORD catalogTypeIs(String a_name, String a_property="value") const
Returns TRUE if given catalog entry match the template type.
Definition: Catalog.h:523
BWORD catalogedAny(String a_name) const
Returns TRUE if any property for the given name has been created.
Definition: Catalog.h:529
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
const String catalogTypeName(String a_name, String a_property="value") const
Returns the type name of the given property, determined by the TypeMaster.
Definition: Catalog.h:493
kernel
Definition: namespace.dox:3
Dictionary of Arbitrary Instances.
Definition: Catalog.h:24
T & catalog(String a_name, String a_property="value")
Returns existing catalog entry if already set or a default if not.
Definition: Catalog.h:372
void catalogMoveToEnd(String a_name)
Move all properties for name to bottom.
Definition: Catalog.h:546
Instance & catalogInstance(Instance &instance, String a_name, String a_property="value")
Returns the literal Instance of the given property for the given name.
Definition: Catalog.h:459
void catalogClear(void)
Remove all entries.
Definition: Catalog.h:610
BWORD operator==(const DualString &s1, const DualString &s2)
Compare two DualString's.
Definition: DualString.h:208
Automatically reference-counted string container.
Definition: String.h:128
const T & catalogOrDefault(String a_name, String a_property, const T &a_default) const
Returns existing catalog entry if already set or default if not.
Definition: Catalog.h:392
Group of named instances.
Definition: InstanceMap.h:17
T & catalogOrException(String a_name, String a_property) const
Returns an existing catalog entry, if it exists.
Definition: Catalog.h:415
BWORD cataloged(String a_name, String a_property="value") const
Returns TRUE if the given property for the given name has been created.
Definition: Catalog.h:537
Wrapper for std::vector.
Definition: Array.h:21
const fe_type_info & catalogTypeInfo(String a_name, String a_property="value") const
Returns the type_info of the given property for the given name.
Definition: Catalog.h:470
Base for all interfacable components.
Definition: Component.h:20
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
void catalogRemove(String a_name)
Remove all properties for a name.
Definition: Catalog.h:560
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192
Object level locking for thread safety.
Definition: SafeShared.h:220