SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
GroupItem.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 #ifndef smtk_attribute_GroupItem_h
11 #define smtk_attribute_GroupItem_h
12 
13 #include "smtk/CoreExports.h"
14 #include "smtk/attribute/Item.h"
15 #include <cassert>
16 #include <vector>
17 namespace smtk
18 {
19 namespace attribute
20 {
21 class GroupItemDefinition;
22 
48 class SMTKCORE_EXPORT GroupItem : public Item
49 {
50  friend class GroupItemDefinition;
51 
52 public:
53  typedef std::vector<std::vector<smtk::attribute::ItemPtr>>::const_iterator const_iterator;
54 
56  ~GroupItem() override;
57  Item::Type type() const override;
58 
59  std::size_t numberOfRequiredGroups() const;
60  std::size_t maxNumberOfGroups() const;
68  void visitChildren(
69  std::function<void(smtk::attribute::ItemPtr, bool)> visitor,
70  bool activeChildren = true) override;
71 
72  bool isExtensible() const;
73 
74  std::size_t numberOfGroups() const { return m_items.size(); }
75  bool setNumberOfGroups(std::size_t newSize);
76  std::size_t numberOfItemsPerGroup() const;
77  bool appendGroup();
78  bool prependGroup();
81  bool insertGroups(std::size_t pos, std::size_t num);
82  bool removeGroup(std::size_t element);
83 
85  smtk::attribute::ItemPtr item(std::size_t ith) const { return this->item(0, ith); }
93  smtk::attribute::ItemPtr item(std::size_t element, std::size_t ith) const
94  {
95  assert(m_items.size() > element);
96  assert(m_items[element].size() > ith);
97  return m_items[element][ith];
98  }
99 
101  find(std::size_t element, const std::string& name, SearchStyle style = IMMEDIATE);
103  find(std::size_t element, const std::string& name, SearchStyle style = IMMEDIATE) const;
104  using Item::find;
105 
106  template<typename T>
107  typename T::Ptr
108  findAs(std::size_t element, const std::string& name, SearchStyle style = IMMEDIATE);
109  template<typename T>
110  typename T::ConstPtr
111  findAs(std::size_t element, const std::string& name, SearchStyle style = IMMEDIATE) const;
112  using Item::findAs;
113 
115  void detachOwningResource() override;
116 
117  void reset() override;
118 
126  bool rotate(std::size_t fromPosition, std::size_t toPosition) override;
127 
133  bool isConditional() const;
134 
141  bool conditionalsSatisfied(bool useActiveCategories = true) const;
142 
147  void setMinNumberOfChoices(unsigned int value) { m_minNumberOfChoices = value; }
148  unsigned int minNumberOfChoices() const { return m_minNumberOfChoices; }
150 
155  void setMaxNumberOfChoices(unsigned int value) { m_maxNumberOfChoices = value; }
156  unsigned int maxNumberOfChoices() const { return m_maxNumberOfChoices; }
158 
161  const_iterator begin() const;
162  const_iterator end() const;
164 
165  using Item::assign;
171  Item::Status assign(
172  const smtk::attribute::ConstItemPtr& sourceItem,
173  const CopyAssignmentOptions& options,
174  smtk::io::Logger& logger) override;
175 
177  bool hasRelevantChildren(
178  bool includeCategories = true,
179  bool includeReadAccess = false,
180  int readAccessLevel = 0) const;
181 
182 protected:
183  GroupItem(Attribute* owningAttribute, int itemPosition);
184  GroupItem(Item* owningItem, int myPosition, int mySubGroupPosition);
185  bool setDefinition(smtk::attribute::ConstItemDefinitionPtr def) override;
187  smtk::attribute::ItemPtr findInternal(const std::string& name, SearchStyle style) override;
188  smtk::attribute::ConstItemPtr findInternal(const std::string& name, SearchStyle style)
189  const override;
190  // This method will detach all of the items directly owned by
191  // this group
192  void detachAllItems();
193  bool isValidInternal(bool useCategories, const std::set<std::string>& categories) const override;
194  std::vector<std::vector<smtk::attribute::ItemPtr>> m_items;
195  unsigned int m_maxNumberOfChoices;
196  unsigned int m_minNumberOfChoices;
197 
198 private:
199 };
200 
201 template<typename T>
202 typename T::Ptr GroupItem::findAs(std::size_t element, const std::string& iname, SearchStyle style)
203 {
204  return smtk::dynamic_pointer_cast<T>(this->find(element, iname, style));
205 }
206 
207 template<typename T>
208 typename T::ConstPtr
209 GroupItem::findAs(std::size_t element, const std::string& iname, SearchStyle style) const
210 {
211  return smtk::dynamic_pointer_cast<const T>(this->find(element, iname, style));
212 }
213 
214 } // namespace attribute
215 } // namespace smtk
216 
217 #endif /* __GroupItem_h */
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::attribute::Item::Type
Type
Definition: Item.h:56
smtk::attribute::GroupItem
A group item represents an array of structures in SMTK.
Definition: GroupItem.h:48
smtk::attribute::CopyAssignmentOptions
Class used to specify copy and assignment options.
Definition: CopyAssignmentOptions.h:272
smtk::attribute::SearchStyle
SearchStyle
How should searches for items be conducted?
Definition: SearchStyle.h:24
smtk::attribute::Item::assign
virtual Status assign(const smtk::attribute::ConstItemPtr &sourceItem, const CopyAssignmentOptions &options=CopyAssignmentOptions())
Definition: Item.cxx:274
smtk::attribute::GroupItem::item
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.
Definition: GroupItem.h:93
smtk::attribute::GroupItem::maxNumberOfChoices
unsigned int maxNumberOfChoices() const
Returns or sets the maximum number of choices that must be set for GroupItem, whose Conditional prope...
Definition: GroupItem.h:156
smtk::attribute::ConstItemDefinitionPtr
smtk::shared_ptr< const smtk::attribute::ItemDefinition > ConstItemDefinitionPtr
Definition: PublicPointerDefs.h:482
smtk::attribute::GroupItem::setMinNumberOfChoices
void setMinNumberOfChoices(unsigned int value)
Returns or sets the minimum number of choices that must be set for the GroupItem, whose Conditional p...
Definition: GroupItem.h:147
smtk::io::Logger
Log messages for later presentation to a user or a file.
Definition: Logger.h:94
smtk::attribute::IMMEDIATE
@ IMMEDIATE
Search only the top level items of an item or attribute.
Definition: SearchStyle.h:26
smtk::attribute::GroupItem::setMaxNumberOfChoices
void setMaxNumberOfChoices(unsigned int value)
Returns or sets the maximum number of choices that must be set for GroupItem, whose Conditional prope...
Definition: GroupItem.h:155
smtk::attribute::Item
The base class for items that hold information inside an attribute.
Definition: Item.h:47
smtk::common::Status
A return value for methods that need to indicate both success/failure and modification/stasis.
Definition: Status.h:30
smtkTypeMacro
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:128
smtk::attribute::ConstItemPtr
smtk::shared_ptr< const smtk::attribute::Item > ConstItemPtr
Definition: PublicPointerDefs.h:476
smtk::attribute::Item::findAs
T::Ptr findAs(const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
return a child item that matches name and satisfies the SearchStyle
Definition: Item.h:321
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:50
smtk::attribute::ItemPtr
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:474
smtk::attribute::GroupItemDefinition
A GroupItemDefinition represents a collection of Item Definitions.
Definition: GroupItemDefinition.h:32
smtk::attribute::Item::find
smtk::attribute::ItemPtr find(const std::string &name, SearchStyle style=RECURSIVE_ACTIVE)
return a child item that matches name and satisfies the SearchStyle
Definition: Item.cxx:136
smtk::attribute::GroupItem::minNumberOfChoices
unsigned int minNumberOfChoices() const
Returns or sets the minimum number of choices that must be set for the GroupItem, whose Conditional p...
Definition: GroupItem.h:148
smtk::attribute::GroupItem::item
smtk::attribute::ItemPtr item(std::size_t ith) const
Return the i-th item in the first entry of the group.
Definition: GroupItem.h:85