本文整理汇总了C++中TestData::clone方法的典型用法代码示例。如果您正苦于以下问题:C++ TestData::clone方法的具体用法?C++ TestData::clone怎么用?C++ TestData::clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestData
的用法示例。
在下文中一共展示了TestData::clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char* args[])
{
int mainSleep = 100;
int nrOfFloats = 500;
int sleepEveryNrPackets = 100000;
int sendSleepTime = 1;
if(argc > 3)
{
sscanf(args[1],"%i", &mainSleep);
sscanf(args[2],"%i", &nrOfFloats);
sscanf(args[3],"%i", &sleepEveryNrPackets);
sscanf(args[4],"%i", &sendSleepTime);
}
else
{
std::cout << "Ignoring arguments (must be > 3) arguments should be: " << "mainSleep, nrOfFloats, sleepEveryNrPackets, sendSleepTime." << std::endl;
}
using namespace TestAll;
using namespace ops;
std::vector<TestData*> bP;
bP.push_back(new TestData());
bP.clear();
ops::Participant* participant = Participant::getInstance("TestAllDomain");
participant->addTypeSupport(new TestAll::TestAllTypeFactory());
ErrorWriter* errorWriter = new ErrorWriter(std::cout);
participant->addListener(errorWriter);
//Create topic, might throw ops::NoSuchTopicException
Topic topic = participant->createTopic("ChildTopic");
//Create a publisher on that topic
ChildDataPublisher pub(topic);
pub.setName("TestAllPublisher");
pub.sendSleepTime = sendSleepTime;
pub.sleepEverySendPacket = sleepEveryNrPackets;
Topic baseTopic = participant->createTopic("BaseTopic");
BaseDataPublisher basePub(baseTopic);
basePub.setName("BasePublisher");
//Create some data to publish
ChildData data;
BaseData baseData;
baseData.baseText = "Text from base";
//Set Base class field
data.baseText = "Hello";
////Set aggregated object
TestData testData;
testData.text = "text in aggregated class";
testData.value = 3456.0;
data.test2 = testData;
data.testPointer = (TestData*)testData.clone();
//
//Set primitives
data.bo = true;
data.b = 1;
data.i = 0;
data.l = 3;
data.f = 4.0;
data.d = 5.0;
//data.s = "World";
data.s = "World";
//Set arrays (vectors)
data.bos.push_back(true);
data.bs.push_back(6);
//data.is.push_back(7);
data.ls.push_back(8);
//data.fs.push_back(9.0);
data.ds.push_back(10.0);
data.ss.push_back("Hello Array");
data.setKey("key1");
//return 0;
for(int i = 0; i < nrOfFloats; i++)
{
data.fs.push_back(i);
}
ChildData* dataClone = (ChildData*)data.clone();
//Publish the data peridically and make a small changes to the data.
while(true)
{
//.........这里部分代码省略.........
示例2: main
int main(int argc, const char* args[])
{
int mainSleep = 40;
int nrOfFloats = 500;
int sleepEveryNrPackets = 100000;
int sendSleepTime = 1;
if(argc > 3)
{
sscanf_s(args[1],"%i", &mainSleep);
sscanf_s(args[2],"%i", &nrOfFloats);
sscanf_s(args[3],"%i", &sleepEveryNrPackets);
sscanf_s(args[4],"%i", &sendSleepTime);
}
else
{
std::cout << "Ignoring arguments (must be > 3) arguments should be: " << "mainSleep, nrOfFloats, sleepEveryNrPackets, sendSleepTime." << std::endl;
}
timeBeginPeriod(1);
using namespace TestAll;
using namespace ops;
std::vector<TestData*> bP;
bP.push_back(new TestData());
bP.clear();
ops::Participant* participant = Participant::getInstance("TestAllDomain");
participant->addTypeSupport(new TestAll::TestAllTypeFactory());
ErrorWriter* errorWriter = new ErrorWriter(std::cout);
participant->addListener(errorWriter);
/*Sleep(2000);
ops::Sender* tcpServer = ops::Sender::createTCPServer("", 1342, participant->getIOService());
while(true)
{
Sleep(10);
tcpServer->sendTo("Hello World!", 13, "", 0);
}
return 1;*/
//Create topic, might throw ops::NoSuchTopicException
Topic topic = participant->createTopic("ChildTopic");
/*{
Topic scoopedTopic;
scoopedTopic = participant->createTopic("ChildTopic");
topic = scoopedTopic;
}*/
//topic.setDomainAddress("10.73.4.93");
//Create a publisher on that topic
ChildDataPublisher pub(topic);
pub.setName("TestAllPublisher");
pub.sendSleepTime = sendSleepTime;
pub.sleepEverySendPacket = sleepEveryNrPackets;
Topic baseTopic = participant->createTopic("BaseTopic");
BaseDataPublisher basePub(baseTopic);
basePub.setName("BasePublisher");
//Create some data to publish
ChildData data;
BaseData baseData;
baseData.baseText = "Text from base";
//Set Base class field
data.baseText = "Hello";
////Set aggregated object
TestData testData;
testData.text = "text in aggregated class";
testData.value = 3456.0;
data.test2 = testData;
data.testPointer = (TestData*)testData.clone();
//
//Set primitives
data.bo = true;
data.b = 3;
data.i = 0;
data.l = -3;
data.f = 4.0;
data.d = 5.0;
//data.s = "World";
//.........这里部分代码省略.........