NLMISC::CEntityId Struct Reference

#include <entity_id.h>

Inheritance diagram for NLMISC::CEntityId:

NLAIAGENT::CAgentNumber NLAIAGENT::CIdent

Detailed Description

Entity identifier
Author:
Sameh Chafik, Vianney Lecroart

Nevrax France

Date:
2001

Definition at line 42 of file entity_id.h.

Public Types

enum  {
  DYNAMIC_ID_SIZE = 11, CREATOR_ID_SIZE = 8, TYPE_SIZE = 5, ID_SIZE = 40,
  UNKNOWN_TYPE = (1 << TYPE_SIZE)-1
}

Public Member Functions

uint64 asUint64 () const
void fromString (const char *str)
 Read from a debug string, use the same format as toString() (id:type:creator:dynamic) in hexadecimal.

uint8 getCreatorId () const
 Get the persistent creator id.

void getDebugString (std::string &str) const
 Have a debug string.

uint8 getDynamicId () const
 Get the variable routing info.

uint64 getRawId () const
 Get the full id.

uint64 getShortId () const
 Get the local entity number.

uint8 getType () const
 Get the entity type.

uint64 getUniqueId () const
 Get the persistent part of the entity id (the dynamic part in the returned id is 0).

bool isUnknownId () const
 Test if the entity id is Unknown.

void load (NLMISC::IStream &is)
 Load the number from an input stream.

const CEntityIdoperator++ (int)
const CEntityIdoperator= (uint64 p)
const CEntityIdoperator= (const CEntityId &a)
void save (NLMISC::IStream &os)
 Save the Id into an output stream.

void serial (NLMISC::IStream &f) throw (NLMISC::EStream)
void setCreatorId (uint8 creatorId)
 Set the persistent creator id.

void setDynamicId (uint8 dynId)
 Set the variable routing info.

void setShortId (uint64 shortId)
 Set the local entity number.

void setType (uint8 type)
 Set the entity type.

std::string toString () const
 return a string in form "(a:b:c:d)" where a,b,c,d are components of entity id.

Constructor
 CEntityId (const char *str)
 CEntityId (const std::string &str)
 CEntityId (NLMISC::IStream &is)
 fill from read stream.

 CEntityId (const CEntityId &a)
 CEntityId (uint64 p)
 CEntityId (uint8 type, uint64 id)
 CEntityId (uint8 type, uint64 id, uint8 creator, uint8 dynamic)
 CEntityId ()

Static Public Member Functions

CEntityId getNewEntityId (uint8 type)
 Generator of entity ids.

void setServiceId (uint8 sid)
 Set the service id for the generator.


Static Public Attributes

const uint64 MaxEntityId = ((uint64)1 << (CEntityId::ID_SIZE + 1)) - (uint64)1
 The maximume of number that we could generate without generate an overtaking exception.

const CEntityId Unknown
 Unknow CEntityId is similar as an NULL pointer.


Static Protected Attributes

NLMISC::CEntityId _NextEntityId
 Counter for generation of unique entity ids.

uint8 _ServerId = 0
 The local num service id of the local machin.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DYNAMIC_ID_SIZE 
CREATOR_ID_SIZE 
TYPE_SIZE 
ID_SIZE 
UNKNOWN_TYPE 

Definition at line 45 of file entity_id.h.

00046         {
00047                 DYNAMIC_ID_SIZE = 11,
00048                 CREATOR_ID_SIZE = 8,
00049                 TYPE_SIZE = 5,
00050                 ID_SIZE = 40,
00051                 UNKNOWN_TYPE = (1 << TYPE_SIZE)-1
00052         };


Constructor & Destructor Documentation

NLMISC::CEntityId::CEntityId  )  [inline]
 

Definition at line 123 of file entity_id.h.

References DetailedId, FullId, and UNKNOWN_TYPE.

Referenced by CEntityId().

00124         {
00125                 FullId = 0;
00126                 DetailedId.Type = UNKNOWN_TYPE;
00127 
00128                 /*
00129                 DynamicId = 0;
00130                 CreatorId = 0;
00131                 Type = 127;
00132                 Id = 0;
00133                 */
00134         }

NLMISC::CEntityId::CEntityId uint8  type,
uint64  id,
uint8  creator,
uint8  dynamic
[inline]
 

Definition at line 136 of file entity_id.h.

References DetailedId, type, uint64, and uint8.

00137         {
00138                 DetailedId.DynamicId = dynamic;
00139                 DetailedId.CreatorId = creator;
00140                 DetailedId.Type = type;
00141                 DetailedId.Id = id;
00142         }

NLMISC::CEntityId::CEntityId uint8  type,
uint64  id
[inline]
 

Definition at line 144 of file entity_id.h.

References _ServerId, DetailedId, type, uint64, and uint8.

00145         {
00146                 DetailedId.Type = type;
00147                 DetailedId.Id = id;
00148                 DetailedId.CreatorId = _ServerId;
00149                 DetailedId.DynamicId = _ServerId;
00150         }

NLMISC::CEntityId::CEntityId uint64  p  )  [inline, explicit]
 

Definition at line 152 of file entity_id.h.

References FullId, and uint64.

00153         {       
00154                 FullId = p;
00155                 /*
00156                 DynamicId = (p & 0xff);
00157                 p >>= 8;
00158                 CreatorId = (p & 0xff);
00159                 p >>= 8;
00160                 Type = (p & 0xff);
00161                 p >>= 8;
00162                 Id = (p);                       
00163                 */
00164         }

NLMISC::CEntityId::CEntityId const CEntityId a  )  [inline]
 

Definition at line 166 of file entity_id.h.

References FullId.

00167         {
00168                 FullId = a.FullId;
00169                 /*
00170                 DynamicId = a.DynamicId;
00171                 CreatorId = a.CreatorId;                        
00172                 Type = a.Type;
00173                 Id = a.Id;
00174                 */
00175         }

NLMISC::CEntityId::CEntityId NLMISC::IStream is  )  [inline]
 

fill from read stream.

Definition at line 178 of file entity_id.h.

References FullId, and NLMISC::IStream::serial().

00179         {
00180                 is.serial(FullId);
00181                 /*
00182                 uint64 p;
00183                 is.serial(p);
00184 
00185                 DynamicId = (p & 0xff);
00186                 p >>= 8;
00187                 CreatorId = (p & 0xff);
00188                 p >>= 8;
00189                 Type = (p & 0xff);
00190                 p >>= 8;
00191                 Id = p;
00192                 */
00193         }

NLMISC::CEntityId::CEntityId const std::string &  str  )  [inline, explicit]
 

Definition at line 195 of file entity_id.h.

References fromString().

00196         {
00197                 fromString(str.c_str());
00198         }

NLMISC::CEntityId::CEntityId const char *  str  )  [inline, explicit]
 

Definition at line 200 of file entity_id.h.

References CEntityId(), and fromString().

00201         {
00202                 CEntityId ();
00203                 fromString(str);
00204         }


Member Function Documentation

uint64 NLMISC::CEntityId::asUint64  )  const [inline]
 

Definition at line 401 of file entity_id.h.

References FullId, and uint64.

00402         {
00403                 return FullId;
00404         }

void NLMISC::CEntityId::fromString const char *  str  )  [inline]
 

Read from a debug string, use the same format as toString() (id:type:creator:dynamic) in hexadecimal.

Definition at line 488 of file entity_id.h.

References DetailedId, NL_I64, type, uint, and uint64.

Referenced by CEntityId(), and NLNET::createMessage().

00490         {
00491                 uint64          id;
00492                 uint            type;
00493                 uint            creatorId;
00494                 uint            dynamicId;
00495 
00496                 if (sscanf(str, "(%"NL_I64"x:%x:%x:%x)", &id, &type, &creatorId, &dynamicId) != 4)
00497                 {
00498                         *this = Unknown;
00499                         return;
00500                 }
00501 
00502                 DetailedId.Id = id;
00503                 DetailedId.Type = type;
00504                 DetailedId.CreatorId = creatorId;
00505                 DetailedId.DynamicId = dynamicId;
00506         }

uint8 NLMISC::CEntityId::getCreatorId  )  const [inline]
 

Get the persistent creator id.

Definition at line 245 of file entity_id.h.

References DetailedId, and uint8.

Referenced by NLAIAGENT::CAgentNumber::operator<().

00246         {
00247                 return DetailedId.CreatorId;
00248         }

void NLMISC::CEntityId::getDebugString std::string &  str  )  const [inline]
 

Have a debug string.

Reimplemented in NLAIAGENT::CIdent.

Definition at line 509 of file entity_id.h.

References DetailedId, sint, uint64, and x.

Referenced by NLAIAGENT::CNumericIndex::getDebugString(), NLAIAGENT::CProxyAgentMail::getDebugString(), and toString().

00511         {                                                                                       
00512                 char b[256];
00513                 memset(b,0,255);
00514                 memset(b,'0',19);
00515                 sint n;
00516 
00517                 uint64 x = DetailedId.Id;
00518                 char baseTable[] = "0123456789abcdef";
00519                 for(n = 10; n < 20; n ++)
00520                 {
00521                         b[19 - n] = baseTable[(x & 15)];
00522                         x >>= 4;
00523                 }
00524                 b[19 - 9] = ':';
00525 
00526                 x = DetailedId.Type;
00527                 for(n = 7; n < 9; n ++)
00528                 {                               
00529                         b[19 - n] = baseTable[(x & 15)];
00530                         x >>= 4;
00531                 }
00532                 b[19 - 6] = ':';
00533 
00534                 x = DetailedId.CreatorId;
00535                 for(n = 4; n < 6; n ++)
00536                 {                               
00537                         b[19 - n] = baseTable[(x & 15)];
00538                         x >>= 4;
00539                 }
00540                 b[19 - 3] = ':';
00541 
00542                 x = DetailedId.DynamicId;
00543                 for(n = 1; n < 3; n ++)
00544                 {                                                       
00545                         b[19 - n] = baseTable[(x & 15)];
00546                         x >>= 4;
00547                 }
00548                 str += "0x" + std::string(b);
00549         }

uint8 NLMISC::CEntityId::getDynamicId  )  const [inline]
 

Get the variable routing info.

Definition at line 233 of file entity_id.h.

References DetailedId, and uint8.

Referenced by NLAIAGENT::CAgentNumber::operator<().

00234         {
00235                 return DetailedId.DynamicId;
00236         }

CEntityId NLMISC::CEntityId::getNewEntityId uint8  type  )  [inline, static]
 

Generator of entity ids.

Definition at line 109 of file entity_id.h.

References _NextEntityId, nlassert, setType(), type, and uint8.

00110         {
00111                 nlassert(_NextEntityId != Unknown ); // type may be Unknown, so isUnknownId() would return true
00112                 NLMISC::CEntityId id = _NextEntityId++;
00113                 id.setType( type );
00114                 return id;
00115         }

uint64 NLMISC::CEntityId::getRawId  )  const [inline]
 

Get the full id.

Definition at line 212 of file entity_id.h.

References FullId, and uint64.

00213         {
00214                 return FullId;
00215                 /*
00216                 return (uint64)*this;
00217                 */
00218         }

uint64 NLMISC::CEntityId::getShortId  )  const [inline]
 

Get the local entity number.

Definition at line 221 of file entity_id.h.

References DetailedId, and uint64.

Referenced by NLAIAGENT::CAgentNumber::operator<().

00222         {
00223                 return DetailedId.Id;
00224         }

uint8 NLMISC::CEntityId::getType void   )  const [inline]
 

Get the entity type.

Definition at line 257 of file entity_id.h.

References DetailedId, and uint8.

Referenced by NLAIAGENT::IRefrence::IRefrence(), NLAIAGENT::CAgentNumber::isAgentId(), and NLAIAGENT::CAgentNumber::setTypeAt().

00258         {
00259                 return (uint8)DetailedId.Type;
00260         }

uint64 NLMISC::CEntityId::getUniqueId  )  const [inline]
 

Get the persistent part of the entity id (the dynamic part in the returned id is 0).

Definition at line 269 of file entity_id.h.

References FullId, and uint64.

Referenced by operator<(), and operator>().

00270         {
00271                 CEntityId id;
00272                 id.FullId = FullId;
00273                 id.DetailedId.DynamicId = 0;
00274                 return id.FullId;
00275         }

bool NLMISC::CEntityId::isUnknownId  )  const [inline]
 

Test if the entity id is Unknown.

Definition at line 278 of file entity_id.h.

References DetailedId, and UNKNOWN_TYPE.

00279         {
00280                 return DetailedId.Type == UNKNOWN_TYPE;
00281         }

void NLMISC::CEntityId::load NLMISC::IStream is  )  [inline]
 

Load the number from an input stream.

Reimplemented in NLAIAGENT::CIdent.

Definition at line 443 of file entity_id.h.

References FullId, and NLMISC::IStream::serial().

Referenced by NLAIAGENT::CNumericIndex::load(), and serial().

00445         {
00446                 is.serial(FullId);
00447                 /*
00448                 uint64 p;
00449                 is.serial(p);
00450 
00451                 DynamicId = (uint64)(p & 0xff);
00452                 p >>= 8;
00453                 CreatorId = (uint64)(p & 0xff);
00454                 p >>= 8;
00455                 Type = (uint64)(p & 0xff);
00456                 p >>= 8;
00457                 Id = (uint64)(p);
00458                 */
00459         }

bool NLMISC::CEntityId::operator!= const CEntityId a  )  const [inline]
 

Definition at line 301 of file entity_id.h.

00302         {
00303                 return !((*this) == a);
00304         }

const CEntityId& NLMISC::CEntityId::operator++ int   )  [inline]
 

Definition at line 358 of file entity_id.h.

References DetailedId, MaxEntityId, NL_I64, and nlerror.

00359         {
00360                 if(DetailedId.Id < MaxEntityId)
00361                 {
00362                         DetailedId.Id ++;
00363                 }
00364                 else
00365                 {
00366                         nlerror ("CEntityId looped (max was %"NL_I64"d", MaxEntityId);
00367                 }
00368                 return *this;
00369         }

bool NLMISC::CEntityId::operator< const CEntityId a  )  const [inline]
 

Definition at line 306 of file entity_id.h.

References getUniqueId().

00308         {
00309                 return getUniqueId() < a.getUniqueId();
00310 
00311                 /*
00312                 if (Type < a.Type)
00313                 {
00314                         return true;
00315                 }
00316                 else if (Type == a.Type)
00317                 {
00318                         if (Id < a.Id)
00319                         {
00320                                 return true;
00321                         }
00322                         else if (Id == a.Id)
00323                         {
00324                                 return (CreatorId < a.CreatorId);
00325                         }
00326                 }               
00327                 return false;
00328                 */
00329         }

const CEntityId& NLMISC::CEntityId::operator= uint64  p  )  [inline]
 

Definition at line 383 of file entity_id.h.

References FullId, and uint64.

00384         {                       
00385                 FullId = p;
00386                 /*
00387                 DynamicId = (uint64)(p & 0xff);
00388                 p >>= 8;
00389                 CreatorId = (uint64)(p & 0xff);
00390                 p >>= 8;
00391                 Type = (uint64)(p & 0xff);
00392                 p >>= 8;
00393                 Id = (uint64)(p);
00394                 */
00395                 return *this;
00396         }

const CEntityId& NLMISC::CEntityId::operator= const CEntityId a  )  [inline]
 

Definition at line 371 of file entity_id.h.

References FullId.

00372         {
00373                 FullId = a.FullId;
00374                 /*
00375                 DynamicId = a.DynamicId;
00376                 CreatorId = a.CreatorId;
00377                 Type = a.Type;
00378                 Id = a.Id;
00379                 */
00380                 return *this;
00381         }

bool NLMISC::CEntityId::operator== const CEntityId a  )  const [inline]
 

Definition at line 289 of file entity_id.h.

References DetailedId, and FullId.

00291         {
00292 
00293                 CEntityId testId ( FullId ^ a.FullId );
00294                 testId.DetailedId.DynamicId = 0;
00295                 return testId.FullId == 0;
00296 
00297                 /*
00298                 return (Id == a.DetailedId.Id && DetailedId.CreatorId == a.DetailedId.CreatorId && DetailedId.Type == a.DetailedId.Type);
00299                 */
00300         }

bool NLMISC::CEntityId::operator> const CEntityId a  )  const [inline]
 

Definition at line 331 of file entity_id.h.

References getUniqueId().

00333         {
00334                 return getUniqueId() > a.getUniqueId();
00335 
00336                 /*
00337                 if (Type > a.Type)
00338                 {
00339                         return true;
00340                 }
00341                 else if (Type == a.Type)
00342                 {
00343                         if (Id > a.Id)
00344                         {
00345                                 return true;
00346                         }
00347                         else if (Id == a.Id)
00348                         {
00349                                 return (CreatorId > a.CreatorId);
00350                         }
00351                 }
00352                 // lesser
00353                 return false;
00354                 */
00355         }

void NLMISC::CEntityId::save NLMISC::IStream os  )  [inline]
 

Save the Id into an output stream.

Reimplemented in NLAIAGENT::CIdent.

Definition at line 426 of file entity_id.h.

References FullId, and NLMISC::IStream::serial().

Referenced by NLAIAGENT::CNumericIndex::save(), NLAIAGENT::CProxyAgentMail::save(), and serial().

00428         {
00429                 os.serial(FullId);
00430                 /*
00431                 uint64 p = Id;
00432                 p <<= 8;
00433                 p |= (uint64)Type;
00434                 p <<= 8;
00435                 p |= (uint64)CreatorId;
00436                 p <<= 8;
00437                 p |= (uint64)DynamicId;
00438                 os.serial(p);
00439                 */
00440         }

void NLMISC::CEntityId::serial NLMISC::IStream f  )  throw (NLMISC::EStream) [inline]
 

Definition at line 462 of file entity_id.h.

References load(), and save().

00464         {
00465                 if (f.isReading ())
00466                 {
00467                         load (f);
00468                 }
00469                 else
00470                 {                               
00471                         save (f);
00472                 }
00473         }

void NLMISC::CEntityId::setCreatorId uint8  creatorId  )  [inline]
 

Set the persistent creator id.

Definition at line 251 of file entity_id.h.

References DetailedId, and uint8.

Referenced by NLMISC::CEntityIdTranslator::checkEntity(), NLLOGIC::CLogicEventMessage::CLogicEventMessage(), NLLOGIC::CLogicStateMachine::displayVariables(), NLMISC::CEntityIdTranslator::getByEntity(), NLMISC::CEntityIdTranslator::getEntityIdInfo(), NLMISC::CEntityIdTranslator::getEntityNameStringId(), NLMISC::CEntityIdTranslator::isEntityOnline(), NLMISC::NLMISC_COMMAND(), NLMISC::CEntityIdTranslator::registerEntity(), NLMISC::CEntityIdTranslator::setEntityOnline(), NLAILINK::setLocalServerID(), setServiceId(), and NLMISC::CEntityIdTranslator::unregisterEntity().

00252         {
00253                 DetailedId.CreatorId = creatorId;
00254         }

void NLMISC::CEntityId::setDynamicId uint8  dynId  )  [inline]
 

Set the variable routing info.

Definition at line 239 of file entity_id.h.

References DetailedId, and uint8.

Referenced by NLMISC::CEntityIdTranslator::checkEntity(), NLLOGIC::CLogicEventMessage::CLogicEventMessage(), NLLOGIC::CLogicStateMachine::displayVariables(), NLMISC::CEntityIdTranslator::getByEntity(), NLMISC::CEntityIdTranslator::getEntityIdInfo(), NLMISC::CEntityIdTranslator::getEntityNameStringId(), NLMISC::CEntityIdTranslator::isEntityOnline(), NLMISC::NLMISC_COMMAND(), NLMISC::CEntityIdTranslator::registerEntity(), NLMISC::CEntityIdTranslator::setEntityOnline(), NLAILINK::setLocalServerID(), setServiceId(), and NLMISC::CEntityIdTranslator::unregisterEntity().

00240         {
00241                 DetailedId.DynamicId = dynId;
00242         }

void NLMISC::CEntityId::setServiceId uint8  sid  )  [inline, static]
 

Set the service id for the generator.

Definition at line 101 of file entity_id.h.

References _NextEntityId, _ServerId, setCreatorId(), setDynamicId(), and uint8.

Referenced by NLNET::IService::main(), and NLAILINK::setLocalServerID().

00102         {
00103                 _NextEntityId.setDynamicId( sid );
00104                 _NextEntityId.setCreatorId( sid ); 
00105                 _ServerId = sid;
00106         }

void NLMISC::CEntityId::setShortId uint64  shortId  )  [inline]
 

Set the local entity number.

Definition at line 227 of file entity_id.h.

References DetailedId, and uint64.

00228         {
00229                 DetailedId.Id = shortId;
00230         }

void NLMISC::CEntityId::setType uint8  type  )  [inline]
 

Set the entity type.

Definition at line 263 of file entity_id.h.

References DetailedId, type, and uint8.

Referenced by NLAIAGENT::CAgentNumber::CAgentNumber(), NLLOGIC::CLogicEventMessage::CLogicEventMessage(), NLLOGIC::CLogicStateMachine::displayVariables(), getNewEntityId(), and NLAIAGENT::CAgentNumber::setTypeAt().

00264         {
00265                 DetailedId.Type = type;
00266         }

std::string NLMISC::CEntityId::toString  )  const [inline]
 

return a string in form "(a:b:c:d)" where a,b,c,d are components of entity id.

Definition at line 480 of file entity_id.h.

References getDebugString().

Referenced by NLMISC::CEntityIdTranslator::checkEntity(), NLMISC::CEntityIdTranslator::getEntityIdInfo(), NLMISC::CEntityIdTranslator::isEntityOnline(), NLMISC::NLMISC_COMMAND(), NLMISC::CEntityIdTranslator::registerEntity(), NLMISC::CEntityIdTranslator::setEntityOnline(), and NLMISC::CEntityIdTranslator::unregisterEntity().

00481         {
00482                 std::string id;
00483                 getDebugString (id);
00484                 return "(" + id + ")";
00485         }


Field Documentation

CEntityId NLMISC::CEntityId::_NextEntityId [static, protected]
 

Counter for generation of unique entity ids.

Definition at line 36 of file entity_id.cpp.

Referenced by getNewEntityId(), and setServiceId().

uint8 NLMISC::CEntityId::_ServerId = 0 [static, protected]
 

The local num service id of the local machin.

Definition at line 38 of file entity_id.cpp.

Referenced by CEntityId(), and setServiceId().

uint64 NLMISC::CEntityId::CreatorId [protected]
 

Id of the service who created the entity (persistent).

Definition at line 66 of file entity_id.h.

struct { ... } NLMISC::CEntityId::DetailedId [protected]
 

Referenced by CEntityId(), fromString(), getCreatorId(), getDebugString(), getDynamicId(), getShortId(), getType(), isUnknownId(), operator++(), operator==(), setCreatorId(), setDynamicId(), setShortId(), and setType().

uint64 NLMISC::CEntityId::DynamicId [protected]
 

Id of the service where the entity is (variable routing info).

Definition at line 64 of file entity_id.h.

uint64 NLMISC::CEntityId::FullId [protected]
 

Definition at line 73 of file entity_id.h.

Referenced by asUint64(), CEntityId(), getRawId(), getUniqueId(), load(), operator=(), operator==(), and save().

uint64 NLMISC::CEntityId::Id [protected]
 

Local entity number (persistent).

Definition at line 70 of file entity_id.h.

const uint64 NLMISC::CEntityId::MaxEntityId = ((uint64)1 << (CEntityId::ID_SIZE + 1)) - (uint64)1 [static]
 

The maximume of number that we could generate without generate an overtaking exception.

Definition at line 34 of file entity_id.cpp.

Referenced by operator++().

uint64 NLMISC::CEntityId::Type [protected]
 

Type of the entity (persistent).

Definition at line 68 of file entity_id.h.

const CEntityId NLMISC::CEntityId::Unknown [static]
 

Unknow CEntityId is similar as an NULL pointer.


The documentation for this struct was generated from the following files:
Generated on Tue Mar 16 13:07:54 2004 for NeL by doxygen 1.3.6