Ignore:
Timestamp:
Mar 22, 2011, 4:05:57 PM (13 years ago)
Author:
mies
Message:

almost forgot to commit: doxygen modules :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/types/LinkID.cpp

    r3690 r9684  
    3939#include "LinkID.h"
    4040
     41#include <boost/unordered_map.hpp>
     42
    4143namespace ariba {
    4244namespace utility {
    4345
    44 const LinkID LinkID::UNSPECIFIED; // for this link isvalid is always false!
     46/// the unspecified link id
     47const LinkID LinkID::UNSPECIFIED;
    4548
    46 LinkID::LinkID() : isvalid(false) {
     49const char* UNSPECIFIED_LINK    = "<LINKID-UNSPECIFIED>";
     50const char* UNKNOWN_LINK                = "<LINKID-UNKNOWN>";
     51const char* NULL_INFO                   = "<NO-INFO-AVAILABLE>";
     52
     53boost::unordered_map<uint16_t, const char*> link_ids;
     54
     55bool LinkID::isValid( const LinkID& id ) {
     56        return link_ids.count(id.local_id)!=0;
    4757}
    4858
    49 LinkID::LinkID(const Identifier& identifier) : Identifier(identifier), isvalid(true) {
     59const 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;
    5068}
    5169
    52 LinkID::~LinkID() {
     70/// create a new locally unique link id
     71LinkID 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);
    5379}
    5480
    55 LinkID::LinkID(const LinkID& rh) : Identifier(rh) {
     81/// free a locally unique link id
     82void LinkID::destroy( const LinkID& id ) {
     83        link_ids.erase(id.local_id);
    5684}
    5785
    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() );
     86std::ostream& operator<<(std::ostream& s, const LinkID& id ) {
     87        return s << id.toString();
    7288}
    7389
Note: See TracChangeset for help on using the changeset viewer.