Added getInt64Value to NamedList and Configuration classes.

Added getIntValue and getBoolValue to Javascript ConfigFile and ConfigSection.


git-svn-id: http://yate.null.ro/svn/yate/trunk@5930 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2014-12-22 11:56:16 +00:00
parent 7f834fd8b8
commit 7f38064c6d
5 changed files with 109 additions and 0 deletions

View File

@ -87,6 +87,13 @@ int Configuration::getIntValue(const String& sect, const String& key, const Toke
return s ? s->toInteger(tokens,defvalue) : defvalue;
}
int64_t Configuration::getInt64Value(const String& sect, const String& key, int64_t defvalue,
int64_t minvalue, int64_t maxvalue, bool clamp) const
{
const NamedString *s = getKey(sect,key);
return s ? s->toInt64(defvalue,0,minvalue,maxvalue,clamp) : defvalue;
}
double Configuration::getDoubleValue(const String& sect, const String& key, double defvalue) const
{
const NamedString *s = getKey(sect,key);

View File

@ -313,6 +313,13 @@ int NamedList::getIntValue(const String& name, const TokenDict* tokens, int defv
return s ? s->toInteger(tokens,defvalue) : defvalue;
}
int64_t NamedList::getInt64Value(const String& name, int64_t defvalue, int64_t minvalue,
int64_t maxvalue, bool clamp) const
{
const NamedString *s = getParam(name);
return s ? s->toInt64(defvalue,0,minvalue,maxvalue,clamp) : defvalue;
}
double NamedList::getDoubleValue(const String& name, double defvalue) const
{
const NamedString *s = getParam(name);

View File

@ -446,6 +446,8 @@ public:
params().addParam(new ExpFunction("sections"));
params().addParam(new ExpFunction("getSection"));
params().addParam(new ExpFunction("getValue"));
params().addParam(new ExpFunction("getIntValue"));
params().addParam(new ExpFunction("getBoolValue"));
params().addParam(new ExpFunction("setValue"));
params().addParam(new ExpFunction("clearKey"));
params().addParam(new ExpFunction("keys"));
@ -475,6 +477,8 @@ protected:
XDebug(DebugAll,"JsConfigSection::JsConfigSection(%p,'%s') [%p]",owner,name,this);
params().addParam(new ExpFunction("configFile"));
params().addParam(new ExpFunction("getValue"));
params().addParam(new ExpFunction("getIntValue"));
params().addParam(new ExpFunction("getBoolValue"));
params().addParam(new ExpFunction("setValue"));
params().addParam(new ExpFunction("clearKey"));
params().addParam(new ExpFunction("keys"));
@ -2351,6 +2355,36 @@ bool JsConfigFile::runNative(ObjList& stack, const ExpOperation& oper, GenObject
else
ExpEvaluator::pushOne(stack,new ExpOperation(val,name));
}
else if (oper.name() == YSTRING("getIntValue")) {
int64_t defVal = 0;
switch (extractArgs(stack,oper,context,args)) {
case 3:
defVal = static_cast<ExpOperation*>(args[2])->valInteger();
// fall through
case 2:
break;
default:
return false;
}
const String& sect = *static_cast<ExpOperation*>(args[0]);
const String& name = *static_cast<ExpOperation*>(args[1]);
ExpEvaluator::pushOne(stack,new ExpOperation(m_config.getInt64Value(sect,name,defVal),name));
}
else if (oper.name() == YSTRING("getBoolValue")) {
bool defVal = false;
switch (extractArgs(stack,oper,context,args)) {
case 3:
defVal = static_cast<ExpOperation*>(args[2])->valBoolean();
// fall through
case 2:
break;
default:
return false;
}
const String& sect = *static_cast<ExpOperation*>(args[0]);
const String& name = *static_cast<ExpOperation*>(args[1]);
ExpEvaluator::pushOne(stack,new ExpOperation(m_config.getBoolValue(sect,name,defVal),name));
}
else if (oper.name() == YSTRING("setValue")) {
if (extractArgs(stack,oper,context,args) != 3)
return false;
@ -2446,6 +2480,40 @@ bool JsConfigSection::runNative(ObjList& stack, const ExpOperation& oper, GenObj
else
ExpEvaluator::pushOne(stack,new ExpOperation(val,name));
}
else if (oper.name() == YSTRING("getIntValue")) {
int64_t val = 0;
switch (extractArgs(stack,oper,context,args)) {
case 2:
val = static_cast<ExpOperation*>(args[1])->valInteger();
// fall through
case 1:
break;
default:
return false;
}
const String& name = *static_cast<ExpOperation*>(args[0]);
NamedList* sect = m_owner->config().getSection(toString());
if (sect)
val = sect->getInt64Value(name,val);
ExpEvaluator::pushOne(stack,new ExpOperation(val,name));
}
else if (oper.name() == YSTRING("getBoolValue")) {
bool val = false;
switch (extractArgs(stack,oper,context,args)) {
case 2:
val = static_cast<ExpOperation*>(args[1])->valBoolean();
// fall through
case 1:
break;
default:
return false;
}
const String& name = *static_cast<ExpOperation*>(args[0]);
NamedList* sect = m_owner->config().getSection(toString());
if (sect)
val = sect->getBoolValue(name,val);
ExpEvaluator::pushOne(stack,new ExpOperation(val,name));
}
else if (oper.name() == YSTRING("setValue")) {
if (extractArgs(stack,oper,context,args) != 2)
return false;

View File

@ -4625,6 +4625,19 @@ public:
*/
int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
/**
* Retrieve the 64-bit numeric value of a parameter.
* @param name Name of parameter to locate
* @param defvalue Default value to return if not found
* @param minvalue Minimum value allowed for the parameter
* @param maxvalue Maximum value allowed for the parameter
* @param clamp Control the out of bound values: true to adjust to the nearest
* bound, false to return the default value
* @return The number contained in the named parameter or the default
*/
int64_t getInt64Value(const String& name, int64_t defvalue = 0, int64_t minvalue = LLONG_MIN,
int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
/**
* Retrieve the floating point value of a parameter.
* @param name Name of parameter to locate

View File

@ -128,6 +128,20 @@ public:
*/
int getIntValue(const String& sect, const String& key, const TokenDict* tokens, int defvalue = 0) const;
/**
* Retrieve the 64-bit numeric value of a key in a section.
* @param sect Name of the section
* @param key Name of the key in section
* @param defvalue Default value to return if not found
* @param minvalue Minimum value allowed for the parameter
* @param maxvalue Maximum value allowed for the parameter
* @param clamp Control the out of bound values: true to adjust to the nearest
* bound, false to return the default value
* @return The number contained in the key or the default
*/
int64_t getInt64Value(const String& sect, const String& key, int64_t defvalue = 0,
int64_t minvalue = LLONG_MIN, int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
/**
* Retrieve the floating point value of a key in a section.
* @param sect Name of the section