本文整理汇总了C++中typenamestd::vector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::size方法的具体用法?C++ vector::size怎么用?C++ vector::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typenamestd::vector
的用法示例。
在下文中一共展示了vector::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
template < typename IN_PORT_TYPE, typename OUT_PORT_TYPE > int peak_detector_ib_base::_transformerServiceFunction( typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams ,
typename std::vector< gr_ostream< OUT_PORT_TYPE > > &ostreams )
{
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
typedef typename std::vector< gr_ostream< OUT_PORT_TYPE > > _OStreamList;
boost::mutex::scoped_lock lock(serviceThreadLock);
if ( validGRBlock() == false ) {
// create our processing block, and setup property notifiers
createBlock();
LOG_DEBUG( peak_detector_ib_base, " FINISHED BUILDING GNU RADIO BLOCK");
}
//process any Stream ID changes this could affect number of io streams
processStreamIdChanges();
if ( !validGRBlock() || istreams.size() == 0 || ostreams.size() == 0 ) {
LOG_WARN( peak_detector_ib_base, "NO STREAMS ATTACHED TO BLOCK..." );
return NOOP;
}
_input_ready.resize( istreams.size() );
_ninput_items_required.resize( istreams.size() );
_ninput_items.resize( istreams.size() );
_input_items.resize( istreams.size() );
_output_items.resize( ostreams.size() );
//
// RESOLVE: need to look at forecast strategy,
// 1) see how many read items are necessary for N number of outputs
// 2) read input data and see how much output we can produce
//
//
// Grab available data from input streams
//
typename _OStreamList::iterator ostream;
typename _IStreamList::iterator istream = istreams.begin();
int nitems=0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
// note this a blocking read that can cause deadlocks
nitems = istream->read();
if ( istream->overrun() ) {
LOG_WARN( peak_detector_ib_base, " NOT KEEPING UP WITH STREAM ID:" << istream->streamID );
}
if ( istream->sriChanged() ) {
// RESOLVE - need to look at how SRI changes can affect Gnu Radio BLOCK state
LOG_DEBUG( peak_detector_ib_base, "SRI CHANGED, STREAMD IDX/ID: "
<< idx << "/" << istream->pkt->streamID );
setOutputStreamSRI( idx, istream->pkt->SRI );
}
}
LOG_TRACE( peak_detector_ib_base, "READ NITEMS: " << nitems );
if ( nitems <= 0 && !_istreams[0].eos() ) {
return NOOP;
}
bool eos = false;
int nout = 0;
bool workDone = false;
while ( nout > -1 && serviceThread->threadRunning() ) {
eos = false;
nout = _forecastAndProcess( eos, istreams, ostreams );
if ( nout > -1 ) {
workDone = true;
// we chunked on data so move read pointer..
istream = istreams.begin();
for ( ; istream != istreams.end(); istream++ ) {
int idx=std::distance( istreams.begin(), istream );
// if we processed data for this stream
if ( _input_ready[idx] ) {
size_t nitems = 0;
try {
nitems = gr_sptr->nitems_read( idx );
} catch(...){}
if ( nitems > istream->nitems() ) {
LOG_WARN( peak_detector_ib_base, "WORK CONSUMED MORE DATA THAN AVAILABLE, READ/AVAILABLE "
<< nitems << "/" << istream->nitems() );
nitems = istream->nitems();
}
istream->consume( nitems );
LOG_TRACE( peak_detector_ib_base, " CONSUME READ DATA ITEMS/REMAIN " << nitems << "/" << istream->nitems());
}
}
gr_sptr->reset_read_index();
}
// check for not enough data return
if ( nout == -1 ) {
// check for end of stream
//.........这里部分代码省略.........
示例2: while
template < typename IN_PORT_TYPE > int file_sink_s_base::_forecastAndProcess( bool &eos, typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams )
{
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
typename _IStreamList::iterator istream = istreams.begin();
int nout = 0;
bool dataReady = false;
if ( !eos ) {
uint64_t max_items_avail = 0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
LOG_TRACE( file_sink_s_base, "GET MAX ITEMS: STREAM:" << idx << " NITEMS/SCALARS:"
<< istream->nitems() << "/" << istream->_data.size() );
max_items_avail = std::max( istream->nitems(), max_items_avail );
}
//
// calc number of output items to produce
//
noutput_items = (int) (max_items_avail * gr_sptr->relative_rate ());
noutput_items = round_down (noutput_items, gr_sptr->output_multiple ());
if ( noutput_items <= 0 ) {
LOG_TRACE( file_sink_s_base, "DATA CHECK - MAX ITEMS NOUTPUT/MAX_ITEMS:" << noutput_items << "/" << max_items_avail);
return -1;
}
if ( gr_sptr->fixed_rate() ) {
istream = istreams.begin();
for ( int i=0; istream != istreams.end(); i++, istream++ ) {
int t_noutput_items = gr_sptr->fixed_rate_ninput_to_noutput( istream->nitems() );
if ( gr_sptr->output_multiple_set() ) {
t_noutput_items = round_up(t_noutput_items, gr_sptr->output_multiple());
}
if ( t_noutput_items > 0 ) {
if ( noutput_items == 0 ) {
noutput_items = t_noutput_items;
}
if ( t_noutput_items <= noutput_items ) {
noutput_items = t_noutput_items;
}
}
}
LOG_TRACE( file_sink_s_base, " FIXED FORECAST NOUTPUT/output_multiple == "
<< noutput_items << "/" << gr_sptr->output_multiple());
}
//
// ask the block how much input they need to produce noutput_items...
// if enough data is available to process then set the dataReady flag
//
int32_t outMultiple = gr_sptr->output_multiple();
while ( !dataReady && noutput_items >= outMultiple ) {
//
// ask the block how much input they need to produce noutput_items...
//
gr_sptr->forecast(noutput_items, _ninput_items_required);
LOG_TRACE( file_sink_s_base, "--> FORECAST IN/OUT " << _ninput_items_required[0] << "/" << noutput_items );
istream = istreams.begin();
uint32_t dr_cnt=0;
for ( int idx=0 ; noutput_items > 0 && istream != istreams.end(); idx++, istream++ ) {
// check if buffer has enough elements
_input_ready[idx] = false;
if ( istream->nitems() >= (uint64_t)_ninput_items_required[idx] ) {
_input_ready[idx] = true;
dr_cnt++;
}
LOG_TRACE( file_sink_s_base, "ISTREAM DATACHECK NELMS/NITEMS/REQ/READY:" <<
istream->nelems() << "/" << istream->nitems() << "/" <<
_ninput_items_required[idx] << "/" << _input_ready[idx]);
}
if ( dr_cnt < istreams.size() ) {
if ( outMultiple > 1 ) {
noutput_items -= outMultiple;
} else {
noutput_items /= 2;
}
} else {
dataReady = true;
}
LOG_TRACE( file_sink_s_base, " TRIM FORECAST NOUTPUT/READY " << noutput_items << "/" << dataReady );
}
// check if data is ready...
if ( !dataReady ) {
LOG_TRACE( file_sink_s_base, "DATA CHECK - NOT ENOUGH DATA AVAIL/REQ:"
<< _istreams[0].nitems() << "/" << _ninput_items_required[0] );
return -1;
}
// reset looping variables
int ritems = 0;
int nitems = 0;
// reset caching vectors
_output_items.clear();
_input_items.clear();
_ninput_items.clear();
//.........这里部分代码省略.........
示例3: while
template < typename IN_PORT_TYPE, typename OUT_PORT_TYPE > int cpfsk_bc_base::_forecastAndProcess( bool &eos, typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams ,
typename std::vector< gr_ostream< OUT_PORT_TYPE > > &ostreams )
{
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
typedef typename std::vector< gr_ostream< OUT_PORT_TYPE > > _OStreamList;
typename _OStreamList::iterator ostream;
typename _IStreamList::iterator istream = istreams.begin();
int nout = 0;
bool dataReady = false;
if ( !eos ) {
uint64_t max_items_avail = 0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
LOG_TRACE( cpfsk_bc_base, "GET MAX ITEMS: STREAM:"<< idx << " NITEMS/SCALARS:" <<
istream->nitems() << "/" << istream->_data.size() );
max_items_avail = std::max( istream->nitems(), max_items_avail );
}
if ( max_items_avail == 0 ) {
LOG_TRACE( cpfsk_bc_base, "DATA CHECK - MAX ITEMS NOUTPUT/MAX_ITEMS:" << noutput_items << "/" << max_items_avail);
return -1;
}
//
// calc number of output elements based on input items available
//
noutput_items = 0;
if ( !gr_sptr->fixed_rate() ) {
noutput_items = round_down((int32_t) (max_items_avail * gr_sptr->relative_rate()), gr_sptr->output_multiple());
LOG_TRACE( cpfsk_bc_base, " VARIABLE FORECAST NOUTPUT == " << noutput_items );
} else {
istream = istreams.begin();
for ( int i=0; istream != istreams.end(); i++, istream++ ) {
int t_noutput_items = gr_sptr->fixed_rate_ninput_to_noutput( istream->nitems() );
if ( gr_sptr->output_multiple_set() ) {
t_noutput_items = round_up(t_noutput_items, gr_sptr->output_multiple());
}
if ( t_noutput_items > 0 ) {
if ( noutput_items == 0 ) {
noutput_items = t_noutput_items;
}
if ( t_noutput_items <= noutput_items ) {
noutput_items = t_noutput_items;
}
}
}
LOG_TRACE( cpfsk_bc_base, " FIXED FORECAST NOUTPUT/output_multiple == " <<
noutput_items << "/" << gr_sptr->output_multiple());
}
//
// ask the block how much input they need to produce noutput_items...
// if enough data is available to process then set the dataReady flag
//
int32_t outMultiple = gr_sptr->output_multiple();
while ( !dataReady && noutput_items >= outMultiple ) {
//
// ask the block how much input they need to produce noutput_items...
//
gr_sptr->forecast(noutput_items, _ninput_items_required);
LOG_TRACE( cpfsk_bc_base, "--> FORECAST IN/OUT " << _ninput_items_required[0] << "/" << noutput_items );
istream = istreams.begin();
uint32_t dr_cnt=0;
for ( int idx=0 ; noutput_items > 0 && istream != istreams.end(); idx++, istream++ ) {
// check if buffer has enough elements
_input_ready[idx] = false;
if ( istream->nitems() >= (uint64_t)_ninput_items_required[idx] ) {
_input_ready[idx] = true;
dr_cnt++;
}
LOG_TRACE( cpfsk_bc_base, "ISTREAM DATACHECK NELMS/NITEMS/REQ/READY:" << istream->nelems() <<
"/" << istream->nitems() << "/" << _ninput_items_required[idx] << "/" << _input_ready[idx]);
}
if ( dr_cnt < istreams.size() ) {
if ( outMultiple > 1 ) {
noutput_items -= outMultiple;
} else {
noutput_items /= 2;
}
} else {
dataReady = true;
}
LOG_TRACE( cpfsk_bc_base, " TRIM FORECAST NOUTPUT/READY " << noutput_items << "/" << dataReady );
}
// check if data is ready...
if ( !dataReady ) {
LOG_TRACE( cpfsk_bc_base, "DATA CHECK - NOT ENOUGH DATA AVAIL/REQ:" << _istreams[0].nitems() <<
"/" << _ninput_items_required[0] );
return -1;
}
// reset looping variables
int ritems = 0;
int nitems = 0;
// reset caching vectors
//.........这里部分代码省略.........
示例4: encodeImageToPNG
template<typename T> void
encodeImageToPNG (typename std::vector<T>& image_arg,
size_t width_arg,
size_t height_arg,
int image_format_arg,
typename std::vector<uint8_t>& pngData_arg,
int png_level_arg)
{
png_structp png_ptr;
png_infop info_ptr;
volatile int channels;
if (image_arg.size () ==0)
return;
// Get amount of channels
switch (image_format_arg)
{
case PNG_COLOR_TYPE_GRAY:
channels = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
channels = 2;
break;
case PNG_COLOR_TYPE_RGB:
channels = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
channels = 4;
break;
default:
channels = 0;
break;
}
// Ensure valid input array
assert (image_arg.size () == width_arg*height_arg*channels);
// Initialize write structure
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
assert (png_ptr && "creating png_create_write_structpng_create_write_struct failed");
// Initialize info structure
info_ptr = png_create_info_struct (png_ptr);
assert (info_ptr && "Could not allocate info struct");
// Setup Exception handling
setjmp(png_jmpbuf(png_ptr));
// reserve memory for output data (300kB)
pngData_arg.clear ();
pngData_arg.reserve (300 * 1024);
// Define I/O methods
png_set_write_fn (png_ptr, reinterpret_cast<void*> (&pngData_arg),
user_write_data, user_flush_data);
// Define zlib compression level
if (png_level_arg >= 0)
{
png_set_compression_level (png_ptr, png_level_arg);
}
else
{
png_set_compression_level (png_ptr, Z_DEFAULT_COMPRESSION);
}
// Write header
png_set_IHDR (png_ptr, info_ptr, width_arg, height_arg, sizeof(T) * 8,
image_format_arg, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info (png_ptr, info_ptr);
// Write image data
size_t y;
for (y = 0; y < height_arg; y++)
{
png_write_row (png_ptr, reinterpret_cast<png_bytep> (&image_arg[y * width_arg * channels]));
}
// End write
png_write_end (png_ptr, 0);
if (info_ptr)
png_free_data (png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr)
png_destroy_write_struct (&png_ptr, 0);
}
示例5: decodePNGImage
template<typename T> void
decodePNGImage (typename std::vector<uint8_t>& pngData_arg,
typename std::vector<T>& imageData_arg,
size_t& width_arg,
size_t& height_arg,
unsigned int& channels_arg)
{
int y;
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 png_width;
png_uint_32 png_height;
int png_bit_depth, png_color_type, png_interlace_type;
png_bytep * row_pointers;
if (pngData_arg.size () == 0)
return;
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
assert (png_ptr && "creating png_create_write_structpng_create_write_struct failed");
// Initialize info structure
info_ptr = png_create_info_struct (png_ptr);
assert(info_ptr && "Could not allocate info struct");
// Setup Exception handling
setjmp (png_jmpbuf(png_ptr));
uint8_t* input_pointer = &pngData_arg[0];
png_set_read_fn (png_ptr, reinterpret_cast<void*> (&input_pointer), user_read_data);
png_read_info (png_ptr, info_ptr);
png_get_IHDR (png_ptr, info_ptr, &png_width, &png_height, &png_bit_depth,
&png_color_type, &png_interlace_type, NULL, NULL);
// ensure a color bit depth of 8
assert(png_bit_depth==sizeof(T)*8);
unsigned int png_channels;
switch (png_color_type)
{
case PNG_COLOR_TYPE_GRAY:
png_channels = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
png_channels = 2;
break;
case PNG_COLOR_TYPE_RGB:
png_channels = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
png_channels = 4;
break;
default:
png_channels = 0;
break;
}
width_arg = png_width;
height_arg = png_height;
channels_arg = png_channels;
imageData_arg.clear ();
imageData_arg.resize (png_height * png_width * png_channels);
row_pointers = reinterpret_cast<png_bytep*> (malloc (sizeof(png_bytep) * png_height));
for (y = 0; y < png_height; y++)
row_pointers[y] = reinterpret_cast<png_byte*> (&imageData_arg[y * png_width * png_channels]);
png_read_image (png_ptr, row_pointers);
if (info_ptr)
png_free_data (png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr)
png_destroy_read_struct (&png_ptr, 0, 0);
if (row_pointers)
free (row_pointers);
}
示例6: addText
void VisusIndexedData::addText(XMLNode& node, const std::vector<std::vector<T > >* items) const
{
// Count max number of items
int maxitems = 0;
for (typename std::vector<std::vector<T> >::const_iterator iiter=items->begin();
iiter!=items->end(); ++iiter)
maxitems += iiter->size() + 1;
// Construct contiguous buffer
const int bufsize = sizeof(T) * maxitems;
unsigned char* buffer = new unsigned char[bufsize+1];
node.addAttribute("numItems", (long) items->size());
node.addAttribute("bufsize", bufsize);
int position = 0;
// Copy non-contiguous data into contiguous buffer
for (typename std::vector<std::vector<T> >::const_iterator iiter=items->begin();
iiter!=items->end(); ++iiter)
{
// Save Num Items
T value = items->size();
memcpy(&buffer[position], &value, sizeof(T));
position += sizeof(T);
// Load Vector's Vector of items into buffer
for (typename std::vector<T>::const_iterator idtIter=iiter->begin();
idtIter!=iiter->end(); ++idtIter)
{
vassert(position < bufsize);
memcpy(&buffer[position], &(*idtIter), sizeof(T));
position += sizeof(T);
}
}
vassert(position == bufsize);
// Save Buffer out to XML
switch (VisusXMLInterface::sWriteXMLDataStorage)
{
case BASE64:
{
// Save data as BASE64
XMLParserBase64Tool base64;
XMLSTR encoded = base64.encode(buffer, bufsize);
node.addText(encoded);
}
break;
case EXTERNAL_FILE:
{
vwarning("saving data to external file is not yet supported");
}
break;
case ASCII:
{
vwarning("saving data to external file is not yet supported");
}
break;
}
delete [] buffer;
}
示例7: lock
template < typename IN_PORT_TYPE > int tagged_file_sink_b_base::_analyzerServiceFunction( typename std::vector< gr_istream< IN_PORT_TYPE > > &istreams )
{
typedef typename std::vector< gr_istream< IN_PORT_TYPE > > _IStreamList;
boost::mutex::scoped_lock lock(serviceThreadLock);
if ( validGRBlock() == false ) {
// create our processing block
createBlock();
LOG_DEBUG( tagged_file_sink_b_base, " FINISHED BUILDING GNU RADIO BLOCK");
}
// process any Stream ID changes this could affect number of io streams
processStreamIdChanges();
if ( !validGRBlock() || istreams.size() == 0 ) {
LOG_WARN( tagged_file_sink_b_base, "NO STREAMS ATTACHED TO BLOCK..." );
return NOOP;
}
// resize data vectors for passing data to GR_BLOCK object
_input_ready.resize( istreams.size() );
_ninput_items_required.resize( istreams.size());
_ninput_items.resize( istreams.size());
_input_items.resize(istreams.size());
_output_items.resize(0);
//
// RESOLVE: need to look at forecast strategy,
// 1) see how many read items are necessary for N number of outputs
// 2) read input data and see how much output we can produce
//
//
// Grab available data from input streams
//
typename _IStreamList::iterator istream = istreams.begin();
int nitems=0;
for ( int idx=0 ; istream != istreams.end() && serviceThread->threadRunning() ; idx++, istream++ ) {
// note this a blocking read that can cause deadlocks
nitems = istream->read();
if ( istream->overrun() ) {
LOG_WARN( tagged_file_sink_b_base, " NOT KEEPING UP WITH STREAM ID:" << istream->streamID );
}
// RESOLVE issue when SRI changes that could affect the GNU Radio BLOCK
if ( istream->sriChanged() ) {
LOG_DEBUG( tagged_file_sink_b_base, "SRI CHANGED, STREAMD IDX/ID: "
<< idx << "/" << istream->pkt->streamID );
}
}
LOG_TRACE( tagged_file_sink_b_base, "READ NITEMS: " << nitems );
if ( nitems <= 0 && !_istreams[0].eos() ) return NOOP;
bool eos = false;
int nout = 0;
while ( nout > -1 && serviceThread->threadRunning() ) {
eos = false;
nout = _forecastAndProcess( eos, istreams );
if ( nout > -1 ) {
// we chunked on data so move read pointer..
istream = istreams.begin();
for ( ; istream != istreams.end(); istream++ ) {
int idx=std::distance( istreams.begin(), istream );
// if we processed data for this stream
if ( _input_ready[idx] ) {
size_t nitems = 0;
try {
nitems = gr_sptr->nitems_read( idx );
} catch(...){}
if ( nitems > istream->nitems() ) {
LOG_WARN( tagged_file_sink_b_base, "WORK CONSUMED MORE DATA THAN AVAILABLE, READ/AVAILABLE "
<< nitems << "/" << istream->nitems() );
nitems = istream->nitems();
}
istream->consume( nitems );
LOG_TRACE( tagged_file_sink_b_base, " CONSUME READ DATA ITEMS/REMAIN " << nitems << "/" << istream->nitems());
}
}
gr_sptr->reset_read_index();
}
// check for not enough data return
if ( nout == -1 ) {
// check for end of stream
istream = istreams.begin();
for ( ; istream != istreams.end() ; istream++) {
if ( istream->eos() ) {
eos=true;
}
}
if ( eos ) {
LOG_TRACE( tagged_file_sink_b_base, " DATA NOT READY, EOS:" << eos );
//.........这里部分代码省略.........
示例8: size
int size() const { return m_int2name.size(); }