From d4aca4b759b1bcd86359e65b611fe860af69262b Mon Sep 17 00:00:00 2001 From: fgerlits Date: Thu, 24 Mar 2005 11:08:55 +0000 Subject: [PATCH] added toDecimalString() method to the UniqueId class --- .../core/include/LiveSupport/Core/UniqueId.h | 19 +++++++++++++++++-- livesupport/modules/core/src/UniqueIdTest.cxx | 12 +++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h b/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h index 64909a2c2..6b1642a42 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h +++ b/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h,v $ ------------------------------------------------------------------------------*/ @@ -60,7 +60,7 @@ namespace Core { * A class representing globally unique identifiers. * * @author $Author: fgerlits $ - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ class UniqueId { @@ -142,6 +142,21 @@ class UniqueId return uid; } + /** + * Return the UniqueId as a string in base 10. + * + * @return a new string containing the value of the UniqueId. + */ + Ptr::Ref + toDecimalString(void) throw () + { + std::stringstream idWriter; + idWriter << std::dec << id; + Ptr::Ref idString(new std::string( + idWriter.str() )); + return idString; + } + /** * Compare this is with an other one. * diff --git a/livesupport/modules/core/src/UniqueIdTest.cxx b/livesupport/modules/core/src/UniqueIdTest.cxx index bddfef1f0..5b69e2e67 100644 --- a/livesupport/modules/core/src/UniqueIdTest.cxx +++ b/livesupport/modules/core/src/UniqueIdTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/UniqueIdTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -114,16 +114,22 @@ UniqueIdTest :: firstTest(void) std::string idAsVeryLongString = "123456789abcdef0123456789abcdef0"; id.reset(new UniqueId(idAsVeryLongString)); CPPUNIT_ASSERT(std::string(*id) == idAsVeryLongString); -// std::cout << std::endl << std::hex << UniqueId::IdType(*id) << std::endl; + std::string idAsSillyString = "this is not a number"; id.reset(new UniqueId(idAsSillyString)); CPPUNIT_ASSERT(std::string(*id) == idAsSillyString); -// std::cout << std::hex << UniqueId::IdType(*id) << std::endl; /* // this works fine, but please don't use UniqueId::IdType idSillyNumeric = -3; id.reset(new UniqueId(idSillyNumeric)); CPPUNIT_ASSERT(UniqueId::IdType(*id) == idSillyNumeric); CPPUNIT_ASSERT(std::string(*id) == "fffffffffffffffd"); */ + + // this is used in Postgresql classes, because Long does not get properly + // typedef'd to long long -- can be removed after this bug is fixed + std::string idAsDecimalString = "65546"; + id = UniqueId::fromDecimalString(idAsDecimalString); + CPPUNIT_ASSERT(id->getId() == 65546); + CPPUNIT_ASSERT(*id->toDecimalString() == idAsDecimalString); }