Changeset 9695 for source/ariba/utility/types/LinkID.cpp
- Timestamp:
- Mar 24, 2011, 10:40:14 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/types/LinkID.cpp
r9684 r9695 39 39 #include "LinkID.h" 40 40 41 #include <boost/unordered_map.hpp>42 43 41 namespace ariba { 44 42 namespace utility { 45 43 46 /// the unspecified link id 47 const LinkID LinkID::UNSPECIFIED; 44 const LinkID LinkID::UNSPECIFIED; // for this link isvalid is always false! 48 45 49 const char* UNSPECIFIED_LINK = "<LINKID-UNSPECIFIED>"; 50 const char* UNKNOWN_LINK = "<LINKID-UNKNOWN>"; 51 const char* NULL_INFO = "<NO-INFO-AVAILABLE>"; 52 53 boost::unordered_map<uint16_t, const char*> link_ids; 54 55 bool LinkID::isValid( const LinkID& id ) { 56 return link_ids.count(id.local_id)!=0; 46 LinkID::LinkID() : isvalid(false) { 57 47 } 58 48 59 const char* LinkID::getInfo( const LinkID& id ) { 60 if (!id.valid()) 61 return UNSPECIFIED_LINK; 62 if ( link_ids.count(id.local_id) == 0 ) 63 return UNKNOWN_LINK; 64 const char* info = link_ids.find( id.local_id )->second; 65 if (info == NULL) 66 return NULL_INFO; 67 return info; 49 LinkID::LinkID(const Identifier& identifier) : Identifier(identifier), isvalid(true) { 68 50 } 69 51 70 /// create a new locally unique link id 71 LinkID LinkID::create( const char* info ) { 72 assert( link_ids.size() != 0xFFFE ); 73 uint16_t id; 74 do { 75 id = rand() & 0xFFFF; 76 } while (id == 0 || link_ids.count(id) != 0); 77 link_ids.insert( std::make_pair(id, info) ); 78 return LinkID(id); 52 LinkID::~LinkID() { 79 53 } 80 54 81 /// free a locally unique link id 82 void LinkID::destroy( const LinkID& id ) { 83 link_ids.erase(id.local_id); 55 LinkID::LinkID(const LinkID& rh) : Identifier(rh) { 84 56 } 85 57 86 std::ostream& operator<<(std::ostream& s, const LinkID& id ) { 87 return s << id.toString(); 58 LinkID& LinkID::operator=(const LinkID& rh){ 59 60 Identifier::operator=( rh ); 61 this->isvalid = rh.isvalid; 62 63 return *this; 64 } 65 66 bool LinkID::valid(){ 67 return isvalid; 68 } 69 70 LinkID LinkID::create() { 71 return LinkID( Identifier::random() ); 88 72 } 89 73
Note:
See TracChangeset
for help on using the changeset viewer.