From 7f38064c6d46b4669eb4485de48d6f599997742f Mon Sep 17 00:00:00 2001 From: paulc Date: Mon, 22 Dec 2014 11:56:16 +0000 Subject: [PATCH] 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 --- engine/Configuration.cpp | 7 +++++ engine/NamedList.cpp | 7 +++++ modules/javascript.cpp | 68 ++++++++++++++++++++++++++++++++++++++++ yateclass.h | 13 ++++++++ yatengine.h | 14 +++++++++ 5 files changed, 109 insertions(+) diff --git a/engine/Configuration.cpp b/engine/Configuration.cpp index a1b6048e..b36babd9 100644 --- a/engine/Configuration.cpp +++ b/engine/Configuration.cpp @@ -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); diff --git a/engine/NamedList.cpp b/engine/NamedList.cpp index aa066542..fd57e2e9 100644 --- a/engine/NamedList.cpp +++ b/engine/NamedList.cpp @@ -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); diff --git a/modules/javascript.cpp b/modules/javascript.cpp index 15c8b755..8ae847d1 100644 --- a/modules/javascript.cpp +++ b/modules/javascript.cpp @@ -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(args[2])->valInteger(); + // fall through + case 2: + break; + default: + return false; + } + const String& sect = *static_cast(args[0]); + const String& name = *static_cast(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(args[2])->valBoolean(); + // fall through + case 2: + break; + default: + return false; + } + const String& sect = *static_cast(args[0]); + const String& name = *static_cast(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(args[1])->valInteger(); + // fall through + case 1: + break; + default: + return false; + } + const String& name = *static_cast(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(args[1])->valBoolean(); + // fall through + case 1: + break; + default: + return false; + } + const String& name = *static_cast(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; diff --git a/yateclass.h b/yateclass.h index 22b218ff..b5ec06dc 100644 --- a/yateclass.h +++ b/yateclass.h @@ -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 diff --git a/yatengine.h b/yatengine.h index 4aff94f6..d9d4398a 100644 --- a/yatengine.h +++ b/yatengine.h @@ -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