mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-19 11:28:24 -04:00
added isNull() method to rsid to allow checking for meaningless ids. Consequenctly the null id 000... is implicitly not an id.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7083 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
235280399f
commit
731d28bd41
1 changed files with 13 additions and 19 deletions
|
@ -37,7 +37,10 @@
|
||||||
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> class t_RsGenericIdType
|
template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> class t_RsGenericIdType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
t_RsGenericIdType() { memset(bytes,0,ID_SIZE_IN_BYTES) ;}
|
t_RsGenericIdType()
|
||||||
|
{
|
||||||
|
memset(bytes,0,ID_SIZE_IN_BYTES) ; // by default, ids are set to null()
|
||||||
|
}
|
||||||
virtual ~t_RsGenericIdType() {}
|
virtual ~t_RsGenericIdType() {}
|
||||||
|
|
||||||
// Explicit constructor from a hexadecimal string
|
// Explicit constructor from a hexadecimal string
|
||||||
|
@ -66,26 +69,17 @@ template<uint32_t ID_SIZE_IN_BYTES,uint32_t UNIQUE_IDENTIFIER> class t_RsGeneric
|
||||||
const unsigned char *toByteArray() const { return &bytes[0] ; }
|
const unsigned char *toByteArray() const { return &bytes[0] ; }
|
||||||
static const uint32_t SIZE_IN_BYTES = ID_SIZE_IN_BYTES ;
|
static const uint32_t SIZE_IN_BYTES = ID_SIZE_IN_BYTES ;
|
||||||
|
|
||||||
bool operator==(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const
|
inline bool operator==(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return !memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) ; }
|
||||||
{
|
inline bool operator!=(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return !!memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES); }
|
||||||
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
|
inline bool operator< (const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const { return (memcmp(bytes,fp.bytes,ID_SIZE_IN_BYTES) < 0) ; }
|
||||||
if(fp.bytes[i] != bytes[i])
|
|
||||||
|
inline bool isNull() const
|
||||||
|
{
|
||||||
|
for(int i=0;i<SIZE_IN_BYTES;++i)
|
||||||
|
if(bytes[i] != 0)
|
||||||
return false ;
|
return false ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
bool operator!=(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const
|
|
||||||
{
|
|
||||||
return !operator==(fp) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const t_RsGenericIdType<ID_SIZE_IN_BYTES,UNIQUE_IDENTIFIER>& fp) const
|
|
||||||
{
|
|
||||||
for(uint32_t i=0;i<ID_SIZE_IN_BYTES;++i)
|
|
||||||
if(fp.bytes[i] != bytes[i])
|
|
||||||
return (bytes[i] < fp.bytes[i]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char bytes[ID_SIZE_IN_BYTES] ;
|
unsigned char bytes[ID_SIZE_IN_BYTES] ;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue