SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
CustomItemDefinition.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_CustomItemDefinition_h
11 #define smtk_attribute_CustomItemDefinition_h
12 
13 #include "smtk/CoreExports.h"
14 #include "smtk/PublicPointerDefs.h"
15 
16 #include "smtk/attribute/Item.h"
17 #include "smtk/attribute/ItemDefinition.h"
18 #include "smtk/attribute/Resource.h"
19 
20 #include "smtk/common/CompilerInformation.h"
21 
22 #include "smtk/resource/Manager.h"
23 #include "smtk/resource/Observer.h"
24 
25 SMTK_THIRDPARTY_PRE_INCLUDE
26 #include "nlohmann/json.hpp"
27 SMTK_THIRDPARTY_POST_INCLUDE
28 
29 namespace pugi
30 {
31 class xml_node;
32 }
33 
34 namespace smtk
35 {
36 namespace attribute
37 {
38 
41 class SMTKCORE_EXPORT CustomItemBaseDefinition : public ItemDefinition
42 {
43 public:
45 
46  CustomItemBaseDefinition(const std::string& myName)
47  : ItemDefinition(myName)
48  {
49  }
50 
51  virtual const CustomItemBaseDefinition& operator>>(nlohmann::json& json) const = 0;
52  virtual CustomItemBaseDefinition& operator<<(const nlohmann::json& json) = 0;
53 
54  virtual const CustomItemBaseDefinition& operator>>(pugi::xml_node& node) const = 0;
55  virtual CustomItemBaseDefinition& operator<<(const pugi::xml_node& node) = 0;
56 };
57 
60 template<typename ItemType>
62 {
63 public:
64  typedef std::shared_ptr<CustomItemDefinition> Ptr;
65 
66  CustomItemDefinition(const std::string& myName)
67  : CustomItemBaseDefinition(myName)
68  {
69  }
70 
71  Item::Type type() const override { return Item::NUMBER_OF_TYPES; }
72 
73  ItemPtr buildItem(Attribute* owningAttribute, int itemPosition) const override
74  {
75  return ItemPtr(new ItemType(owningAttribute, itemPosition));
76  }
77 
78  ItemPtr buildItem(Item* owningItem, int position, int subGroupPosition) const override
79  {
80  return ItemPtr(new ItemType(owningItem, position, subGroupPosition));
81  }
82 };
83 } // namespace attribute
84 } // namespace smtk
85 
86 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::attribute::Item::Type
Type
Definition: Item.h:52
PublicPointerDefs.h
smtk::attribute::CustomItemBaseDefinition
A base class for custom (i.e.
Definition: CustomItemDefinition.h:41
smtk::attribute::CustomItemDefinition
Custom item definitions inherit from from a specialization of this template class,...
Definition: CustomItemDefinition.h:61
smtk::attribute::ItemDefinition
Definition: ItemDefinition.h:37
smtk::task::operator<<
std::ostream & operator<<(std::ostream &os, const State &s)
States may be appended to streams.
Definition: State.h:78
smtk::attribute::Item
Definition: Item.h:43
smtkTypeMacro
#define smtkTypeMacro(...)
Add typedefs to a class for identifcation.
Definition: SharedFromThis.h:51
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:49
smtk::attribute::ItemPtr
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:467