From bdbbbc507683954721370aad15b8d43393dd28fe Mon Sep 17 00:00:00 2001 From: paulc Date: Mon, 31 Aug 2009 13:36:37 +0000 Subject: [PATCH] Added NamedList constructor and method to copy subparameters from another list. git-svn-id: http://yate.null.ro/svn/yate/trunk@2811 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/NamedList.cpp | 24 ++++++++++++++++++++++++ yateclass.h | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/engine/NamedList.cpp b/engine/NamedList.cpp index 9f90bfa0..fd290b03 100644 --- a/engine/NamedList.cpp +++ b/engine/NamedList.cpp @@ -46,6 +46,12 @@ NamedList::NamedList(const NamedList& original) } } +NamedList::NamedList(const char* name, const NamedList& original, const String& prefix) + : String(name) +{ + copySubParams(original,prefix); +} + void* NamedList::getObject(const String& name) const { if (name == "NamedList") @@ -172,6 +178,24 @@ NamedList& NamedList::copyParams(const NamedList& original, const String& list, return *this; } +NamedList& NamedList::copySubParams(const NamedList& original, const String& prefix) +{ + XDebug(DebugInfo,"NamedList::copySubParams(%p,\"%s\")",&original,prefix.c_str()); + if (prefix) { + unsigned int offs = prefix.length(); + unsigned int n = original.length(); + for (unsigned int i = 0; i < n; i++) { + const NamedString* s = original.getParam(i); + if (s && s->name().startsWith(prefix)) { + const char* name = s->name().c_str() + offs; + if (*name) + addParam(name,*s); + } + } + } + return *this; +} + void NamedList::dump(String& str, const char* separator, char quote, bool force) const { if (force && str.null()) diff --git a/yateclass.h b/yateclass.h index 82068c42..fbe68bda 100644 --- a/yateclass.h +++ b/yateclass.h @@ -3240,6 +3240,14 @@ public: */ NamedList(const NamedList& original); + /** + * Creates a named list with subparameters of another list. + * @param name Name of the list - must not be NULL or empty + * @param original Named list to copy parameters from + * @param prefix Prefix to match and remove from parameter names + */ + NamedList(const char* name, const NamedList& original, const String& prefix); + /** * Get a pointer to a derived class given that class name * @param name Name of the class we are asking for @@ -3330,6 +3338,13 @@ public: */ NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0); + /** + * Copy subparameters from another list + * @param original Named list to copy parameters from + * @param prefix Prefix to match and remove from parameter names, must not be NULL + */ + NamedList& copySubParams(const NamedList& original, const String& prefix); + /** * Get the index of a named string in the parameter list. * @param param Pointer to the parameter to locate