本文整理汇总了C++中Simulator::addObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Simulator::addObject方法的具体用法?C++ Simulator::addObject怎么用?C++ Simulator::addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simulator
的用法示例。
在下文中一共展示了Simulator::addObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
Simulator sim;
SimplePhyChannel pch;
BaseStation::MODE mode = BaseStation::VAR_DYNAMIC;
bool variableRate = true;
bool dynamicCode = true;
for (int i = 1; i < argc; ++ i)
{
if ((0 == stricmp("-f", argv[i])) || (0 == stricmp("--fixed-rate", argv[i])))
{
variableRate = false;
if (dynamicCode)
{
mode = BaseStation::FIXED_DYNAMIC;
}
else
{
mode = BaseStation::FIXED_ONCE;
}
}
else if ((0 == stricmp("-o", argv[i])) || (0 == stricmp("--once-code", argv[i])))
{
dynamicCode = false;
if (variableRate)
{
mode = BaseStation::VAR_ONCE;
}
else
{
mode = BaseStation::FIXED_ONCE;
}
}
}
BaseStation bs(string("BaseStation"), pch, mode);
sim.addObject(&bs);
const int testRate = pch.getChipRate() / 8;
#if TEST_DEFAULT
AutoMobileStation ms(string("MobileStation"), pch, UID_1);
ms.setRateRange(testRate, testRate);
sim.addObject(&ms);
AutoMobileStation ms2(string("MobileStation"), pch, UID_2, false, MOBILE2_JOIN_TIME);
ms2.setRateRange(testRate, testRate);
sim.addObject(&ms2);
#if TEST_CODE_RANGE
// Fix MS data rate if TEST_CODE_RANGE is not set
ms.setRateRange(testRate, testRate);
ms2.setRateRange(testRate, testRate);
#endif
#else // Add user from stdin by test file
addUser(sim, pch);
#endif
sim.addObject(&pch);
Timer timer;
sim.addObject(&timer);
sim.run(shouldStop, &bs);
cout << "Time: " << timer.getTime() << endl;
return 0;
}
示例2: addUser
void addUser(Simulator& sim, SimplePhyChannel& pch)
{
char status;
char line[1024];
// Read until EOF
// States of input
enum { PARSE_TICK_DELAY, PARSE_UID, PARSE_TR, PARSER_DATA_RATE };
uint8_t state = PARSE_TICK_DELAY;
int tickDelay;
int uid;
int tr;
int dataRate;
while ((status = getLine(line, sizeof(line))) && (EOF != status))
{
char* data = line;
if (PARSE_TICK_DELAY == state)
{
data = getNumber(data, &tickDelay);
if (NULL != data)
{
state = PARSE_UID;
}
else
{
continue;
}
}
if (PARSE_UID == state)
{
data = getNumber(data, &uid);
if (NULL != data)
{
state = PARSE_TR;
}
else
{
continue;
}
}
if (PARSE_TR == state)
{
data = getNumber(data, &tr);
if (NULL != data)
{
state = PARSER_DATA_RATE;
}
else
{
continue;
}
}
if (PARSER_DATA_RATE == state)
{
data = getNumber(data, &dataRate);
if (NULL != data)
{
state = PARSE_TICK_DELAY;
string name = "MobileStation";
cout << "Adding " << name << uid << endl;
// TODO: where do we clean this memory
AutoMobileStation* ms = new AutoMobileStation(name, pch, uid, tr ? true: false, tickDelay);
++s_totalConnections;
cout << "s_totalConnections: " << s_totalConnections << endl;
ms->setRateRange(dataRate, dataRate);
sim.addObject(ms);
}
else
{
continue;
}
}
}
}