2008-06-11 Ramon Novoa <rnovoa@artica.es>

* win32/pandora_strutils.cc, win32/pandora_strutils.h,
          win32/modules/pandora_module.cc: Added support for floating-point
          numbers




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@852 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2008-06-11 10:10:48 +00:00
parent 08c15a1c25
commit de8d4afe35
4 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2008-06-11 Ramon Novoa <rnovoa@artica.es>
* win32/pandora_strutils.cc, win32/pandora_strutils.h,
win32/modules/pandora_module.cc: Added support for floating-point
numbers.
2008-06-11 Ramon Novoa <rnovoa@artica.es>
* win32/bin/pandora_agent.conf: Added remote_config option.

View File

@ -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 ();
}
/**

View File

@ -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.
*

View File

@ -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);