本文整理汇总了C++中CID类的典型用法代码示例。如果您正苦于以下问题:C++ CID类的具体用法?C++ CID怎么用?C++ CID使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSimpleRootPDUToOutputStream
/**
* Check that writing an Root PDU to an output stream works
*/
void RootPDUTest::testSimpleRootPDUToOutputStream() {
CID cid = CID::Generate();
RootPDU pdu1(TEST_VECTOR, cid, NULL);
OLA_ASSERT(cid == pdu1.Cid());
OLA_ASSERT_EQ(16u, pdu1.HeaderSize());
OLA_ASSERT_EQ(4u, pdu1.VectorSize());
OLA_ASSERT_EQ(0u, pdu1.DataSize());
OLA_ASSERT_EQ(22u, pdu1.Size());
IOQueue output;
OutputStream stream(&output);
pdu1.Write(&stream);
OLA_ASSERT_EQ(22u, output.Size());
uint8_t *raw_pdu = new uint8_t[output.Size()];
unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
OLA_ASSERT_EQ(output.Size(), raw_pdu_size);
uint8_t EXPECTED[] = {
0x70, 22,
0, 0, 0, 4,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
cid.Pack(EXPECTED + 6);
ASSERT_DATA_EQUALS(__LINE__,
EXPECTED, sizeof(EXPECTED),
raw_pdu, raw_pdu_size);
output.Pop(output.Size());
delete[] raw_pdu;
}
示例2: testToString
/*
* Check that ToString works.
*/
void CIDTest::testToString() {
CID cid = CID::FromData(TEST_DATA);
string cid_str = cid.ToString();
transform(cid_str.begin(), cid_str.end(), cid_str.begin(), toupper);
OLA_ASSERT_EQ(string("00010203-0405-0607-0809-0A0B0C0D0E0F"),
cid_str);
}
示例3: CID
/*
* Generates UDP key for specified IP address
*/
CID Utils::getUdpKey(const string& targetIp)
{
CID myUdpKey = CID(SETTING(DHT_KEY));
TigerTree th;
th.update(myUdpKey.data(), sizeof(CID));
th.update(targetIp.c_str(), targetIp.size());
return CID(th.finalize());
}
示例4: transform
/*
* Check that from string works.
*/
void CIDTest::testFromString() {
const string uuid = "00010203-0405-0607-0809-0A0B0C0D0E0F";
CID cid = CID::FromString(uuid);
string cid_str = cid.ToString();
transform(cid_str.begin(), cid_str.end(), cid_str.begin(), toupper);
OLA_ASSERT_EQ(uuid, cid_str);
const string bad_uuid = "foo";
cid = CID::FromString(bad_uuid);
OLA_ASSERT(cid.IsNil());
}
示例5: testToOutputBuffer
/**
* Check writing to an OutputBuffer works.
*/
void CIDTest::testToOutputBuffer() {
ola::io::IOQueue output;
const string uuid = "00010203-0405-0607-0809-0A0B0C0D0E0F";
CID cid = CID::FromString(uuid);
cid.Write(&output);
OLA_ASSERT_EQ(16u, output.Size());
unsigned int size = output.Size();
uint8_t cid_data[size];
OLA_ASSERT_EQ(size, output.Read(cid_data, size));
ASSERT_DATA_EQUALS(__LINE__, TEST_DATA, sizeof(TEST_DATA),
cid_data, size);
}
示例6: OLA_ASSERT
/*
* Check that basic assignment & equality works
*/
void CIDTest::testCID() {
CID cid;
OLA_ASSERT(cid.IsNil());
CID cid1 = CID::Generate();
OLA_ASSERT_FALSE(cid1.IsNil());
CID cid2 = cid1;
OLA_ASSERT(cid2 == cid1);
OLA_ASSERT_FALSE(cid2.IsNil());
CID cid3;
cid3 = cid1;
OLA_ASSERT(cid3 == cid1);
OLA_ASSERT_FALSE(cid3.IsNil());
}
示例7: cid
UserPtr DirectoryListing::getUserFromFilename(const string& fileName)
{
// General file list name format: [username].[CID].[xml|xml.bz2]
string name = Util::getFileName(fileName);
string ext = Text::toLower(Util::getFileExt(name));
if (ext == ".dcls" || ext == ".dclst") // [+] IRainman dclst support
{
auto l_user = std::make_shared<User>(CID(), name, 0);
return l_user;
}
// Strip off any extensions
if (ext == ".bz2")
{
name.erase(name.length() - 4);
ext = Text::toLower(Util::getFileExt(name));
}
if (ext == ".xml")
{
name.erase(name.length() - 4);
}
// Find CID
string::size_type i = name.rfind('.');
if (i == string::npos)
{
return ClientManager::getUser(name, "Unknown Hub", 0);
}
size_t n = name.length() - (i + 1);
// CID's always 39 chars long...
if (n != 39)
{
return ClientManager::getUser(name, "Unknown Hub", 0);
}
const CID cid(name.substr(i + 1));
if (cid.isZero())
{
return ClientManager::getUser(name, "Unknown Hub", 0);
}
UserPtr u = ClientManager::createUser(cid, name.substr(0, i), 0);
return u;
}
示例8: getHeaderString
string AdcCommand::getHeaderString(const CID& cid) const {
dcassert(type == TYPE_UDP);
string tmp;
tmp += getType();
tmp += cmdChar;
tmp += ' ';
tmp += cid.toBase32();
return tmp;
}
示例9: AddService
ErrorCode ComponentManager::AddService( CID cid, ISupports *service )
{
TRACE_BEGIN( LOG_LVL_INFO );
ClassInfo *info = jh_new ClassInfo( cid, service );
LOG( "Adding cid %s, ISupports %p", cid.toString(), service );
service->AddRef();
mClasses.push_back( info );
return kNoError;
}
示例10: pdu1
/*
* Test that packing a RootPDU with nested data works
*/
void RootPDUTest::testNestedRootPDUToOutputStream() {
FakePDU pdu1(1);
FakePDU pdu2(42);
PDUBlock<PDU> block;
block.AddPDU(&pdu1);
block.AddPDU(&pdu2);
CID cid = CID::Generate();
RootPDU pdu(TEST_VECTOR, cid, &block);
OLA_ASSERT(cid == pdu.Cid());
OLA_ASSERT_EQ(30u, pdu.Size());
IOQueue output;
OutputStream stream(&output);
pdu.Write(&stream);
OLA_ASSERT_EQ(30u, output.Size());
uint8_t *raw_pdu = new uint8_t[output.Size()];
unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size());
OLA_ASSERT_EQ(output.Size(), raw_pdu_size);
uint8_t EXPECTED[] = {
0x70, 30,
0, 0, 0, 4,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
0, 0, 0, 42
};
cid.Pack(EXPECTED + 6);
ASSERT_DATA_EQUALS(__LINE__,
EXPECTED, sizeof(EXPECTED),
raw_pdu, raw_pdu_size);
output.Pop(output.Size());
delete[] raw_pdu;
}
示例11: getNicks
StringList ClientManager::getNicks(const CID& cid) const {
Lock l(cs);
StringSet nicks;
OnlinePairC op = onlineUsers.equal_range(cid);
for(OnlineIterC i = op.first; i != op.second; ++i) {
nicks.insert(i->second->getIdentity().getNick());
}
if(nicks.empty()) {
// Offline perhaps?
UserMap::const_iterator i = users.find(cid);
if(i != users.end() && !i->second->getFirstNick().empty()) {
nicks.insert(i->second->getFirstNick());
} else {
nicks.insert('{' + cid.toBase32() + '}');
}
}
return StringList(nicks.begin(), nicks.end());
}
示例12: TypeBase
CID::CID(CID const& other)
: TypeBase(other.GetNode())
{
}
示例13: UIntValidator
/*
* Load the plugin prefs and default to sensible values
*
*/
bool E131Plugin::SetDefaultPreferences() {
if (!m_preferences)
return false;
bool save = false;
CID cid = CID::FromString(m_preferences->GetValue(CID_KEY));
if (cid.IsNil()) {
cid = CID::Generate();
m_preferences->SetValue(CID_KEY, cid.ToString());
save = true;
}
save |= m_preferences->SetDefaultValue(
DSCP_KEY,
UIntValidator(0, 63),
DEFAULT_DSCP_VALUE);
save |= m_preferences->SetDefaultValue(
DRAFT_DISCOVERY_KEY,
BoolValidator(),
BoolValidator::DISABLED);
save |= m_preferences->SetDefaultValue(
IGNORE_PREVIEW_DATA_KEY,
BoolValidator(),
BoolValidator::ENABLED);
save |= m_preferences->SetDefaultValue(
INPUT_PORT_COUNT_KEY,
UIntValidator(0, 128),
DEFAULT_PORT_COUNT);
save |= m_preferences->SetDefaultValue(
OUTPUT_PORT_COUNT_KEY,
UIntValidator(0, 128),
DEFAULT_PORT_COUNT);
save |= m_preferences->SetDefaultValue(IP_KEY, StringValidator(true), "");
save |= m_preferences->SetDefaultValue(
PREPEND_HOSTNAME_KEY,
BoolValidator(),
BoolValidator::ENABLED);
std::set<string> revision_values;
revision_values.insert(REVISION_0_2);
revision_values.insert(REVISION_0_46);
save |= m_preferences->SetDefaultValue(
REVISION_KEY,
SetValidator<string>(revision_values),
REVISION_0_46);
if (save)
m_preferences->Save();
// check if this saved correctly
// we don't want to use it if null
string revision = m_preferences->GetValue(REVISION_KEY);
if (m_preferences->GetValue(CID_KEY).empty() ||
(revision != REVISION_0_2 && revision != REVISION_0_46))
return false;
return true;
}
示例14: OLA_ASSERT_FALSE
void CIDTest::testSetPack() {
uint8_t buffer[CID::CID_LENGTH];
CID cid = CID::FromData(TEST_DATA);
cid.Pack(buffer);
OLA_ASSERT_FALSE(memcmp(TEST_DATA, buffer, CID::CID_LENGTH));
}
示例15: getOfflineNick
string ClientManager::getOfflineNick(const CID& cid) const {
auto i = nicks.find(cid);
return i != nicks.end() ? i->second.first : '{' + cid.toBase32() + '}';
}