added toDecimalString() method to the UniqueId class
This commit is contained in:
parent
b80950568d
commit
d4aca4b759
2 changed files with 26 additions and 5 deletions
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
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 $
|
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.
|
* A class representing globally unique identifiers.
|
||||||
*
|
*
|
||||||
* @author $Author: fgerlits $
|
* @author $Author: fgerlits $
|
||||||
* @version $Revision: 1.7 $
|
* @version $Revision: 1.8 $
|
||||||
*/
|
*/
|
||||||
class UniqueId
|
class UniqueId
|
||||||
{
|
{
|
||||||
|
@ -142,6 +142,21 @@ class UniqueId
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the UniqueId as a string in base 10.
|
||||||
|
*
|
||||||
|
* @return a new string containing the value of the UniqueId.
|
||||||
|
*/
|
||||||
|
Ptr<std::string>::Ref
|
||||||
|
toDecimalString(void) throw ()
|
||||||
|
{
|
||||||
|
std::stringstream idWriter;
|
||||||
|
idWriter << std::dec << id;
|
||||||
|
Ptr<std::string>::Ref idString(new std::string(
|
||||||
|
idWriter.str() ));
|
||||||
|
return idString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare this is with an other one.
|
* Compare this is with an other one.
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
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 $
|
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";
|
std::string idAsVeryLongString = "123456789abcdef0123456789abcdef0";
|
||||||
id.reset(new UniqueId(idAsVeryLongString));
|
id.reset(new UniqueId(idAsVeryLongString));
|
||||||
CPPUNIT_ASSERT(std::string(*id) == 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";
|
std::string idAsSillyString = "this is not a number";
|
||||||
id.reset(new UniqueId(idAsSillyString));
|
id.reset(new UniqueId(idAsSillyString));
|
||||||
CPPUNIT_ASSERT(std::string(*id) == idAsSillyString);
|
CPPUNIT_ASSERT(std::string(*id) == idAsSillyString);
|
||||||
// std::cout << std::hex << UniqueId::IdType(*id) << std::endl;
|
|
||||||
|
|
||||||
/* // this works fine, but please don't use
|
/* // this works fine, but please don't use
|
||||||
UniqueId::IdType idSillyNumeric = -3;
|
UniqueId::IdType idSillyNumeric = -3;
|
||||||
id.reset(new UniqueId(idSillyNumeric));
|
id.reset(new UniqueId(idSillyNumeric));
|
||||||
CPPUNIT_ASSERT(UniqueId::IdType(*id) == idSillyNumeric);
|
CPPUNIT_ASSERT(UniqueId::IdType(*id) == idSillyNumeric);
|
||||||
CPPUNIT_ASSERT(std::string(*id) == "fffffffffffffffd"); */
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue