From 98da0c0becadb74d3ec01c691d7ac1034082ae81 Mon Sep 17 00:00:00 2001 From: dhickin Date: Mon, 30 Mar 2015 09:05:59 +0100 Subject: [PATCH] Add template getField member functions which return specific field types to Structure and Union. --- src/pv/pvIntrospect.h | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/pv/pvIntrospect.h b/src/pv/pvIntrospect.h index a7a1cfb..1d339be 100644 --- a/src/pv/pvIntrospect.h +++ b/src/pv/pvIntrospect.h @@ -670,6 +670,17 @@ public: * This will hold a null pointer if the field is not in the structure. */ FieldConstPtr getField(std::string const &fieldName) const; + + template + std::tr1::shared_ptr getField(std::string const &fieldName) const + { + FieldConstPtr field = getField(fieldName); + if (field.get()) + return std::tr1::dynamic_pointer_cast(field); + else + return std::tr1::shared_ptr(); + } + /** * Get the field for the specified fieldName. * @param fieldName The index of the field to get; @@ -677,6 +688,17 @@ public: * This will hold a null pointer if the field is not in the structure. */ FieldConstPtr getField(std::size_t index) const {return fields.at(index);} + + template + std::tr1::shared_ptr getField(std::size_t index) const + { + FieldConstPtr field = getField(index); + if (field.get()) + return std::tr1::dynamic_pointer_cast(field); + else + return std::tr1::shared_ptr(); + } + /** * Get the field index for the specified fieldName. * @return The introspection interface. @@ -757,6 +779,17 @@ public: * This will hold a null pointer if the field is not in the union. */ FieldConstPtr getField(std::string const &fieldName) const; + + template + std::tr1::shared_ptr getField(std::string const &fieldName) const + { + FieldConstPtr field = getField(fieldName); + if (field.get()) + return std::tr1::dynamic_pointer_cast(field); + else + return std::tr1::shared_ptr(); + } + /** * Get the field for the specified fieldName. * @param fieldName The index of the field to get; @@ -764,6 +797,17 @@ public: * 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);} + + template + std::tr1::shared_ptr getField(std::size_t index) const + { + FieldConstPtr field = getField(index); + if (field.get()) + return std::tr1::dynamic_pointer_cast(field); + else + return std::tr1::shared_ptr(); + } + /** * Get the field index for the specified fieldName. * @return The introspection interface.