Supporting Custom Relevancy Functions for Enums

In addition to supporting information with discrete enumerated values, smtk::ValueItem also contains a method that returns a list of relevant enums.

In 24.01, an emum value is considered relevant based on the following:

  • If category filtering is requested and the set of categories satisfies the enum’s category constraint
  • If read access filtering is requested and the enum’s read access <= the request read access level

However, there are times when an enum’s relevance depends on additional information, for example it may only be relevant if the value of an item, which is part of another attribute, lies within a specific range of values.

Propose Approach

Allow a programmer to specify their own custom isRelevant method to the Item’s ValueItemDefinition. This method would have the following signature:

bool f(const smtk::attribute::ValueItem *item, int enumIndex,  bool includeCategories, const std::set<std::string>& testCategories, bool includeReadAccess, unsigned int readAccessLevel)

The arguments represent:

  • item - the item owning the enum
  • enumIndex - the index of the enum being tested
  • includeCategories - indicates if category testing should be applied
  • testCategories - used when includeCategories is true and is the set of categories to be used for testing
  • includeReadAccessLevel - indicates if the enum’s read access level should be checked
  • readAccessLevel - used when includeReadAccessLevel is true and is the value that the enum’s access level should be less than or equal to

Changes to ValueItemDefinition

  • The existing method relevantEnums will be refactored into two methods
    • defaultIsEnumRelevant(int enumIndex, bool includeCategories, const std::set<std::string>& testCategories, bool includeReadAccess, unsigned int readAccessLevel) which will include the current evaluation logic and can be called by a custom relevance function if needed (eliminating code potential code duplication)
    • relevantEnums will make use of the above method to for its evaluations
  • Add methods that would set and retrieve a custom isEnumRelivant method

Changes to ValueItem

  • Change the method relevantEnums not to call its Definition’s relevantEnums if its Definition has a custom isEnumRelevant method assigned and instead have it test its Enums against that function.

@rohith @justin.2.wilson @Aaron @johnt @dcthomp FYI

1 Like