本文整理汇总了C++中DataWriter::topic方法的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter::topic方法的具体用法?C++ DataWriter::topic怎么用?C++ DataWriter::topic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataWriter
的用法示例。
在下文中一共展示了DataWriter::topic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual void run(const dds::domain::DomainParticipant& dp,
const dds::topic::Topic<T>& topic,
const Params& params)
{
dds::pub::qos::PublisherQos pqos =
dp.default_publisher_qos() << Partition("ishapes");
dds::pub::Publisher pub(dp, pqos);
dds::pub::qos::DataWriterQos dwqos =
pub.default_datawriter_qos() << Durability::Transient() << Reliability::Reliable();
dds::pub::DataWriter<T> dw(pub, topic, dwqos);
const uint32_t period = params.period;
const uint32_t samples = params.samples;
uint32_t sleep_time = period * 1000;
srand(clock());
const uint32_t x0 = 10;
const uint32_t y0 = 10;
const uint32_t r = 200;
const uint32_t dx = 5;
const uint32_t dy = 7;
// AnyDataWriter work just fine...
AnyDataWriter adw = dw;
DataWriter<ShapeType> xdw = adw.get<ShapeType>();
std::cout << "Topic Name = " << xdw.topic().name()
<< "\tType Name = " << xdw.topic().type_name() << std::endl;
// ShapeType s = {params.color, x0, y0, params.shape_size};
ShapeType s = {params.color.c_str(), x0 , y0, params.shape_size};
std::cout << ">> Writing Data...";
std::flush(std::cout);
for (uint32_t i = 0; i < samples; ++i) {
// Regular write
dw.write(s);
// Stream write
dw << s;
s.x = (s.x + dx) % r;
s.y = (s.y + dy) % r;
exampleSleepMilliseconds(sleep_time); // period is in ms
}
}