From c70d3db1e64dcb90f94a30267031cb7b8526903e Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Sat, 22 Mar 2025 10:29:24 -0400 Subject: [PATCH] Params: support filtering by `ParamKeyType` for `allKeys` (#696) --- common/params.cc | 6 ++++-- common/params.h | 2 +- common/params_pyx.pyx | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/common/params.cc b/common/params.cc index d1e5a3646..94fbfa4a7 100644 --- a/common/params.cc +++ b/common/params.cc @@ -103,10 +103,12 @@ Params::~Params() { assert(queue.empty()); } -std::vector Params::allKeys() const { +std::vector Params::allKeys(ParamKeyType type) const { std::vector ret; for (auto &p : keys) { - ret.push_back(p.first); + if (type == ALL || (p.second & type)) { + ret.push_back(p.first); + } } return ret; } diff --git a/common/params.h b/common/params.h index b40371f97..73e21a3fe 100644 --- a/common/params.h +++ b/common/params.h @@ -28,7 +28,7 @@ public: Params(const Params&) = delete; Params& operator=(const Params&) = delete; - std::vector allKeys() const; + std::vector allKeys(ParamKeyType type = ALL) const; bool checkKey(const std::string &key); ParamKeyType getKeyType(const std::string &key); inline std::string getParamPath(const std::string &key = {}) { diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 2d11ab649..e851020d8 100644 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -11,6 +11,7 @@ cdef extern from "common/params.h": CLEAR_ON_ONROAD_TRANSITION CLEAR_ON_OFFROAD_TRANSITION DEVELOPMENT_ONLY + BACKUP ALL cdef cppclass c_Params "Params": @@ -25,7 +26,7 @@ cdef extern from "common/params.h": bool checkKey(string) nogil string getParamPath(string) nogil void clearAll(ParamKeyType) - vector[string] allKeys() + vector[string] allKeys(ParamKeyType) def ensure_bytes(v): @@ -119,5 +120,5 @@ cdef class Params: cdef string key_bytes = ensure_bytes(key) return self.p.getParamPath(key_bytes).decode("utf-8") - def all_keys(self): - return self.p.allKeys() + def all_keys(self, type=ParamKeyType.ALL): + return self.p.allKeys(type)