Commit 0bb07aa6 authored by Bob Obara's avatar Bob Obara
Browse files

ENH:Added CastTo Methods for Wrapping

Also made all Item constructors and setDefinition methods protected
parent 7ad9b5c7
...@@ -200,4 +200,4 @@ namespace smtk ...@@ -200,4 +200,4 @@ namespace smtk
}; };
}; };
#endif /* __smtk_PublicPointerDefs_h */ #endif /* __smtk_PublicPointerDefs_h */
\ No newline at end of file
...@@ -38,15 +38,18 @@ namespace smtk ...@@ -38,15 +38,18 @@ namespace smtk
{ {
class Attribute; class Attribute;
class AttributeRefItemDefinition; class AttributeRefItemDefinition;
class ValueItemDefinition;
class SMTKCORE_EXPORT AttributeRefItem : public Item class SMTKCORE_EXPORT AttributeRefItem : public Item
{ {
friend class Attribute; friend class AttributeRefItemDefinition;
friend class ValueItemDefinition;
public: public:
AttributeRefItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
AttributeRefItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::AttributeRefItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<AttributeRefItem>(p);}
virtual ~AttributeRefItem(); virtual ~AttributeRefItem();
virtual Item::Type type() const; virtual Item::Type type() const;
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
std::size_t numberOfValues() const std::size_t numberOfValues() const
{return this->m_values.size();} {return this->m_values.size();}
bool setNumberOfValues(std::size_t newSize); bool setNumberOfValues(std::size_t newSize);
...@@ -67,6 +70,9 @@ namespace smtk ...@@ -67,6 +70,9 @@ namespace smtk
virtual void unset(int element=0); virtual void unset(int element=0);
protected: protected:
AttributeRefItem(Attribute *owningAttribute, int itemPosition);
AttributeRefItem(Item *owningItem, int myPosition, int mySubGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
void clearAllReferences(); void clearAllReferences();
std::vector<WeakAttributePtr>m_values; std::vector<WeakAttributePtr>m_values;
private: private:
......
...@@ -45,6 +45,11 @@ namespace smtk ...@@ -45,6 +45,11 @@ namespace smtk
static smtk::AttributeRefItemDefinitionPtr New(const std::string &myName) static smtk::AttributeRefItemDefinitionPtr New(const std::string &myName)
{ return smtk::AttributeRefItemDefinitionPtr(new AttributeRefItemDefinition(myName));} { return smtk::AttributeRefItemDefinitionPtr(new AttributeRefItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::AttributeRefItemDefinitionPtr
CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<AttributeRefItemDefinition>(p);}
virtual ~AttributeRefItemDefinition(); virtual ~AttributeRefItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
......
...@@ -40,11 +40,13 @@ namespace smtk ...@@ -40,11 +40,13 @@ namespace smtk
class DirectoryItemDefinition; class DirectoryItemDefinition;
class SMTKCORE_EXPORT DirectoryItem : public Item class SMTKCORE_EXPORT DirectoryItem : public Item
{ {
friend class DirectoryItemDefinition;
public: public:
DirectoryItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
DirectoryItem(Item *owningItem, int position, int subGroupPosition); static smtk::DirectoryItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<DirectoryItem>(p);}
virtual ~DirectoryItem(); virtual ~DirectoryItem();
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
virtual Item::Type type() const; virtual Item::Type type() const;
bool shouldBeRelative() const; bool shouldBeRelative() const;
bool shouldExist() const; bool shouldExist() const;
...@@ -69,6 +71,9 @@ namespace smtk ...@@ -69,6 +71,9 @@ namespace smtk
{this->m_isSet[element] = false;} {this->m_isSet[element] = false;}
protected: protected:
DirectoryItem(Attribute *owningAttribute, int itemPosition);
DirectoryItem(Item *owningItem, int position, int subGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
std::vector<std::string>m_values; std::vector<std::string>m_values;
std::vector<bool> m_isSet; std::vector<bool> m_isSet;
private: private:
......
...@@ -44,6 +44,11 @@ namespace smtk ...@@ -44,6 +44,11 @@ namespace smtk
public: public:
static smtk::DirectoryItemDefinitionPtr New(const std::string &myName) static smtk::DirectoryItemDefinitionPtr New(const std::string &myName)
{ return smtk::DirectoryItemDefinitionPtr(new DirectoryItemDefinition(myName));} { return smtk::DirectoryItemDefinitionPtr(new DirectoryItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::DirectoryItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<DirectoryItemDefinition>(p);}
virtual ~DirectoryItemDefinition(); virtual ~DirectoryItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
......
...@@ -41,11 +41,15 @@ namespace smtk ...@@ -41,11 +41,15 @@ namespace smtk
{ {
friend class DoubleItemDefinition; friend class DoubleItemDefinition;
public: public:
DoubleItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
DoubleItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::DoubleItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<DoubleItem>(p);}
virtual ~DoubleItem(); virtual ~DoubleItem();
virtual Item::Type type() const; virtual Item::Type type() const;
protected: protected:
DoubleItem(Attribute *owningAttribute, int itemPosition);
DoubleItem(Item *owningItem, int myPosition, int mySubGroupPosition);
private: private:
......
...@@ -39,6 +39,11 @@ namespace smtk ...@@ -39,6 +39,11 @@ namespace smtk
public: public:
static smtk::DoubleItemDefinitionPtr New(const std::string &myName) static smtk::DoubleItemDefinitionPtr New(const std::string &myName)
{ return smtk::DoubleItemDefinitionPtr(new DoubleItemDefinition(myName));} { return smtk::DoubleItemDefinitionPtr(new DoubleItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::DoubleItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<DoubleItemDefinition>(p);}
virtual ~DoubleItemDefinition(); virtual ~DoubleItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute, virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute,
......
...@@ -40,11 +40,13 @@ namespace smtk ...@@ -40,11 +40,13 @@ namespace smtk
class FileItemDefinition; class FileItemDefinition;
class SMTKCORE_EXPORT FileItem : public Item class SMTKCORE_EXPORT FileItem : public Item
{ {
friend class FileItemDefinition;
public: public:
FileItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
FileItem(Item *owningItem, int position, int subGroupPosition); static smtk::FileItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<FileItem>(p);}
virtual ~FileItem(); virtual ~FileItem();
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
virtual Item::Type type() const; virtual Item::Type type() const;
bool shouldBeRelative() const; bool shouldBeRelative() const;
bool shouldExist() const; bool shouldExist() const;
...@@ -69,6 +71,9 @@ namespace smtk ...@@ -69,6 +71,9 @@ namespace smtk
{this->m_isSet[element] = false;} {this->m_isSet[element] = false;}
protected: protected:
FileItem(Attribute *owningAttribute, int itemPosition);
FileItem(Item *owningItem, int position, int subGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
std::vector<std::string>m_values; std::vector<std::string>m_values;
std::vector<bool> m_isSet; std::vector<bool> m_isSet;
private: private:
......
...@@ -45,6 +45,10 @@ namespace smtk ...@@ -45,6 +45,10 @@ namespace smtk
static smtk::FileItemDefinitionPtr New(const std::string &myName) static smtk::FileItemDefinitionPtr New(const std::string &myName)
{ return smtk::FileItemDefinitionPtr(new FileItemDefinition(myName));} { return smtk::FileItemDefinitionPtr(new FileItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::FileItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<FileItemDefinition>(p);}
virtual ~FileItemDefinition(); virtual ~FileItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
......
...@@ -39,11 +39,12 @@ namespace smtk ...@@ -39,11 +39,12 @@ namespace smtk
{ {
friend class GroupItemDefinition; friend class GroupItemDefinition;
public: public:
GroupItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
GroupItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::GroupItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<GroupItem>(p);}
virtual ~GroupItem(); virtual ~GroupItem();
virtual Item::Type type() const; virtual Item::Type type() const;
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
std::size_t numberOfRequiredGroups() const; std::size_t numberOfRequiredGroups() const;
std::size_t numberOfGroups() const std::size_t numberOfGroups() const
{return this->m_items.size();} {return this->m_items.size();}
...@@ -66,6 +67,9 @@ namespace smtk ...@@ -66,6 +67,9 @@ namespace smtk
virtual void reset(); virtual void reset();
protected: protected:
GroupItem(Attribute *owningAttribute, int itemPosition);
GroupItem(Item *owningItem, int myPosition, int mySubGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
// This method will detach all of the items directly owned by // This method will detach all of the items directly owned by
// this group // this group
void detachAllItems(); void detachAllItems();
......
...@@ -44,6 +44,10 @@ namespace smtk ...@@ -44,6 +44,10 @@ namespace smtk
static smtk::GroupItemDefinitionPtr New(const std::string &myName) static smtk::GroupItemDefinitionPtr New(const std::string &myName)
{ return smtk::GroupItemDefinitionPtr(new GroupItemDefinition(myName));} { return smtk::GroupItemDefinitionPtr(new GroupItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::GroupItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<GroupItemDefinition>(p);}
virtual ~GroupItemDefinition(); virtual ~GroupItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
std::size_t numberOfItemDefinitions() const std::size_t numberOfItemDefinitions() const
......
...@@ -41,11 +41,15 @@ namespace smtk ...@@ -41,11 +41,15 @@ namespace smtk
{ {
friend class IntItemDefinition; friend class IntItemDefinition;
public: public:
IntItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
IntItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::IntItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<IntItem>(p);}
virtual ~IntItem(); virtual ~IntItem();
virtual Item::Type type() const; virtual Item::Type type() const;
protected: protected:
IntItem(Attribute *owningAttribute, int itemPosition);
IntItem(Item *owningItem, int myPosition, int mySubGroupPosition);
private: private:
......
...@@ -40,6 +40,10 @@ namespace smtk ...@@ -40,6 +40,10 @@ namespace smtk
static smtk::IntItemDefinitionPtr New(const std::string &myName) static smtk::IntItemDefinitionPtr New(const std::string &myName)
{ return smtk::IntItemDefinitionPtr(new IntItemDefinition(myName));} { return smtk::IntItemDefinitionPtr(new IntItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::IntItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<IntItemDefinition>(p);}
virtual ~IntItemDefinition(); virtual ~IntItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute, virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute,
......
...@@ -40,32 +40,33 @@ namespace smtk ...@@ -40,32 +40,33 @@ namespace smtk
{ {
class ItemDefinition; class ItemDefinition;
class GroupItem; class GroupItem;
class GroupItemDefinition;
class Attribute; class Attribute;
class Definition;
class SMTKCORE_EXPORT Item class SMTKCORE_EXPORT Item
{ {
friend class Definition;
friend class GroupItemDefinition;
public: public:
enum Type enum Type
{ {
ATTRIBUTE_REF, ATTRIBUTE_REF,
DOUBLE, DOUBLE,
GROUP, GROUP,
INT, INT,
STRING, STRING,
VOID, VOID,
FILE, FILE,
DIRECTORY, DIRECTORY,
COLOR, COLOR,
NUMBER_OF_TYPES NUMBER_OF_TYPES
}; };
Item(Attribute *owningAttribute, int itemPosition);
Item(Item *owningItem, int myPosition, int mySubGroupPOsition);
virtual ~Item(); virtual ~Item();
std::string name() const; std::string name() const;
std::string label() const; std::string label() const;
virtual Item::Type type() const = 0; virtual Item::Type type() const = 0;
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
smtk::ConstAttributeItemDefinitionPtr definition() const smtk::ConstAttributeItemDefinitionPtr definition() const
{return this->m_definition;} {return this->m_definition;}
...@@ -120,17 +121,20 @@ namespace smtk ...@@ -120,17 +121,20 @@ namespace smtk
static std::string type2String(Item::Type t); static std::string type2String(Item::Type t);
static Item::Type string2Type(const std::string &s); static Item::Type string2Type(const std::string &s);
protected: protected:
Attribute *m_attribute; Item(Attribute *owningAttribute, int itemPosition);
Item *m_owningItem; Item(Item *owningItem, int myPosition, int mySubGroupPOsition);
int m_position; virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
int m_subGroupPosition; Attribute *m_attribute;
bool m_isEnabled; Item *m_owningItem;
mutable std::string m_tempString; int m_position;
smtk::ConstAttributeItemDefinitionPtr m_definition; int m_subGroupPosition;
std::map<std::string, smtk::UserDataPtr > m_userData; bool m_isEnabled;
mutable std::string m_tempString;
smtk::ConstAttributeItemDefinitionPtr m_definition;
std::map<std::string, smtk::UserDataPtr > m_userData;
private: private:
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
inline smtk::UserDataPtr Item::userData(const std::string &key) const inline smtk::UserDataPtr Item::userData(const std::string &key) const
......
...@@ -48,7 +48,6 @@ namespace smtk ...@@ -48,7 +48,6 @@ namespace smtk
friend class smtk::attribute::Definition; friend class smtk::attribute::Definition;
friend class smtk::attribute::GroupItemDefinition; friend class smtk::attribute::GroupItemDefinition;
public: public:
ItemDefinition(const std::string &myname);
virtual ~ItemDefinition(); virtual ~ItemDefinition();
const std::string &name() const const std::string &name() const
{ return this->m_name;} { return this->m_name;}
...@@ -116,6 +115,7 @@ namespace smtk ...@@ -116,6 +115,7 @@ namespace smtk
int position, int position,
int subGroupPosition) const = 0; int subGroupPosition) const = 0;
protected: protected:
ItemDefinition(const std::string &myname);
virtual void updateCategories(); virtual void updateCategories();
int m_version; int m_version;
bool m_isOptional; bool m_isOptional;
......
...@@ -41,11 +41,15 @@ namespace smtk ...@@ -41,11 +41,15 @@ namespace smtk
{ {
friend class StringItemDefinition; friend class StringItemDefinition;
public: public:
StringItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
StringItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::StringItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<StringItem>(p);}
virtual ~StringItem(); virtual ~StringItem();
virtual Item::Type type() const; virtual Item::Type type() const;
protected: protected:
StringItem(Attribute *owningAttribute, int itemPosition);
StringItem(Item *owningItem, int myPosition, int mySubGroupPosition);
private: private:
......
...@@ -40,6 +40,10 @@ namespace smtk ...@@ -40,6 +40,10 @@ namespace smtk
static smtk::StringItemDefinitionPtr New(const std::string &myName) static smtk::StringItemDefinitionPtr New(const std::string &myName)
{ return smtk::StringItemDefinitionPtr(new StringItemDefinition(myName));} { return smtk::StringItemDefinitionPtr(new StringItemDefinition(myName));}
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::StringItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<StringItemDefinition>(p);}
virtual ~StringItemDefinition(); virtual ~StringItemDefinition();
virtual Item::Type type() const; virtual Item::Type type() const;
virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute, virtual smtk::AttributeItemPtr buildItem(Attribute *owningAttribute,
......
...@@ -42,14 +42,15 @@ namespace smtk ...@@ -42,14 +42,15 @@ namespace smtk
{ {
public: public:
friend class ValueItemDefinition; friend class ValueItemDefinition;
ValueItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
ValueItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::ValueItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<ValueItem>(p);}
virtual ~ValueItem(); virtual ~ValueItem();
std::size_t numberOfValues() const std::size_t numberOfValues() const
{return this->m_isSet.size();} {return this->m_isSet.size();}
int numberOfRequiredValues() const; int numberOfRequiredValues() const;
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
bool allowsExpressions() const; bool allowsExpressions() const;
bool isExpression(int elementIndex=0) const bool isExpression(int elementIndex=0) const
{ return (this->expression(elementIndex) != NULL);} { return (this->expression(elementIndex) != NULL);}
...@@ -87,6 +88,9 @@ namespace smtk ...@@ -87,6 +88,9 @@ namespace smtk
{return this->m_expressions[elementIndex];} {return this->m_expressions[elementIndex];}
protected: protected:
ValueItem(Attribute *owningAttribute, int itemPosition);
ValueItem(Item *owningItem, int myPosition, int mySubGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr def);
virtual void updateDiscreteValue(int elementIndex) = 0; virtual void updateDiscreteValue(int elementIndex) = 0;
std::vector<int> m_discreteIndices; std::vector<int> m_discreteIndices;
std::vector<bool> m_isSet; std::vector<bool> m_isSet;
......
...@@ -52,6 +52,10 @@ namespace smtk ...@@ -52,6 +52,10 @@ namespace smtk
ValueItemDefinition(const std::string &myname); ValueItemDefinition(const std::string &myname);
virtual ~ValueItemDefinition(); virtual ~ValueItemDefinition();
// This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
static smtk::ValueItemDefinitionPtr CastTo(const smtk::AttributeItemDefinitionPtr &p)
{return smtk::dynamic_pointer_cast<ValueItemDefinition>(p);}
const std::string &units() const const std::string &units() const
{ return this->m_units;} { return this->m_units;}
void setUnits(const std::string &newUnits) void setUnits(const std::string &newUnits)
......
...@@ -46,10 +46,7 @@ namespace smtk ...@@ -46,10 +46,7 @@ namespace smtk
typedef DataT DataType; typedef DataT DataType;
typedef ValueItemDefinitionTemplate<DataType> DefType; typedef ValueItemDefinitionTemplate<DataType> DefType;
ValueItemTemplate(Attribute *owningAttribute, int itemPosition);
ValueItemTemplate(Item *owningItem, int myPosition, int mySubGroupPosition);
virtual ~ValueItemTemplate() {} virtual ~ValueItemTemplate() {}
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
std::size_t numberOfValues() const std::size_t numberOfValues() const
{return this->m_values.size();} {return this->m_values.size();}
virtual bool setNumberOfValues(std::size_t newSize); virtual bool setNumberOfValues(std::size_t newSize);
...@@ -68,6 +65,9 @@ namespace smtk ...@@ -68,6 +65,9 @@ namespace smtk
bool setToDefault(int element=0); bool setToDefault(int element=0);
protected: protected:
ValueItemTemplate(Attribute *owningAttribute, int itemPosition);
ValueItemTemplate(Item *owningItem, int myPosition, int mySubGroupPosition);
virtual bool setDefinition(smtk::ConstAttributeItemDefinitionPtr vdef);
virtual void updateDiscreteValue(int element); virtual void updateDiscreteValue(int element);
std::vector<DataT> m_values; std::vector<DataT> m_values;
private: private:
......
...@@ -39,14 +39,19 @@ namespace smtk ...@@ -39,14 +39,19 @@ namespace smtk
class VoidItemDefinition; class VoidItemDefinition;
class SMTKCORE_EXPORT VoidItem : public Item class SMTKCORE_EXPORT VoidItem : public Item
{ {
friend class VoidItemDefinition;
public: public:
VoidItem(Attribute *owningAttribute, int itemPosition); // This method is for wrapping code. C++ developers should use smtk::dynamicCastPointer
VoidItem(Item *owningItem, int myPosition, int mySubGroupPosition); static smtk::VoidItemPtr CastTo(const smtk::AttributeItemPtr &p)
{return smtk::dynamic_pointer_cast<VoidItem>(p);}