mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
SF:# 3522084 : AbstractConfiguration does not support 64-bit integers
This commit is contained in:
parent
484510dec5
commit
7eb7176397
@ -10,7 +10,8 @@ Release 1.5.0 (2012-07-04)
|
||||
- added PRoGen
|
||||
- added FIFOBuffer
|
||||
- fixed SF# 3522906: Unregistering handlers from SocketReactor
|
||||
|
||||
- fixed SF# 3522084: AbstractConfiguration does not support 64-bit integers
|
||||
|
||||
Release 1.4.4 (2012-04-??)
|
||||
==========================
|
||||
|
||||
|
@ -182,6 +182,28 @@ public:
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
Int64 getInt64(const std::string& key) const;
|
||||
/// Returns the Int64 value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an Int64.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
Int64 getInt64(const std::string& key, Int64 defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's Int64 value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an Int64.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
double getDouble(const std::string& key) const;
|
||||
/// Returns the double value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
@ -226,6 +248,14 @@ public:
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
void setInt64(const std::string& key, Int64 value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
void setDouble(const std::string& key, double value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
@ -160,6 +160,32 @@ int AbstractConfiguration::getInt(const std::string& key, int defaultValue) cons
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
Int64 AbstractConfiguration::getInt64(const std::string& key) const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string value;
|
||||
if (getRaw(key, value))
|
||||
return NumberParser::parse64(internalExpand(value));
|
||||
else
|
||||
throw NotFoundException(key);
|
||||
}
|
||||
|
||||
|
||||
Int64 AbstractConfiguration::getInt64(const std::string& key, Int64 defaultValue) const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string value;
|
||||
if (getRaw(key, value))
|
||||
return NumberParser::tryParse64(internalExpand(value), defaultValue);
|
||||
}
|
||||
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
|
||||
double AbstractConfiguration::getDouble(const std::string& key) const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
@ -220,6 +246,17 @@ void AbstractConfiguration::setInt(const std::string& key, int value)
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
void AbstractConfiguration::setInt64(const std::string& key, Int64 value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
setRaw(key, NumberFormatter::format(value));
|
||||
}
|
||||
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
void AbstractConfiguration::setDouble(const std::string& key, double value)
|
||||
{
|
||||
setRawWithEvent(key, NumberFormatter::format(value));
|
||||
|
@ -118,6 +118,31 @@ void AbstractConfigurationTest::testGetInt()
|
||||
}
|
||||
|
||||
|
||||
void AbstractConfigurationTest::testGetInt64()
|
||||
{
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
|
||||
|
||||
assert (pConf->getInt64("prop4.bigint1") == 420000000000L);
|
||||
assert (pConf->getInt64("prop4.bigint2") == -420000000000L);
|
||||
assert (pConf->getInt64("ref2") == 42);
|
||||
|
||||
try
|
||||
{
|
||||
int x = pConf->getInt64("prop1");
|
||||
x=x;
|
||||
fail("not a number - must throw");
|
||||
}
|
||||
catch (Poco::SyntaxException&)
|
||||
{
|
||||
}
|
||||
|
||||
assert (pConf->getInt64("prop4.bigint1", 100) == 420000000000L);
|
||||
assert (pConf->getInt64("prop4.bigint2", 100) == -420000000000L);
|
||||
#endif //defined(POCO_HAVE_INT64)
|
||||
}
|
||||
|
||||
|
||||
void AbstractConfigurationTest::testGetDouble()
|
||||
{
|
||||
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
|
||||
@ -220,6 +245,19 @@ void AbstractConfigurationTest::testSetInt()
|
||||
}
|
||||
|
||||
|
||||
void AbstractConfigurationTest::testSetInt64()
|
||||
{
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
|
||||
|
||||
pConf->setInt64("set.bigint1", 440000000000L);
|
||||
pConf->setInt64("set.bigint2", -440000000000L);
|
||||
assert (pConf->getInt64("set.int1") == 440000000000L);
|
||||
assert (pConf->getInt64("set.int2") == -440000000000L);
|
||||
#endif //defined(POCO_HAVE_INT64)
|
||||
}
|
||||
|
||||
|
||||
void AbstractConfigurationTest::testSetDouble()
|
||||
{
|
||||
AutoPtr<AbstractConfiguration> pConf = createConfiguration();
|
||||
@ -371,6 +409,8 @@ Poco::AutoPtr<AbstractConfiguration> AbstractConfigurationTest::createConfigurat
|
||||
pConfig->setString("prop3.string2", "bar");
|
||||
pConfig->setString("prop4.int1", "42");
|
||||
pConfig->setString("prop4.int2", "-42");
|
||||
pConfig->setString("prop4.bigint1", "420000000000");
|
||||
pConfig->setString("prop4.bigint2", "-420000000000");
|
||||
pConfig->setString("prop4.hex", "0x1f");
|
||||
pConfig->setString("prop4.double1", "1");
|
||||
pConfig->setString("prop4.double2", "-1.5");
|
||||
|
@ -51,11 +51,13 @@ public:
|
||||
void testHasProperty();
|
||||
void testGetString();
|
||||
void testGetInt();
|
||||
void testGetInt64();
|
||||
void testGetDouble();
|
||||
void testGetBool();
|
||||
void testExpand();
|
||||
void testSetString();
|
||||
void testSetInt();
|
||||
void testSetInt64();
|
||||
void testSetDouble();
|
||||
void testSetBool();
|
||||
void testKeys();
|
||||
|
Loading…
Reference in New Issue
Block a user