SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
smtk::attribute::GroupItem Class Reference

A group item represents an array of structures in SMTK. More...

#include <GroupItem.h>

Inheritance diagram for smtk::attribute::GroupItem:
[legend]
Collaboration diagram for smtk::attribute::GroupItem:
[legend]

Public Types

typedef std::vector< std::vector< smtk::attribute::ItemPtr > >::const_iterator const_iterator
 
- Public Types inherited from smtk::attribute::Item
enum  Type {
  AttributeRefType, DoubleType, GroupType, IntType,
  StringType, VoidType, FileType, DirectoryType,
  ColorType, ModelEntityType, MeshEntityType, DateTimeType,
  ReferenceType, ResourceType, ComponentType, NUMBER_OF_TYPES
}
 
enum  AssignmentOptions {
  IGNORE_EXPRESSIONS = 0x001, IGNORE_MODEL_ENTITIES = 0x002, IGNORE_ATTRIBUTE_REF_ITEMS = 0x004, IGNORE_RESOURCE_COMPONENTS = 0x008,
  COPY_MODEL_ASSOCIATIONS = 0x010
}
 Deprecated Assignment Options. More...
 

Public Member Functions

 smtkTypeMacro (smtk::attribute::GroupItem)
 
Item::Type type () const override
 
std::size_t numberOfRequiredGroups () const
 
std::size_t maxNumberOfGroups () const
 
void visitChildren (std::function< void(smtk::attribute::ItemPtr, bool)> visitor, bool activeChildren=true) override
 visitChildren Invoke a function on each (or, if findInActiveChildren is true, each active) child item. More...
 
bool isExtensible () const
 
std::size_t numberOfGroups () const
 
bool setNumberOfGroups (std::size_t newSize)
 
std::size_t numberOfItemsPerGroup () const
 
bool appendGroup ()
 
bool prependGroup ()
 
bool insertGroups (std::size_t pos, std::size_t num)
 Insert num groups before index pos - so append is pos = numberOfGroups and prepend would be pos = 0.
 
bool removeGroup (std::size_t element)
 
smtk::attribute::ItemPtr item (std::size_t ith) const
 Return the i-th item in the first entry of the group.
 
smtk::attribute::ItemPtr item (std::size_t element, std::size_t ith) const
 Return the i-th item in for the element-th value of the group. More...
 
smtk::attribute::ItemPtr find (std::size_t element, const std::string &name, SearchStyle style=IMMEDIATE)
 
smtk::attribute::ConstItemPtr find (std::size_t element, const std::string &name, SearchStyle style=IMMEDIATE) const
 
template<typename T >
T::Ptr findAs (std::size_t element, const std::string &name, SearchStyle style=IMMEDIATE)
 
template<typename T >
T::ConstPtr findAs (std::size_t element, const std::string &name, SearchStyle style=IMMEDIATE) const
 
void detachOwningResource () override
 Release the item's dependency on its parent attribute's Resource.
 
void reset () override
 
bool rotate (std::size_t fromPosition, std::size_t toPosition) override
 Rotate the order of subgroups between specified positions. More...
 
bool isConditional () const
 Returns the item's conditional property. More...
 
bool conditionalsSatisfied (bool useActiveCategories=true) const
 Returns true if the GroupItem satisfies its conditional requirements. More...
 
bool assign (const smtk::attribute::ConstItemPtr &sourceItem, const CopyAssignmentOptions &options, smtk::io::Logger &logger) override
 Assigns this item to be equivalent to another. More...
 
bool hasRelevantChildren (bool includeCategories=true, bool includeReadAccess=false, int readAccessLevel=0) const
 Returns true if the group item has relevant children.
 
smtk::attribute::ItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 return a child item that matches name and satisfies the SearchStyle
 
smtk::attribute::ConstItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 
template<typename T >
T::Ptr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 
template<typename T >
T::ConstPtr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 
virtual bool assign (const smtk::attribute::ConstItemPtr &sourceItem, unsigned int options)
 Assigns this item to be equivalent to another. More...
 
virtual bool assign (const smtk::attribute::ConstItemPtr &sourceItem, const CopyAssignmentOptions &options=CopyAssignmentOptions())
 
virtual bool assign (const smtk::attribute::ConstItemPtr &sourceItem, const CopyAssignmentOptions &options, smtk::io::Logger &logger)
 
void setMinNumberOfChoices (unsigned int value)
 Returns or sets the minimum number of choices that must be set for the GroupItem, whose Conditional property is true, to be considered valid. If set to 0 then there is no minimum number. This value is initialized by the item's definition.
 
unsigned int minNumberOfChoices () const
 Returns or sets the minimum number of choices that must be set for the GroupItem, whose Conditional property is true, to be considered valid. If set to 0 then there is no minimum number. This value is initialized by the item's definition.
 
void setMaxNumberOfChoices (unsigned int value)
 Returns or sets the maximum number of choices that must be set for GroupItem, whose Conditional property is true, to be considered valid. If set to 0 then there is no maximum number. This value is initialized by the item's definition.
 
unsigned int maxNumberOfChoices () const
 Returns or sets the maximum number of choices that must be set for GroupItem, whose Conditional property is true, to be considered valid. If set to 0 then there is no maximum number. This value is initialized by the item's definition.
 
const_iterator begin () const
 Iterator-style access to values: More...
 
const_iterator end () const
 Return an iterator just past the last group in this item.
 
- Public Member Functions inherited from smtk::attribute::Item
 smtkTypeMacroBase (smtk::attribute::Item)
 
std::string name () const
 
std::string label () const
 
virtual bool isRelevant (bool includeCatagories=true, bool includeReadAccess=false, unsigned int readAccessLevel=0) const
 Returns true if the item is relevant. More...
 
const smtk::attribute::ConstItemDefinitionPtrdefinition () const
 
template<typename DefType >
std::shared_ptr< const DefType > definitionAs () const
 
smtk::attribute::AttributePtr attribute () const
 Return the attribute that owns this item.
 
smtk::attribute::ItemPtr owningItem () const
 
int position () const
 Position is the item's location w/r to the owning item if not null or the owning attribute. More...
 
int subGroupPosition () const
 
bool isOptional () const
 Returns true if the item is optional.
 
bool isEnabled () const
 An item is enabled under the following conditions: More...
 
bool localEnabledState () const
 Return the state of the instance's isEnabled state.
 
void setIsEnabled (bool isEnabledValue)
 Set the instance's local enabled state.
 
const smtk::attribute::Categoriescategories () const
 return the categories associated with the item (via its Definition)
 
unsigned int advanceLevel (int mode=0) const
 Get the item 's advance level. More...
 
void setLocalAdvanceLevel (int mode, unsigned int level)
 
unsigned int localAdvanceLevel (int mode=0) const
 
void unsetLocalAdvanceLevel (int mode=0)
 
bool hasLocalAdvanceLevelInfo (int mode=0) const
 
void setUserData (const std::string &key, smtk::simulation::UserDataPtr value)
 
smtk::simulation::UserDataPtr userData (const std::string &key) const
 
void clearUserData (const std::string &key)
 
void clearAllUserData ()
 
void detachOwningAttribute ()
 This should be used only by attributes.
 
void detachOwningItem ()
 This should only be called by the item that owns this one.
 
virtual bool assign (const smtk::attribute::ConstItemPtr &sourceItem, unsigned int options)
 Assigns this item to be equivalent to another. More...
 
virtual bool assign (const smtk::attribute::ConstItemPtr &sourceItem, const CopyAssignmentOptions &options=CopyAssignmentOptions())
 
bool isValid (bool useActiveCategories=true) const
 tests the validity of an item More...
 
bool isValid (const std::set< std::string > &categories) const
 tests the validity of an item More...
 
smtk::attribute::ItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 return a child item that matches name and satisfies the SearchStyle
 
smtk::attribute::ConstItemPtr find (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 return a child item that matches name and satisfies the SearchStyle
 
template<typename T >
T::Ptr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
 return a child item that matches name and satisfies the SearchStyle
 
template<typename T >
T::ConstPtr findAs (const std::string &name, SearchStyle style=RECURSIVE_ACTIVE) const
 return a child item that matches name and satisfies the SearchStyle
 
void setForceRequired (bool val)
 Controls if an item should be forced to be required regardless of its local enable property. More...
 
bool forceRequired () const
 Controls if an item should be forced to be required regardless of its local enable property. More...
 
void setIsIgnored (bool val)
 Controls if an item should be ignored. More...
 
bool isIgnored () const
 Controls if an item should be ignored. More...
 

Protected Member Functions

 GroupItem (Attribute *owningAttribute, int itemPosition)
 
 GroupItem (Item *owningItem, int myPosition, int mySubGroupPosition)
 
bool setDefinition (smtk::attribute::ConstItemDefinitionPtr def) override
 
smtk::attribute::ItemPtr findInternal (const std::string &name, SearchStyle style) override
 Internal implementation of the find method.
 
smtk::attribute::ConstItemPtr findInternal (const std::string &name, SearchStyle style) const override
 
void detachAllItems ()
 
bool isValidInternal (bool useCategories, const std::set< std::string > &categories) const override
 Internal implementation of calculating the validity of the item. More...
 
- Protected Member Functions inherited from smtk::attribute::Item
 Item (Attribute *owningAttribute, int itemPosition)
 
 Item (Item *owningItem, int myPosition, int mySubGroupPOsition)
 
template<typename T >
bool rotateVector (std::vector< T > &v, std::size_t fromPosition, std::size_t toPosition)
 

Protected Attributes

std::vector< std::vector< smtk::attribute::ItemPtr > > m_items
 
unsigned int m_maxNumberOfChoices
 
unsigned int m_minNumberOfChoices
 
- Protected Attributes inherited from smtk::attribute::Item
Attributem_attribute
 
Itemm_owningItem
 
int m_position
 
int m_subGroupPosition
 
bool m_isEnabled
 
bool m_isIgnored
 
smtk::attribute::ConstItemDefinitionPtr m_definition
 
std::map< std::string, smtk::simulation::UserDataPtrm_userData
 

Friends

class GroupItemDefinition
 

Additional Inherited Members

- Static Public Member Functions inherited from smtk::attribute::Item
static std::string type2String (Item::Type t)
 
static Item::Type string2Type (const std::string &s)
 
static void mapOldAssignmentOptions (CopyAssignmentOptions &options, unsigned int oldStyleOptions)
 

Detailed Description

A group item represents an array of structures in SMTK.

Groups are arrays of structures. The structure is defined by the children items in the group; each child item in the group is repeated once for every element of the array.

The numberOfGroups() method returns the number of entries in the array, while numberOfItemsPerGroup() returns the number of children items. Groups may have other groups as children.

As an example, consider a group g with 2 child items: a string item named "key" and a double item named "value". Calling setNumberOfGroups(5) will cause 5 key-value pairs to be allocated. You may then set values by like so:

const char* keyNames[];
for (std::size_t ii = 0; ii < 5; ++ii)
{
g->findAs<StringItem>(ii, "key")->setValue(keyNames[ii]);
g->findAs<DoubleItem>(ii, "value")->setValue(0.5 * ii);
}

Member Function Documentation

◆ assign() [1/2]

bool GroupItem::assign ( const smtk::attribute::ConstItemPtr sourceItem,
const CopyAssignmentOptions options,
smtk::io::Logger logger 
)
overridevirtual

Assigns this item to be equivalent to another.

Options are processed by derived item classes Returns true if success and false if a problem occurred - options are use when copying sub-items. See CopyAssigmentOptions.h for a description of these options.

Reimplemented from smtk::attribute::Item.

◆ assign() [2/2]

bool Item::assign

Assigns this item to be equivalent to another.

Options are processed by derived item classes Returns true if success and false if a problem occurred

◆ begin()

GroupItem::const_iterator GroupItem::begin ( ) const

Iterator-style access to values:

Return an iterator to the first group in this item.

◆ conditionalsSatisfied()

bool GroupItem::conditionalsSatisfied ( bool  useActiveCategories = true) const

Returns true if the GroupItem satisfies its conditional requirements.

Requirements are met if the item is not conditional, or if it have the appropriate number of enabled items that are relevant. If useActiveCategories is true, then category checking using the resource's active categories is performed, else no category checking is done.

◆ isConditional()

bool GroupItem::isConditional ( ) const

Returns the item's conditional property.

If the Conditional Property is true, then the Group Item represents a collection of choices. the GroupItem will use its minNumberOfChoices and maxNumberOfChoices properties to determine its validity. Default is false.

◆ isValidInternal()

bool GroupItem::isValidInternal ( bool  useCategories,
const std::set< std::string > &  categories 
) const
overrideprotectedvirtual

Internal implementation of calculating the validity of the item.

If useCategories is true then the set of categories will be taken into consideration.

Implements smtk::attribute::Item.

◆ item()

smtk::attribute::ItemPtr smtk::attribute::GroupItem::item ( std::size_t  element,
std::size_t  ith 
) const
inline

Return the i-th item in for the element-th value of the group.

If a group has M required values and each value consists of N items, then element must be in [0,M - 1] and ith in [0, N - 1].

Note that numberOfGroups() returns M and numberOfItemsPerGroup() returns N.

◆ rotate()

bool GroupItem::rotate ( std::size_t  fromPosition,
std::size_t  toPosition 
)
overridevirtual

Rotate the order of subgroups between specified positions.

The subgroup at fromPosition is moved to toPosition, and the subgroups in between are shifted one position. The return value is true if the rotation was applied, which is when both position arguments are valid with respect to the underlying data/range.

Reimplemented from smtk::attribute::Item.

◆ visitChildren()

void GroupItem::visitChildren ( std::function< void(smtk::attribute::ItemPtr, bool)>  visitor,
bool  activeChildren = true 
)
overridevirtual

visitChildren Invoke a function on each (or, if findInActiveChildren is true, each active) child item.

If a subclass presents children items(ValueItem, Group, ...) then this function should be overriden.

Parameters
visitora lambda function which would be applied on children items
activeChildrena flag indicating whether it should be applied to active children only or not

Reimplemented from smtk::attribute::Item.


The documentation for this class was generated from the following files: