From 2f263229f902a60d53ba581a48f887c68748f833 Mon Sep 17 00:00:00 2001 From: "DrZiplok@gmail.com" Date: Sun, 23 Jan 2011 23:46:58 +0000 Subject: [PATCH] Rename AP_Meta_class::AP_Type_id to AP_Meta_class::Type_id in keeping with the coding standard. Add a non-static version of AP_Meta_class::meta_cast that can be used against any subclass object directly. git-svn-id: https://arducopter.googlecode.com/svn/trunk@1539 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/AP_Common/AP_MetaClass.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Common/AP_MetaClass.h b/libraries/AP_Common/AP_MetaClass.h index 35a3f9dad2..b46f4308d1 100644 --- a/libraries/AP_Common/AP_MetaClass.h +++ b/libraries/AP_Common/AP_MetaClass.h @@ -48,7 +48,7 @@ public: /// /// See ::meta_type_id for a discussion of class type IDs. /// - typedef uint16_t AP_Type_id; + typedef uint16_t Type_id; /// Obtain a value unique to all instances of a specific subclass. /// @@ -68,21 +68,21 @@ public: /// /// @return A type-unique value for this. /// - AP_Type_id meta_type_id(void) const { - return *(AP_Type_id *)this; + Type_id meta_type_id(void) const { + return *(Type_id *)this; } /// Obtain a value unique to all instances of a named subclass. /// /// This is similar to ::meta_type_id, but is a template taking a class name. - /// Use this function to cache the AP_Type_id for a class when you don't need + /// Use this function to cache the Type_id for a class when you don't need /// or cannot afford the constructor cost associated with meta_cast. /// /// @tparam T A subclass of AP_Meta_class. - /// @return The AP_Type_id value for T. + /// @return The Type_id value for T. /// template - static AP_Type_id meta_type_id(void) { + static Type_id meta_type_id(void) { T tmp; return tmp.meta_type_id(); } @@ -198,6 +198,22 @@ public: return NULL; } + /// Cast this to an expected class type. + /// + /// This is equivalent to meta_cast(this) + /// + /// @tparam T The name of a type to which this is to be cast. + /// @return NULL if this is not of precisely type T, otherwise this cast to T. + /// + template + T *meta_cast(void) { + T tmp; + if (meta_type_equivalent(this, &tmp)) { + return (T*)this; + } + return NULL; + } + /// Serialize the class. /// /// Serialization stores the state of the class in an external buffer in such a