Changeset 9684 for source/ariba/utility/types/LinkID.cpp
- Timestamp:
- Mar 22, 2011, 4:05:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/types/LinkID.cpp
r3690 r9684 39 39 #include "LinkID.h" 40 40 41 #include <boost/unordered_map.hpp> 42 41 43 namespace ariba { 42 44 namespace utility { 43 45 44 const LinkID LinkID::UNSPECIFIED; // for this link isvalid is always false! 46 /// the unspecified link id 47 const LinkID LinkID::UNSPECIFIED; 45 48 46 LinkID::LinkID() : isvalid(false) { 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; 47 57 } 48 58 49 LinkID::LinkID(const Identifier& identifier) : Identifier(identifier), isvalid(true) { 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; 50 68 } 51 69 52 LinkID::~LinkID() { 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); 53 79 } 54 80 55 LinkID::LinkID(const LinkID& rh) : Identifier(rh) { 81 /// free a locally unique link id 82 void LinkID::destroy( const LinkID& id ) { 83 link_ids.erase(id.local_id); 56 84 } 57 85 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() ); 86 std::ostream& operator<<(std::ostream& s, const LinkID& id ) { 87 return s << id.toString(); 72 88 } 73 89
Note:
See TracChangeset
for help on using the changeset viewer.