48 const_cast<PROPERTY_MANAGER*>(
this )->Rebuild();
59 if( !aProperty.CmpNoCase( property->
Name() ) )
70 const_cast<PROPERTY_MANAGER*>(
this )->Rebuild();
78 return it->second.m_allProperties;
84 if( aBase == aTarget )
92 auto& converters = classDesc->second.m_typeCasts;
93 auto converter = converters.find( aTarget );
95 if( converter == converters.end() )
96 return IsOfType( aBase, aTarget ) ? aSource :
nullptr;
98 return (*converter->second)( aSource );
104 const wxString&
name = aProperty->
Name();
114 wxASSERT( aBase == aNew->
BaseHash() );
116 classDesc.
m_replaced.insert( std::make_pair( aBase, aName ) );
126 wxASSERT_MSG( typeCasts.count( derivedHash ) == 0, wxT(
"Such converter already exists" ) );
127 typeCasts.emplace( derivedHash, aCast );
133 wxASSERT_MSG( aDerived != aBase, wxT(
"Class cannot inherit from itself" ) );
137 derived.
m_bases.push_back( base );
141 wxT(
"You need to add a TYPE_CAST for classes inheriting from multiple bases" ) );
147 if( aDerived == aBase )
150 auto derived =
m_classes.find( aDerived );
151 wxCHECK( derived !=
m_classes.end(), false );
154 for(
auto& base : derived->second.m_bases )
156 if(
IsOfType( base.get().m_id, aBase ) )
166 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
167 classEntry.second.rebuild();
197 for(
const std::pair<size_t, wxString>& replacedEntry : m_replaced )
198 aReplaced.emplace( replacedEntry );
200 for(
const std::pair<
const wxString, std::unique_ptr<PROPERTY_BASE>>& prop : m_ownProperties )
205 if( aReplaced.count( std::make_pair( property->OwnerHash(),
property->Name() ) ) == 0 )
206 aResult.push_back( property );
209 for(
const std::reference_wrapper<CLASS_DESC>& base : m_bases )
210 base.get().collectPropsRecur( aResult, aReplaced );
216 std::vector<TYPE_ID> ids;
238 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
242 info.type = classEntry.first;
245 for(
PROPERTY_BASE* prop : classEntry.second.m_allProperties )
246 info.properties.push_back( prop );
248 rv.push_back(
info );
void Rebuild()
Rebuild the list of all registered properties.
const PROPERTY_LIST & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
std::vector< TYPE_ID > GetMatchingClasses(PROPERTY_BASE *aProperty)
PROPERTY_SET m_replaced
Recreates the list of properties.
virtual size_t BaseHash() const =0
size_t TYPE_ID
Unique type identifier.
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
virtual size_t DerivedHash() const =0
bool m_dirty
Flag indicating that the list of properties needs to be rebuild (RebuildProperties())
std::map< TYPE_ID, std::unique_ptr< TYPE_CAST_BASE > > m_typeCasts
All properties (both unique to the type and inherited)
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
std::unordered_map< TYPE_ID, CLASS_DESC > m_classes
void collectPropsRecur(PROPERTY_LIST &aResult, PROPERTY_SET &aReplaced) const
void rebuild()
Traverses the class inheritance hierarchy bottom-to-top, gathering all properties available to a type...
Returns metadata for a specific type.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
const wxString & Name() const
const wxString & ResolveType(TYPE_ID aType) const
Return name of a type.
static wxString EMPTY_STRING(wxEmptyString)
CLASS_DESC & getClass(TYPE_ID aTypeId)
void RegisterType(TYPE_ID aType, const wxString &aName)
Associate a name with a type.
std::unordered_map< TYPE_ID, wxString > m_classNames
Map of all available types.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
std::vector< CLASS_INFO > CLASSES_INFO
std::vector< std::reference_wrapper< CLASS_DESC > > m_bases
Properties unique to this type (i.e. not inherited)
std::vector< PROPERTY_BASE * > PROPERTY_LIST
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
static bool empty(const wxTextEntryBase *aCtrl)
virtual size_t BaseHash() const =0
Return type-id of the Base class.
void ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew)
Replace an existing property for a specific type.
CLASSES_INFO GetAllClasses()
std::set< std::pair< size_t, wxString > > PROPERTY_SET
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
std::map< wxString, std::unique_ptr< PROPERTY_BASE > > m_ownProperties
Type converters available for this type.
std::vector< PROPERTY_BASE * > m_allProperties
Replaced properties (TYPE_ID / name)