Add {Structure,Union}::getFieldT, fix {Structure,Union}::getField
This commit is contained in:
committed by
mdavidsaver
parent
cfcdd1a3f9
commit
caa11605fc
+65
-5
@@ -719,7 +719,7 @@ public:
|
||||
* @return The introspection interface.
|
||||
* This will hold a null pointer if the field is not in the structure.
|
||||
*/
|
||||
FieldConstPtr getField(std::string const &fieldName) const;
|
||||
FieldConstPtr getField(std::string const &fieldName) const {return getFieldImpl(fieldName, false);};
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getField(std::string const &fieldName) const
|
||||
@@ -731,13 +731,27 @@ public:
|
||||
return std::tr1::shared_ptr<const FT>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param fieldName The name of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will throw a runtime_error exception if the field is not in the structure.
|
||||
*/
|
||||
FieldConstPtr getFieldT(std::string const &fieldName) const {return getFieldImpl(fieldName, true);};
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getFieldT(std::string const &fieldName) const
|
||||
{
|
||||
return std::tr1::dynamic_pointer_cast<const FT>(getFieldT(fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param index The index of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will hold a null pointer if the field is not in the structure.
|
||||
*/
|
||||
const FieldConstPtr& getField(std::size_t index) const {return fields.at(index);}
|
||||
FieldConstPtr getField(std::size_t index) const {return getFieldImpl(index, false);}
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getField(std::size_t index) const
|
||||
@@ -749,6 +763,20 @@ public:
|
||||
return std::tr1::shared_ptr<const FT>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param index The index of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will throw a runtime_error exception if the field is not in the structure.
|
||||
*/
|
||||
FieldConstPtr getFieldT(std::size_t index) const {return getFieldImpl(index, true);}
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getFieldT(std::size_t index) const
|
||||
{
|
||||
return std::tr1::dynamic_pointer_cast<const FT>(getFieldT(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field index for the specified fieldName.
|
||||
* @return The introspection interface.
|
||||
@@ -790,6 +818,8 @@ private:
|
||||
FieldConstPtrArray fields;
|
||||
std::string id;
|
||||
|
||||
FieldConstPtr getFieldImpl(const std::string& fieldName, bool throws) const;
|
||||
FieldConstPtr getFieldImpl(const std::size_t fieldOffset, bool throws) const;
|
||||
void dumpFields(std::ostream& o) const;
|
||||
|
||||
friend class FieldCreate;
|
||||
@@ -842,7 +872,7 @@ public:
|
||||
* @return The introspection interface.
|
||||
* This will hold a null pointer if the field is not in the union.
|
||||
*/
|
||||
FieldConstPtr getField(std::string const &fieldName) const;
|
||||
FieldConstPtr getField(std::string const &fieldName) const {return getFieldImpl(fieldName, false);};
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getField(std::string const &fieldName) const
|
||||
@@ -854,13 +884,27 @@ public:
|
||||
return std::tr1::shared_ptr<const FT>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param fieldName The name of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will throw a runtime_error exception if the field is not in the union.
|
||||
*/
|
||||
FieldConstPtr getFieldT(std::string const &fieldName) const {return getFieldImpl(fieldName, true);};
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getFieldT(std::string const &fieldName) const
|
||||
{
|
||||
return std::tr1::dynamic_pointer_cast<const FT>(getFieldT(fieldName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param index The index of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will hold a null pointer if the field is not in the union.
|
||||
*/
|
||||
FieldConstPtr getField(std::size_t index) const {return fields.at(index);}
|
||||
FieldConstPtr getField(std::size_t index) const {return getFieldImpl(index, false);}
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getField(std::size_t index) const
|
||||
@@ -872,6 +916,20 @@ public:
|
||||
return std::tr1::shared_ptr<const FT>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field for the specified fieldName.
|
||||
* @param index The index of the field to get;
|
||||
* @return The introspection interface.
|
||||
* This will throw a runtime_error exception if the field is not in the union.
|
||||
*/
|
||||
FieldConstPtr getFieldT(std::size_t index) const {return getFieldImpl(index, true);}
|
||||
|
||||
template<typename FT>
|
||||
std::tr1::shared_ptr<const FT> getFieldT(std::size_t index) const
|
||||
{
|
||||
return std::tr1::dynamic_pointer_cast<const FT>(getFieldT(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field index for the specified fieldName.
|
||||
* @return The introspection interface.
|
||||
@@ -929,7 +987,9 @@ private:
|
||||
StringArray fieldNames;
|
||||
FieldConstPtrArray fields;
|
||||
std::string id;
|
||||
|
||||
|
||||
FieldConstPtr getFieldImpl(const std::string& fieldName, bool throws) const;
|
||||
FieldConstPtr getFieldImpl(const std::size_t fieldOffset, bool throws) const;
|
||||
void dumpFields(std::ostream& o) const;
|
||||
|
||||
friend class FieldCreate;
|
||||
|
||||
Reference in New Issue
Block a user