diff options
Diffstat (limited to 'cpp/src/IceGrid/DescriptorHelper.cpp')
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/cpp/src/IceGrid/DescriptorHelper.cpp b/cpp/src/IceGrid/DescriptorHelper.cpp index bf82a95a24c..ae35ff622b6 100644 --- a/cpp/src/IceGrid/DescriptorHelper.cpp +++ b/cpp/src/IceGrid/DescriptorHelper.cpp @@ -353,8 +353,13 @@ Resolver::asInt(const string& value, const string& name) const string v = operator()(value, name); if(!v.empty()) { + string::size_type beg = v.find_first_not_of(' '); + string::size_type end = v.find_last_not_of(' '); + v = v.substr(beg == string::npos ? 0 : beg, end == string::npos ? v.length() - 1 : end - beg + 1); + int val; - if(!(istringstream(v) >> val)) + istringstream is(v); + if(!(is >> val) || !is.eof()) { DeploymentException ex; ex.reason = "invalid value `" + value + "' for `" + name + "' in " + _context + ": not an integer"; @@ -364,6 +369,29 @@ Resolver::asInt(const string& value, const string& name) const return v; } +string +Resolver::asFloat(const string& value, const string& name) const +{ + string v = operator()(value, name); + if(!v.empty()) + { + string::size_type beg = v.find_first_not_of(' '); + string::size_type end = v.find_last_not_of(' '); + v = v.substr(beg == string::npos ? 0 : beg, end == string::npos ? v.length() - 1 : end - beg + 1); + + float val; + istringstream is(v); + if(!(is >> val) || !is.eof()) + { + DeploymentException ex; + ex.reason = "invalid value `" + value + "' for `" + name + "' in " + _context + ": not a float"; + throw ex; + } + cerr << v << " " << val << endl; + } + return v; +} + void Resolver::setReserved(const string& name, const string& value) { @@ -1488,7 +1516,7 @@ NodeHelper::instantiate(const Resolver& resolve) const { NodeDescriptor desc; desc.variables = _definition.variables; - desc.loadFactor = resolve(_definition.loadFactor, "load factor"); + desc.loadFactor = resolve.asFloat(_definition.loadFactor, "load factor"); desc.description = resolve(_definition.description, "description"); ServerInstanceHelperDict::const_iterator r; for(r = _serverInstances.begin(); r != _serverInstances.end(); ++r) |