election.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 71 行
CPP
71 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
/*
* Copyright (C) 2006 Paul Fitzpatrick
* CopyPolicy: Released under the terms of the GNU GPL v2.0.
*
*/
#include <yarp/Election.h>
#include <yarp/Logger.h>
using namespace yarp;
Election::Election() {
ct = 0;
}
Election::~Election() {
}
Election::PeerRecord *Election::getRecord(const String& key, bool create) {
ACE_Hash_Map_Entry<String,Election::PeerRecord> *entry = NULL;
int result = nameMap.find(key,entry);
if (result==-1 && create) {
nameMap.bind(key,Election::PeerRecord());
result = nameMap.find(key,entry);
}
if (result==-1) {
return NULL;
}
return &(entry->int_id_);
}
void Election::add(const String& key, void *entity) {
ct++;
PeerRecord *rec = getRecord(key,true);
YARP_ASSERT(rec!=NULL);
rec->add(entity);
}
void Election::remove(const String& key, void *entity) {
ct++;
PeerRecord *rec = getRecord(key,false);
YARP_ASSERT(rec!=NULL);
rec->remove(entity);
if (rec->getFirst()==NULL) {
//nameMap.unbind(key); // ACE wants a lot before this can happen
}
}
void *Election::getElect(const String& key) {
PeerRecord *rec = getRecord(key,false);
if (rec!=NULL) {
return rec->getFirst();
}
return NULL;
}
long Election::getEventCount() {
return ct;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?