60 if( !aProperty.CmpNoCase( property->
Name() ) )
79 return it->second.m_allProperties;
94 return it->second.m_displayOrder;
103 static const std::vector<wxString>
empty;
109 return it->second.m_groupDisplayOrder;
115 if( aBase == aTarget )
118 auto classDesc =
m_classes.find( aBase );
123 auto& converters = classDesc->second.m_typeCasts;
124 auto converter = converters.find( aTarget );
126 if( converter == converters.end() )
127 return IsOfType( aBase, aTarget ) ? aSource :
nullptr;
129 return (*converter->second)( aSource );
135 const wxString&
name = aProperty->
Name();
143 if( !classDesc.
m_groups.count( aGroup ) )
146 classDesc.
m_groups.insert( aGroup );
158 classDesc.
m_replaced.insert( std::make_pair( aBase, aName ) );
168 wxASSERT_MSG( typeCasts.count( derivedHash ) == 0,
"Such converter already exists" );
169 typeCasts.emplace( derivedHash, aCast );
175 wxASSERT_MSG( aDerived != aBase,
"Class cannot inherit from itself" );
179 derived.
m_bases.push_back( base );
183 "You need to add a TYPE_CAST for classes inheriting from multiple bases" );
189 wxASSERT_MSG( aDerived != aBase,
"Class cannot mask from itself" );
198 const wxString& aName,
201 wxASSERT_MSG( aDerived != aBase,
"Class cannot override from itself" );
210 const wxString& aName,
213 wxASSERT_MSG( aDerived != aBase,
"Class cannot override from itself" );
233 return it->second( aItem );
251 return it->second( aItem );
259 if( aDerived == aBase )
262 auto derived =
m_classes.find( aDerived );
263 wxCHECK( derived !=
m_classes.end(),
false );
266 for(
auto& base : derived->second.m_bases )
268 if(
IsOfType( base.get().m_id, aBase ) )
278 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
279 classEntry.second.rebuild();
305 std::vector<wxString> displayOrder;
306 std::set<wxString> groups;
309 [&]( std::set<wxString>& aSet, std::vector<wxString>& aResult )
311 auto collectGroupsRecursive =
312 [](
auto& aSelf, std::set<wxString>& aSetR, std::vector<wxString>& aResultR,
315 for(
const wxString&
group : aClassR.m_groupDisplayOrder )
317 if( !aSetR.count(
group ) )
319 aSetR.insert(
group );
320 aResultR.emplace_back(
group );
325 aSelf( aSelf, aSetR, aResultR, base );
328 collectGroupsRecursive( collectGroupsRecursive, aSet, aResult, *
this );
333 collectGroups( groups, displayOrder );
343 for(
const std::pair<size_t, wxString>& replacedEntry : m_replaced )
344 aReplaced.emplace( replacedEntry );
346 for(
const std::pair<size_t, wxString>& maskedEntry : m_maskedBaseProperties )
347 aMasked.emplace( maskedEntry );
353 int displayOrderStart = 0;
355 if( !aDisplayOrder.empty() )
357 int firstSoFar = std::min_element( aDisplayOrder.begin(), aDisplayOrder.end(),
358 [](
const std::pair<PROPERTY_BASE*, int>& aFirst,
359 const std::pair<PROPERTY_BASE*, int>& aSecond )
361 return aFirst.second < aSecond.second;
364 displayOrderStart = firstSoFar - m_ownProperties.size();
371 PROPERTY_SET::key_type propertyKey = std::make_pair( property->OwnerHash(),
374 if( aReplaced.count( propertyKey ) )
378 if( aMasked.count( propertyKey ) )
381 aDisplayOrder[property] = displayOrderStart + idx++;
382 aResult.push_back( property );
386 for(
auto it = m_bases.rbegin(); it != m_bases.rend(); ++it )
387 it->get().collectPropsRecur( aResult, aReplaced, aDisplayOrder, aMasked );
393 std::vector<TYPE_ID> ids;
415 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
419 info.type = classEntry.first;
422 for(
PROPERTY_BASE* prop : classEntry.second.m_allProperties )
423 info.properties.push_back( prop );
425 rv.push_back(
info );
Class that other classes need to inherit from, in order to be inspectable.
PROPERTY_BASE & SetGroup(const wxString &aGroup)
virtual size_t BaseHash() const =0
Return type-id of the Base class.
virtual bool Writeable(INSPECTABLE *aObject) const
bool Available(INSPECTABLE *aObject) const
Return true if aObject offers this PROPERTY.
const wxString & Name() const
virtual size_t OwnerHash() const =0
Return type-id of the Owner class.
Provide class metadata.Helper macro to map type hashes to names.
bool m_dirty
Flag indicating that the list of properties needs to be rebuild (RebuildProperties())
CLASSES_INFO GetAllClasses()
std::vector< CLASS_INFO > CLASSES_INFO
const wxString & ResolveType(TYPE_ID aType) const
Return name of a type.
const PROPERTY_LIST & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
const PROPERTY_DISPLAY_ORDER & GetDisplayOrder(TYPE_ID aType) const
bool IsWriteableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void Rebuild()
Rebuild the list of all registered properties.
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
const void * TypeCast(const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const
Cast a type to another type.
CLASS_DESC & getClass(TYPE_ID aTypeId)
void RegisterType(TYPE_ID aType, const wxString &aName)
Associate a name with a type.
bool IsAvailableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
std::vector< TYPE_ID > GetMatchingClasses(PROPERTY_BASE *aProperty)
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
void OverrideWriteability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override writeability functor for a base class property of a given derived class.
std::unordered_map< TYPE_ID, wxString > m_classNames
Map of all available types.
const std::vector< wxString > & GetGroupDisplayOrder(TYPE_ID aType) const
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
virtual size_t BaseHash() const =0
virtual size_t DerivedHash() const =0
static bool empty(const wxTextEntryBase *aCtrl)
static wxString EMPTY_STRING(wxEmptyString)
std::vector< PROPERTY_BASE * > PROPERTY_LIST
std::map< PROPERTY_BASE *, int > PROPERTY_DISPLAY_ORDER
std::set< std::pair< size_t, wxString > > PROPERTY_SET
size_t TYPE_ID
Unique type identifier.
Returns metadata for a specific type.
std::vector< std::reference_wrapper< CLASS_DESC > > m_bases
Properties unique to this type (i.e. not inherited)
PROPERTY_SET m_replaced
Recreates the list of properties.
PROPERTY_SET m_maskedBaseProperties
Overrides for base class property availabilities.
std::vector< wxString > m_groupDisplayOrder
Non-owning list of classes's direct properties in display order.
std::map< wxString, std::unique_ptr< PROPERTY_BASE > > m_ownProperties
Type converters available for this type.
std::vector< PROPERTY_BASE * > m_ownDisplayOrder
The property groups provided by this class.
std::vector< PROPERTY_BASE * > m_allProperties
Compiled display order for all properties.
PROPERTY_DISPLAY_ORDER m_displayOrder
List of property groups provided by this class in display order.
PROPERTY_FUNCTOR_MAP m_writeabilityOverrides
All properties (both unique to the type and inherited)
std::map< TYPE_ID, std::unique_ptr< TYPE_CAST_BASE > > m_typeCasts
Properties from bases that should be masked (hidden) on this subclass.
void rebuild()
Traverses the class inheritance hierarchy bottom-to-top, gathering all properties available to a type...
void collectPropsRecur(PROPERTY_LIST &aResult, PROPERTY_SET &aReplaced, PROPERTY_DISPLAY_ORDER &aDisplayOrder, PROPERTY_SET &aMasked) const
PROPERTY_FUNCTOR_MAP m_availabilityOverrides
Overrides for base class property writeable status.
std::set< wxString > m_groups
Replaced properties (TYPE_ID / name)