diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index 79b8318c3c..9d4435b1a5 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,9 @@ +2008-06-11 Ramon Novoa + + * win32/pandora_strutils.cc, win32/pandora_strutils.h, + win32/modules/pandora_module.cc: Added support for floating-point + numbers. + 2008-06-11 Ramon Novoa * win32/bin/pandora_agent.conf: Added remote_config option. diff --git a/pandora_agents/win32/modules/pandora_module.cc b/pandora_agents/win32/modules/pandora_module.cc index 2c3eb06596..87bbc6a242 100644 --- a/pandora_agents/win32/modules/pandora_module.cc +++ b/pandora_agents/win32/modules/pandora_module.cc @@ -197,14 +197,14 @@ Pandora_Module::getModuleType () const { */ string Pandora_Module::getDataOutput (Pandora_Data *data) { - int value; + double value; if (this->module_type == TYPE_GENERIC_DATA_STRING) { return data->getValue (); } try { - value = Pandora_Strutils::strtoint (data->getValue ()); + value = Pandora_Strutils::strtodouble (data->getValue ()); } catch (Pandora_Strutils::Invalid_Conversion e) { pandoraLog ("Output error on module %s", this->module_name.c_str ()); @@ -219,7 +219,7 @@ Pandora_Module::getDataOutput (Pandora_Data *data) { } } - return Pandora_Strutils::inttostr (value); + return data->getValue (); } /** diff --git a/pandora_agents/win32/pandora_strutils.cc b/pandora_agents/win32/pandora_strutils.cc index 505b9f0828..cdabe3f9e7 100644 --- a/pandora_agents/win32/pandora_strutils.cc +++ b/pandora_agents/win32/pandora_strutils.cc @@ -119,6 +119,25 @@ Pandora_Strutils::strtoint (const string str) { return result; } +/** + * Returns the double precision floating-point value of a given string. + * + * @param str The string. + * + * @return The double precision floating-point value of the string. + * + * @exception Invalid_Conversion thrown on error. + */ +double +Pandora_Strutils::strtodouble (const string str) { + double result; + + if (! std::sscanf (str.c_str (), "%le", &result)) { + throw Invalid_Conversion (); + } + return result; +} + /** * Tranform a string into a long integer. * diff --git a/pandora_agents/win32/pandora_strutils.h b/pandora_agents/win32/pandora_strutils.h index 1ef5fe0454..5ccc0a7fb8 100644 --- a/pandora_agents/win32/pandora_strutils.h +++ b/pandora_agents/win32/pandora_strutils.h @@ -48,6 +48,7 @@ namespace Pandora_Strutils { string longtohex (const long i); int strtoint (const string str); + double strtodouble (const string str); unsigned long long strtoulong (const string str); string strreplace (string in, string pattern, string rep);