本文整理汇总了C++中boost::shared_array类的典型用法代码示例。如果您正苦于以下问题:C++ shared_array类的具体用法?C++ shared_array怎么用?C++ shared_array使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了shared_array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_packet
void reception_thread::read_packet(boost::shared_array<unsigned char> buffer, unsigned int size)
{
std::cout << "read_packet " << size << std::endl;
assert(!!boost::get<frequency_lock_state>(&state)
|| !!boost::get<ready_state>(&state));
if(boost::get<frequency_lock_state>(&state))
{
frequency_lock_state& s = boost::get<frequency_lock_state>(state);
if(size >= 4)
{
typedef gts::sections::extended_section<unsigned char*> section_type;
section_type section(buffer.get (), buffer.get () + size);
typedef section_type::table_id_iterator table_id_iterator;
table_id_iterator table_id = section.begin ();
std::cout << "table_id: 0x" << std::hex << *table_id << std::dec << std::endl;
if(*table_id == 0x42) // SDT
{
std::cout << "SDT" << std::endl;
if(parse_sdt(buffer.get(), size))
{
Q_EMIT lock_end_signal ();
}
else
Q_EMIT lock_error_signal ();
}
}
}
else
{
std::cout << "Already in ready state" << std::endl;
}
}
示例2: GetMsgParam
inline bool GetMsgParam(const std::string& netmsgbus_msgcontent, boost::shared_array<char>& msgparam, uint32_t& param_len)
{
std::string msgparamstr;
if (netmsgbus_msgcontent.length() < SENDER_LEN_BYTES)
return false;
uint8_t msgsender_len = (uint8_t)netmsgbus_msgcontent[0];
if (netmsgbus_msgcontent.length() < SENDER_LEN_BYTES + (std::size_t)msgsender_len + MSGKEY_LEN_BYTES)
return false;
uint8_t msgkey_len = (uint8_t)(netmsgbus_msgcontent[SENDER_LEN_BYTES + msgsender_len]);
uint32_t msgparam_offset = SENDER_LEN_BYTES + msgsender_len + MSGKEY_LEN_BYTES + msgkey_len;
if (netmsgbus_msgcontent.length() < msgparam_offset + MSGVALUE_LEN_BYTES)
return false;
uint32_t netparam_len = *((uint32_t *)&netmsgbus_msgcontent[msgparam_offset]);
param_len = ntohl(netparam_len);
if (netmsgbus_msgcontent.length() < msgparam_offset + MSGVALUE_LEN_BYTES + param_len)
return false;
msgparam.reset(new char[param_len]);
memcpy(msgparam.get(), &netmsgbus_msgcontent[msgparam_offset + MSGVALUE_LEN_BYTES], param_len);
return true;
//if(GetMsgKey(netmsgbus_msgcontent, msgparam_str, msgparamstr))
//{
// assert(msgparamstr.size());
// msgparam.reset(new char[msgparamstr.size()]);
// memcpy(msgparam.get(), msgparamstr.data(), msgparamstr.size());
// param_len = msgparamstr.size();
// return true;
//}
//printf("netmsgbus_msgcontent error, no msgparam found.\n");
//return false;
}
开发者ID:absolute8511,项目名称:Message-Bus-All-In-One-For-In-Process--Inter-Process-and-Internet,代码行数:33,代码来源:NetMsgBusUtility.hpp
示例3: test_write_then_read
void test_write_then_read(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
zlib_trans->write(buf.get(), buf_len);
zlib_trans->finish();
boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
uint32_t got = zlib_trans->readAll(mirror.get(), buf_len);
BOOST_REQUIRE_EQUAL(got, buf_len);
BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf.get(), buf_len), 0);
zlib_trans->verifyChecksum();
}
示例4: processIpfixPacket
/**
* Process an IPFIX Packet
* @return 0 on success
*/
int IpfixParser::processIpfixPacket(boost::shared_array<uint8_t> message, uint16_t length, boost::shared_ptr<IpfixRecord::SourceID> sourceId) {
IpfixHeader* header = (IpfixHeader*)message.get();
sourceId->observationDomainId = ntohl(header->observationDomainId);
if (ntohs(header->length) != length) {
msg(MSG_ERROR, "IpfixParser: Bad message length - packet length is %#06x, header length field is %#06x\n", length, ntohs(header->length));
return -1;
}
/* pointer to first set */
IpfixSetHeader* set = (IpfixSetHeader*)&header->data;
/* pointer beyond message */
uint8_t* endOfMessage = (uint8_t*)((uint8_t*)message.get() + length);
uint16_t tmpid;
uint32_t numberOfDataRecords;
/* while there is space for a set header... */
while((uint8_t*)(set) + 4 <= endOfMessage) {
/* check set length */
if (ntohs(set->length) < 3) {
msg(MSG_ERROR, "IpfixParser: Invalid set length %u, must be >= 4", ntohs(set->length));
return -1;
}
tmpid=ntohs(set->id);
switch(tmpid) {
case IPFIX_SetId_DataTemplate:
processDataTemplateSet(sourceId, message, set, endOfMessage);
break;
case IPFIX_SetId_Template:
processTemplateSet(sourceId, message, set, endOfMessage);
break;
case IPFIX_SetId_OptionsTemplate:
processOptionsTemplateSet(sourceId, message, set, endOfMessage);
break;
default:
if(tmpid >= IPFIX_SetId_Data_Start) {
statTotalDRPackets++;
numberOfDataRecords += processDataSet(sourceId, message, set, endOfMessage);
} else {
msg(MSG_ERROR, "processIpfixPacket: Unsupported Set ID - expected 2/3/4/256+, got %d", tmpid);
}
}
set = (IpfixSetHeader*)((uint8_t*)set + ntohs(set->length));
}
//FIXME: check for out-of-order messages and lost records
msg(MSG_VDEBUG, "Message contained %u bytes, sequence number was %u", numberOfDataRecords, ntohl(header->sequenceNo));
return 0;
}
示例5: is_robust_coloring
bool is_robust_coloring(const Graph & g, const int & k,
const boost::shared_array<int>& col)
{
bool ok = true;
boost::shared_array<int> tcol(new int[order(g)]);
/* The coloring is robust if each vertex is locally recolorable. */
for (int v = 0; v < order(g) && ok; v++) {
std::copy(col.get(), col.get() + order(g), tcol.get());
if (!is_locally_recolorable(g, k, tcol, v))
ok = false;
}
return ok;
}
示例6: do_work
// do all the work on 'np' partitions, 'nx' data points each, for 'nt'
// time steps
hpx::future<space> do_work(std::size_t np, std::size_t nx, std::size_t nt,
boost::shared_array<double> data)
{
using hpx::dataflow;
using hpx::util::unwrapped;
// U[t][i] is the state of position i at time t.
std::vector<space> U(2);
for (space& s: U)
s.resize(np);
if (!data) {
// Initial conditions: f(0, i) = i
std::size_t b = 0;
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(
par, boost::begin(range), boost::end(range),
[&U, nx](std::size_t i)
{
U[0][i] = hpx::make_ready_future(
partition_data(nx, double(i)));
}
);
}
else {
// Initialize from existing data
std::size_t b = 0;
auto range = boost::irange(b, np);
using hpx::parallel::execution::par;
hpx::parallel::for_each(
par, boost::begin(range), boost::end(range),
[&U, nx, data](std::size_t i)
{
U[0][i] = hpx::make_ready_future(
partition_data(nx, data.get()+(i*nx)));
}
);
}
auto Op = unwrapped(&stepper::heat_part);
// Actual time step loop
for (std::size_t t = 0; t != nt; ++t)
{
space const& current = U[t % 2];
space& next = U[(t + 1) % 2];
for (std::size_t i = 0; i != np; ++i)
{
next[i] = dataflow(
hpx::launch::async, Op,
current[idx(i, -1, np)], current[i], current[idx(i, +1, np)]
);
}
}
// Return the solution at time-step 'nt'.
return hpx::when_all(U[nt % 2]);
}
示例7: gotDownloadProgram
void btlauncherAPI::gotDownloadProgram(const FB::JSObjectPtr& callback,
std::wstring& program,
std::string& version,
bool success,
const FB::HeaderMap& headers,
const boost::shared_array<uint8_t>& data,
const size_t size) {
TCHAR temppath[500];
DWORD gettempresult = GetTempPath(500, temppath);
if (! gettempresult) {
callback->InvokeAsync("", FB::variant_list_of(false)("GetTempPath")(GetLastError()));
return;
}
std::wstring syspath(temppath);
syspath.append( program.c_str() );
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
syspath.append( _T("_") );
std::wstring wversion;
wversion.assign( version.begin(), version.end() );
syspath.append( wversion );
syspath.append( _T("_") );
syspath.append( boost::uuids::to_wstring(u) );
syspath.append(_T(".exe"));
HANDLE hFile = CreateFile( syspath.c_str(), GENERIC_WRITE | GENERIC_EXECUTE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL );
if (hFile == INVALID_HANDLE_VALUE) {
callback->InvokeAsync("", FB::variant_list_of(false)(GetLastError()));
return;
}
PVOID ptr = (VOID*) data.get();
DWORD written = 0;
BOOL RESULT = WriteFile( hFile, ptr, size, &written, NULL);
CloseHandle(hFile);
if (! RESULT) {
callback->InvokeAsync("", FB::variant_list_of("FILE")(false)(GetLastError()));
return;
}
std::wstring installcommand = std::wstring(syspath);
installcommand.append(_T(" /NOINSTALL /MINIMIZED /HIDE"));
STARTUPINFO info;
PROCESS_INFORMATION procinfo;
memset(&info,0,sizeof(info));
info.cb = sizeof(STARTUPINFO);
/* CreateProcessW can modify installcommand thus we allocate needed memory */
wchar_t * pwszParam = new wchar_t[installcommand.size() + 1];
const wchar_t* pchrTemp = installcommand.c_str();
wcscpy_s(pwszParam, installcommand.size() + 1, pchrTemp);
BOOL bProc = CreateProcess(NULL, pwszParam, NULL, NULL, FALSE, 0, NULL, NULL, &info, &procinfo);
if(bProc) {
callback->InvokeAsync("", FB::variant_list_of("PROCESS")(true)(installcommand.c_str())(GetLastError()));
} else {
callback->InvokeAsync("", FB::variant_list_of("PROCESS")(false)(installcommand.c_str())(GetLastError()));
}
}
示例8: onMessageLength
void TransportPublisherLink::onMessageLength(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success)
{
if (retry_timer_handle_ != -1)
{
getInternalTimerManager()->remove(retry_timer_handle_);
retry_timer_handle_ = -1;
}
if (!success)
{
if (connection_)
connection_->read(4, boost::bind(&TransportPublisherLink::onMessageLength, this, _1, _2, _3, _4));
return;
}
ROS_ASSERT(conn == connection_);
ROS_ASSERT(size == 4);
uint32_t len = *((uint32_t*)buffer.get());
if (len > 1000000000)
{
ROS_ERROR("a message of over a gigabyte was " \
"predicted in tcpros. that seems highly " \
"unlikely, so I'll assume protocol " \
"synchronization is lost.");
drop();
return;
}
connection_->read(len, boost::bind(&TransportPublisherLink::onMessage, this, _1, _2, _3, _4));
}
示例9: test_write_after_flush
void test_write_after_flush(const boost::shared_array<uint8_t> buf, uint32_t buf_len) {
// write some data
boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
zlib_trans->write(buf.get(), buf_len);
// call finish()
zlib_trans->finish();
// make sure write() throws an error
try {
uint8_t write_buf[] = "a";
zlib_trans->write(write_buf, 1);
BOOST_ERROR("write() after finish() did not raise an exception");
} catch (TTransportException& ex) {
BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
}
// make sure flush() throws an error
try {
zlib_trans->flush();
BOOST_ERROR("flush() after finish() did not raise an exception");
} catch (TTransportException& ex) {
BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
}
// make sure finish() throws an error
try {
zlib_trans->finish();
BOOST_ERROR("finish() after finish() did not raise an exception");
} catch (TTransportException& ex) {
BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
}
}
示例10: RecvMsg
/*
* return number of bytes received, negative if error, 0 for received nothing,
* which should be treated as error
*/
int32_t RecvMsg(zmq::socket_t &sock, boost::shared_array<uint8_t> &data,
bool *_more){
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt);
}catch(zmq::error_t &e){
LOG(ERROR) << "RecvMsg error = " << e.what();
return -1;
}
if(nbytes == 0) return 0;
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc &e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
if(_more != NULL){
int more_recv;
size_t s = sizeof(int);
sock.getsockopt(ZMQ_RCVMORE, &more_recv, &s);
*_more = (more_recv == 1) ? true : false;
}
return len;
}
示例11: recv_msg
/*
* return number of bytes received, negative if error, 0 for received nothing, which should be treated as error
*/
int recv_msg(zmq::socket_t &sock, boost::shared_array<uint8_t> &data)
{
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt);
}catch(zmq::error_t e){
//LOG(NOR, stderr, "recv failed: %s\n", e.what());
return -1;
}
if(nbytes == 0) return 0;
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc e){
//LOG(DBG, stderr, "can not allocate memory!\n");
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
return len;
}
示例12: getURLCallback
void FBTestPluginAPI::getURLCallback(const FB::JSObjectPtr& callback, bool success,
const FB::HeaderMap& headers, const boost::shared_array<uint8_t>& data, const size_t size) {
FB::VariantMap outHeaders;
for (FB::HeaderMap::const_iterator it = headers.begin(); it != headers.end(); ++it) {
if (headers.count(it->first) > 1) {
if (outHeaders.find(it->first) != outHeaders.end()) {
outHeaders[it->first].cast<FB::VariantList>().push_back(it->second);
} else {
outHeaders[it->first] = FB::VariantList(FB::variant_list_of(it->second));
}
} else {
outHeaders[it->first] = it->second;
}
}
if (success) {
std::string dstr(reinterpret_cast<const char*>(data.get()), size);
callback->InvokeAsync("", FB::variant_list_of
(true)
(outHeaders)
(dstr)
);
} else {
callback->InvokeAsync("", FB::variant_list_of(false));
}
}
示例13: recv_msg_async
// 0 for received nothing
int recv_msg_async(zmq::socket_t &sock, boost::shared_array<uint8_t> &data)
{
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt, ZMQ_DONTWAIT);
}catch(zmq::error_t e){
return -1;
}
if(nbytes == 0){
if(zmq_errno() == EAGAIN)
return 0;
else
return -1;
}
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
return len;
}
示例14: debugMsgBuffer
void HeaderManipulation::debugMsgBuffer(boost::shared_array<uint8_t> &msg_buffer, uint32_t &msg_size)
{
for (uint j = 0; j < 4; ++j)
{
ROS_INFO("32-bit:%4i: %4i", j, (int)((uint32_t *)msg_buffer.get())[j]);
}
for (uint i = 0; i < 36; ++i)
{
ROS_DEBUG(" 8-bit:%4i: %2c = %4i", i, ((uint8_t *)msg_buffer.get())[i], (int)((uint8_t *)msg_buffer.get())[i]);
}
ROS_DEBUG("...");
for (uint i = msg_size-6; i < msg_size; ++i)
{
ROS_DEBUG(" 8-bit:%4i: %2c = %4i", i, ((uint8_t *)msg_buffer.get())[i], (int)((uint8_t *)msg_buffer.get())[i]);
}
}
示例15: write
void Header::write(const M_string& key_vals, boost::shared_array<uint8_t>& buffer, uint32_t& size)
{
// Calculate the necessary size
size = 0;
{
M_string::const_iterator it = key_vals.begin();
M_string::const_iterator end = key_vals.end();
for (; it != end; ++it)
{
const std::string& key = it->first;
const std::string& value = it->second;
size += key.length();
size += value.length();
size += 1; // = sign
size += 4; // 4-byte length
}
}
if (size == 0)
{
return;
}
buffer.reset(new uint8_t[size]);
char* ptr = (char*)buffer.get();
// Write the data
{
M_string::const_iterator it = key_vals.begin();
M_string::const_iterator end = key_vals.end();
for (; it != end; ++it)
{
const std::string& key = it->first;
const std::string& value = it->second;
uint32_t len = key.length() + value.length() + 1;
SROS_SERIALIZE_PRIMITIVE(ptr, len);
SROS_SERIALIZE_BUFFER(ptr, key.data(), key.length());
static const char equals = '=';
SROS_SERIALIZE_PRIMITIVE(ptr, equals);
SROS_SERIALIZE_BUFFER(ptr, value.data(), value.length());
}
}
ROS_ASSERT(ptr == (char*)buffer.get() + size);
}