Added support for hierarchical parameter names.

git-svn-id: http://voip.null.ro/svn/yate@1120 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2006-11-30 00:53:15 +00:00
parent 5c95dce80d
commit 46f591363e
2 changed files with 77 additions and 6 deletions

View File

@ -87,13 +87,17 @@ NamedList& NamedList::setParam(const char* name, const char* value)
return *this;
}
NamedList& NamedList::clearParam(const String& name)
NamedList& NamedList::clearParam(const String& name, char childSep)
{
XDebug(DebugInfo,"NamedList::clearParam(\"%s\")",name.c_str());
XDebug(DebugInfo,"NamedList::clearParam(\"%s\",'%1s')",
name.c_str(),&childSep);
String tmp;
if (childSep)
tmp << name << childSep;
ObjList *p = &m_params;
while (p) {
NamedString *s = static_cast<NamedString *>(p->get());
if (s && (s->name() == name))
if (s && ((s->name() == name) || s->name().startsWith(tmp)))
p->remove();
else
p = p->next();
@ -101,11 +105,55 @@ NamedList& NamedList::clearParam(const String& name)
return *this;
}
NamedList& NamedList::copyParam(const NamedList& original, const String& name, char childSep)
{
XDebug(DebugInfo,"NamedList::copyParam(%p,\"%s\",'%1s')",
&original,name.c_str(),&childSep);
if (!childSep) {
// faster and simpler - used in most cases
const NamedString* s = original.getParam(name);
return s ? setParam(name,*s) : clearParam(name);
}
clearParam(name,childSep);
String tmp;
tmp << name << childSep;
unsigned int n = original.length();
for (unsigned int i = 0; i < n; i++) {
const NamedString* s = original.getParam(i);
if (s && ((s->name() == name) || s->name().startsWith(tmp)))
addParam(s->name(),*s);
}
return *this;
}
int NamedList::getIndex(const NamedString* param) const
{
if (!param)
return -1;
const ObjList *p = &m_params;
for (int i=0; p; p=p->next(),i++) {
if (static_cast<const NamedString *>(p->get()) == param)
return i;
}
return -1;
}
int NamedList::getIndex(const String& name) const
{
const ObjList *p = &m_params;
for (int i=0; p; p=p->next(),i++) {
NamedString *s = static_cast<NamedString *>(p->get());
if (s && (s->name() == name))
return i;
}
return -1;
}
NamedString* NamedList::getParam(const String& name) const
{
XDebug(DebugInfo,"NamedList::getParam(\"%s\")",name.c_str());
const ObjList *p = m_params.skipNull();
for (;p;p=p->skipNext()) {
for (; p; p=p->skipNext()) {
NamedString *s = static_cast<NamedString *>(p->get());
if (s->name() == name)
return s;

View File

@ -2757,10 +2757,33 @@ public:
NamedList& setParam(const char* name, const char* value);
/**
* Clars all instances of a named string in the parameter list.
* Clears all instances of a named string in the parameter list.
* @param name Name of the string to remove
* @param childSep If set clears all child parameters in format name+childSep+anything
*/
NamedList& clearParam(const String& name);
NamedList& clearParam(const String& name, char childSep = 0);
/**
* Copy a parameter from another NamedList, clears it if not present there
* @param original NamedList to copy the parameter from
* @param name Name of the string to copy or clear
* @param childSep If set copies all child parameters in format name+childSep+anything
*/
NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
/**
* Get the index of a named string in the parameter list.
* @param param Pointer to the parameter to locate
* @return Index of the named string or -1 if not found
*/
int getIndex(const NamedString* param) const;
/**
* Get the index of first matching named string in the parameter list.
* @param name Name of parameter to locate
* @return Index of the first matching named string or -1 if not found
*/
int getIndex(const String& name) const;
/**
* Locate a named string in the parameter list.