From 0431b6dc6980e7ae0d49367e8d2560c9450bb895 Mon Sep 17 00:00:00 2001 From: DrZiplok Date: Fri, 25 Mar 2011 02:46:45 +0000 Subject: [PATCH] Add an interface for locating a variable by key. git-svn-id: https://arducopter.googlecode.com/svn/trunk@1811 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- libraries/AP_Common/AP_Var.cpp | 16 ++++++++++++++++ libraries/AP_Common/AP_Var.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/libraries/AP_Common/AP_Var.cpp b/libraries/AP_Common/AP_Var.cpp index aab6b949ec..c45155998e 100644 --- a/libraries/AP_Common/AP_Var.cpp +++ b/libraries/AP_Common/AP_Var.cpp @@ -159,6 +159,22 @@ AP_Var::find(const char *name) return NULL; } +// Find a variable by key. +// +AP_Var * +AP_Var::find(Key key) +{ + AP_Var *vp; + + for (vp = first(); vp; vp = vp->next()) { + + if (key == vp->key()) { + return vp; + } + } + return NULL; +} + // Save the variable to EEPROM, if supported // diff --git a/libraries/AP_Common/AP_Var.h b/libraries/AP_Common/AP_Var.h index 7b545208e3..cdf2688533 100644 --- a/libraries/AP_Common/AP_Var.h +++ b/libraries/AP_Common/AP_Var.h @@ -214,6 +214,14 @@ public: /// static AP_Var *find(const char *name); + /// Find a variable by key. + /// + /// @param key The key being looked up. + /// @return A pointer to the variable, or NULL if + /// it does not exist. + /// + static AP_Var *find(Key key); + /// Save the current value of the variable to EEPROM. /// /// This interface works for any subclass that implements