63 if( !aProperty.CmpNoCase( property->
Name() ) )
81 return it->second.m_allProperties;
95 return it->second.m_displayOrder;
109 return it->second.m_groupDisplayOrder;
115 if( aBase == aTarget )
118 auto classDesc =
m_classes.find( aBase );
123 const std::map<TYPE_ID, std::unique_ptr<TYPE_CAST_BASE>>& 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();
152 if( !classDesc.
m_groups.count( aGroup ) )
155 classDesc.
m_groups.insert( aGroup );
164 const wxString& aGroup )
167 classDesc.
m_replaced.insert( std::make_pair( aBase, aName ) );
177 wxASSERT_MSG( classDesc.
m_typeCasts.count( derivedHash ) == 0, wxT(
"Such converter already exists" ) );
178 classDesc.
m_typeCasts.emplace( derivedHash, aCast );
184 wxASSERT_MSG( aDerived != aBase, wxT(
"Class cannot inherit from itself" ) );
191 wxT(
"You need to add a TYPE_CAST for classes inheriting from multiple bases" ) );
197 wxASSERT_MSG( aDerived != aBase, wxT(
"Class cannot mask from itself" ) );
208 wxASSERT_MSG( aDerived != aBase, wxT(
"Class cannot override from itself" ) );
219 wxASSERT_MSG( aDerived != aBase, wxT(
"Class cannot override from itself" ) );
237 return it->second( aItem );
253 return it->second( aItem );
261 if( aDerived == aBase )
264 auto derived =
m_classes.find( aDerived );
265 wxCHECK( derived !=
m_classes.end(),
false );
268 for(
const std::reference_wrapper<CLASS_DESC>& base : derived->second.m_bases )
270 if(
IsOfType( base.get().m_id, aBase ) )
280 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
281 classEntry.second.rebuild();
312 std::set<std::pair<size_t, wxString>> replaced;
313 std::set<std::pair<size_t, wxString>> masked;
321 std::vector<wxString> displayOrder;
322 std::set<wxString> groups;
325 [&]( std::set<wxString>& aSet, std::vector<wxString>& aResult )
327 auto collectGroupsRecursive =
328 [](
auto& aSelf, std::set<wxString>& aSetR, std::vector<wxString>& aResultR,
331 for(
const wxString&
group : aClassR.m_groupDisplayOrder )
333 if( !aSetR.count(
group ) )
335 aSetR.insert(
group );
336 aResultR.emplace_back(
group );
340 for(
const CLASS_DESC& base : aClassR.m_bases )
341 aSelf( aSelf, aSetR, aResultR, base );
344 collectGroupsRecursive( collectGroupsRecursive, aSet, aResult, *
this );
349 collectGroups( groups, displayOrder );
355 std::set<std::pair<size_t, wxString>>& aReplaced,
356 std::map<PROPERTY_BASE*, int>& aDisplayOrder,
357 std::set<std::pair<size_t, wxString>>& aMasked )
const
359 for(
const std::pair<size_t, wxString>& replacedEntry :
m_replaced )
360 aReplaced.emplace( replacedEntry );
363 aMasked.emplace( maskedEntry );
369 int displayOrderStart = 0;
371 if( !aDisplayOrder.empty() )
373 int firstSoFar = std::min_element( aDisplayOrder.begin(), aDisplayOrder.end(),
374 [](
const std::pair<PROPERTY_BASE*, int>& aFirst,
375 const std::pair<PROPERTY_BASE*, int>& aSecond )
377 return aFirst.second < aSecond.second;
387 std::set<std::pair<size_t, wxString>>::key_type propertyKey = std::make_pair( property->OwnerHash(),
390 if( aReplaced.count( propertyKey ) )
394 if( aMasked.count( propertyKey ) )
397 aDisplayOrder[property] = displayOrderStart + idx++;
398 aResult.push_back( property );
402 for( std::reference_wrapper<CLASS_DESC> base : std::ranges::reverse_view(
m_bases ) )
403 base.get().collectPropsRecur( aResult, aReplaced, aDisplayOrder, aMasked );
411 for( std::pair<const TYPE_ID, CLASS_DESC>& classEntry :
m_classes )
415 info.type = classEntry.first;
418 for(
PROPERTY_BASE* prop : classEntry.second.m_allProperties )
419 info.properties.push_back( prop );
421 rv.push_back(
info );
437 for(
const auto& [ handle, listener ] : listeners->second )
444 callListeners( objectClass.
m_id );
447 callListeners( superClass.
m_id );
454 return, wxT(
"Can't have more than one managed commit at a time!" ) );
463 wxT(
"Something went wrong: m_managedCommit already null!" ) );
473 m_listeners[aType].emplace_back( handle, std::move( aListenerFunc ) );
474 return { aType, handle };
485 auto& vec = it->second;
486 vec.erase( std::remove_if( vec.begin(), vec.end(),
487 [aHandle](
const auto& aPair )
488 { return aPair.first == aHandle; } ),
502 if(
this != &aOther )
Represent a set of changes (additions, deletions or modifications) of a data model (e....
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.
~PROPERTY_COMMIT_HANDLER()
PROPERTY_COMMIT_HANDLER(COMMIT *aCommit)
Move-only RAII wrapper around a single listener registration.
PROPERTY_LISTENER_HANDLE m_handle
PROPERTY_LISTENER_SUBSCRIPTION()=default
~PROPERTY_LISTENER_SUBSCRIPTION()
PROPERTY_LISTENER_SUBSCRIPTION & operator=(const PROPERTY_LISTENER_SUBSCRIPTION &)=delete
const std::vector< PROPERTY_BASE * > & GetProperties(TYPE_ID aType) const
Return all properties for a specific type.
bool m_dirty
Flag indicating that the list of properties needs to be rebuild (RebuildProperties())
CLASSES_INFO GetAllClasses()
std::vector< CLASS_INFO > CLASSES_INFO
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
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 PropertyChanged(INSPECTABLE *aObject, PROPERTY_BASE *aProperty)
Callback to alert the notification system that a property has changed.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
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
~PROPERTY_MANAGER() noexcept
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 ...
class PROPERTY_LISTENER_SUBSCRIPTION RegisterListener(TYPE_ID aType, PROPERTY_LISTENER aListenerFunc)
Register a listener for the given type and return a move-only subscription that auto-unregisters in i...
const std::map< PROPERTY_BASE *, int > & GetDisplayOrder(TYPE_ID aType) const
PROPERTY_LISTENER_HANDLE m_nextListenerHandle
void UnregisterListener(TYPE_ID aType, PROPERTY_LISTENER_HANDLE aHandle)
Remove a single listener registration by its handle.
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.
std::map< TYPE_ID, std::vector< std::pair< PROPERTY_LISTENER_HANDLE, PROPERTY_LISTENER > > > m_listeners
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 const std::vector< PROPERTY_BASE * > EMPTY_PROP_LIST
static const std::map< PROPERTY_BASE *, int > EMPTY_PROP_DISPLAY_ORDER
std::vector< wxString > EMPTY_GROUP_DISPLAY_ORDER
std::function< void(INSPECTABLE *, PROPERTY_BASE *, COMMIT *)> PROPERTY_LISTENER
Opaque handle returned by RegisterListener so a specific registration can be removed without disturbi...
std::size_t PROPERTY_LISTENER_HANDLE
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)
std::set< std::pair< size_t, wxString > > m_replaced
Recreates the list of properties.
std::vector< wxString > m_groupDisplayOrder
Non-owning list of classes's direct properties in display order.
std::map< std::pair< size_t, wxString >, std::function< bool(INSPECTABLE *)> > m_availabilityOverrides
Overrides for base class property writeable status.
std::map< std::pair< size_t, wxString >, std::function< bool(INSPECTABLE *)> > m_writeabilityOverrides
All properties (both unique to the type and inherited)
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::set< std::pair< size_t, wxString > > m_maskedBaseProperties
Overrides for base class property availabilities.
std::map< PROPERTY_BASE *, int > m_displayOrder
List of property groups provided by this class in display order.
std::vector< PROPERTY_BASE * > m_allProperties
Compiled display order for all properties.
std::map< TYPE_ID, std::unique_ptr< TYPE_CAST_BASE > > m_typeCasts
Properties from bases that should be masked (hidden) on this subclass.
void collectPropsRecur(std::vector< PROPERTY_BASE * > &aResult, std::set< std::pair< size_t, wxString > > &aReplaced, std::map< PROPERTY_BASE *, int > &aDisplayOrder, std::set< std::pair< size_t, wxString > > &aMasked) const
void rebuild()
Traverses the class inheritance hierarchy bottom-to-top, gathering all properties available to a type...
const TYPE_ID m_id
Types after which this type inherits.
std::set< wxString > m_groups
Replaced properties (TYPE_ID / name)