本文整理汇总了C++中boost::posix_time::time_duration::total_seconds方法的典型用法代码示例。如果您正苦于以下问题:C++ time_duration::total_seconds方法的具体用法?C++ time_duration::total_seconds怎么用?C++ time_duration::total_seconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::posix_time::time_duration
的用法示例。
在下文中一共展示了time_duration::total_seconds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: datagen_thread_loop
/* threat functions*/
void datagen_thread_loop(void)
{
ostringstream testline;
/* create testdata*/
int jj=0;
for(int ii=0; ii < 8*8-1; ii++) //64 = 63 chars + end line
{
if(++jj > 9) jj = 0;
testline << jj;
}
testline << "\n";
jj=0;
while(record_thread_running && jj < NUM_LINES)
{
#if !defined(WITH_BOOST_TIME)
clock_gettime(CLOCK_MONOTONIC, &ts_beg); // http://linux.die.net/man/3/clock_gettime
#else
start_time = boost::posix_time::microsec_clock::local_time();
#endif
// ********************************* //
*active_buffer += testline.str().c_str();
if(4*1024 < active_buffer->length()) //write 4 kbyte blocks
{
record_trigger.notify_all();
}
// ********************************* //
#if !defined(WITH_BOOST_TIME)
clock_gettime(CLOCK_MONOTONIC, &ts_end);
v_fTime_s.push_back(ts_end.tv_sec);
v_fTime_us.push_back(ts_end.tv_nsec/1e+3);
v_fDifftime.push_back((ts_end.tv_sec - ts_beg.tv_sec) + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9);
f_DT_s = (ts_end.tv_sec - ts_beg.tv_sec) + (ts_end.tv_nsec - ts_beg.tv_nsec) / 1e9;
#else
stop_time = boost::posix_time::microsec_clock::local_time();
time_duration = (stop_time - start_time);
v_fTime_s.push_back( (stop_time-boost::posix_time::from_time_t(0)).total_seconds() );
v_fTime_us.push_back( (stop_time-boost::posix_time::from_time_t(0)).fractional_seconds() );
v_fDifftime.push_back( time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
f_DT_s = (time_duration.total_seconds()+ time_duration.fractional_seconds()/ 1e6);
#endif
#if defined(DEBUG)
if(0.5 < 1.e+3*f_DT_s) // log only values above 0.5 ms
{
cout << "Line " << jj << " of " << NUM_LINES << ":"
<< "\t" << v_fTime_s.back() << "." << v_fTime_us.back() << "s: "
<< "\tdT: " << fixed << 1.e+3*f_DT_s << " ms"
<< endl;
}
#endif
boost::this_thread::sleep(boost::posix_time::microseconds(4*1e+6*f_DT_s)); //about 50% CPU load
jj++;
}//while
datagen_done = true;
}
示例2:
platform_duration(boost::posix_time::time_duration const& rel_time)
{
#if defined BOOST_THREAD_CHRONO_POSIX_API || defined BOOST_THREAD_CHRONO_MAC_API
ts_val.tv_sec = rel_time.total_seconds();
ts_val.tv_nsec = static_cast<long>(rel_time.fractional_seconds() * (1000000000l / rel_time.ticks_per_second()));
#else
ns_val = static_cast<boost::time_max_t>(rel_time.total_seconds()) * 1000000000l;
ns_val += rel_time.fractional_seconds() * (1000000000l / rel_time.ticks_per_second());
#endif
}
示例3: wait
std::size_t select::wait( boost::posix_time::time_duration timeout )
{
unsigned int sec = timeout.total_seconds();
unsigned int nanosec = ( static_cast< unsigned int >( timeout.total_microseconds() ) - sec * 1000000 ) * 1000;
// std::cerr << "select wait " << sec << " , " << nanosec << std::endl;
return wait( sec, nanosec );
}
示例4: addTStep
void TimeMap::addTStep(boost::posix_time::time_duration step) {
if (step.total_seconds() > 0) {
boost::posix_time::ptime newTime = m_timeList.back() + step;
m_timeList.push_back( newTime );
} else
throw std::invalid_argument("Can only add positive steps");
}
示例5: GetBinInSeconds
boost::posix_time::time_duration Timer::RoundTime (boost::posix_time::time_duration time,
RoundingDirection direction,
RoundingDistance distance) const
{
long totalSeconds = time.total_seconds();
unsigned int rounding = GetBinInSeconds (distance);
boost::posix_time::time_duration roundedTime (0,0,0);
int numIntervals;
switch (direction) {
case ROUNDING_NONE:
roundedTime = time;
break;
case ROUNDING_UP:
numIntervals = int(ceil ((double)totalSeconds/(double)rounding));
roundedTime = boost::posix_time::seconds(numIntervals * rounding);
break;
case ROUNDING_DOWN:
numIntervals = int(floor ((double)totalSeconds/(double)rounding));
roundedTime = boost::posix_time::seconds(numIntervals * rounding);
break;
case ROUNDING_NEAREST:
numIntervals = int(((double)totalSeconds/(double)rounding) + 0.5);
roundedTime = boost::posix_time::seconds(numIntervals * rounding);
break;
}
return roundedTime;
}
示例6:
inline struct timespec get_timespec(boost::system_time const& abs_time)
{
struct timespec timeout={0};
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
timeout.tv_sec=time_since_epoch.total_seconds();
timeout.tv_nsec=time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second());
return timeout;
}
示例7: get_xtime
inline xtime get_xtime(boost::system_time const& abs_time)
{
xtime res={0};
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}
示例8: highLevelAPI
static void highLevelAPI(std::vector<const char*> const& filenames,
bool print_bayer_format, const boost::posix_time::time_duration& d,
unsigned char recordfilter)
{
contourpp::record_parser parser;
std::vector<contourpp::record> records;
records.reserve(128);
if (!filenames.empty()) {
for (std::vector<const char*>::const_iterator f = filenames.begin(); f != filenames.end(); ++f) {
std::ifstream ifs(*f);
if (!ifs.good())
throw std::runtime_error(std::string("could not open '") + (*f) + "'");
std::string buf;
contourpp::record rec;
while (std::getline(ifs, buf)) {
if (parser.parse(buf.data(), buf.data() + buf.size(), rec)) {
if (records.size() == records.capacity())
records.reserve(2 * records.capacity());
records.push_back(rec);
}
}
}
}
else
parser.get_all(records);
std::vector<contourpp::record>::iterator i, e(records.end());
if (d.total_seconds() != 0) {
for (i = records.begin(); i != e; ++i)
i->shift_time(d);
}
if (print_bayer_format) {
for (i = records.begin(); i != e; ++i) {
if (getRecordType(*i) & recordfilter) {
i->print_bayer(std::cout);
std::cout << std::endl;
}
}
}
else {
for (i = records.begin(); i != e; ++i)
if (getRecordType(*i) & recordfilter)
std::cout << (*i) << std::endl;
}
}
示例9: EPOCH
value_visitor::result_type
value_visitor::operator()(const date_t& value)
{
static const date_t EPOCH(boost::gregorian::date(1970, 1, 1));
const boost::posix_time::time_duration duration = value - EPOCH;
if (duration.seconds() == 0 && duration.fractional_seconds() == 0)
{
push_back<std::int8_t>('K');
push_back<std::int32_t>(duration.total_seconds() / 60);
}
else
{
push_back<std::int8_t>('J');
push_back<std::int64_t>(duration.total_milliseconds());
}
}
示例10: force_reannounce
void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const
{
INVARIANT_CHECK;
TORRENT_ASYNC_CALL1(force_tracker_request, time_now() + seconds(duration.total_seconds()));
}
示例11: purge
/**
* @brief Purge cache entries that have not been active for some time.
*
* @param indom Instance domain to purge entries for.
* @param recent All entries that have not been active within this interval
* will be purged.
*
* @throw pcp::exception On error.
*
* @return The number of items purged.
*
* @see pmdaCachePurge
*/
inline size_t purge(const pmInDom indom, const boost::posix_time::time_duration &recent)
{
return purge(indom, recent.total_seconds());
}
示例12: force_reannounce
void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const
{
async_call(&torrent::force_tracker_request, aux::time_now()
+ seconds(duration.total_seconds()), -1);
}
示例13: ToSeconds
static double ToSeconds(const boost::posix_time::time_duration &diff) {
return diff.total_seconds() + diff.total_nanoseconds() / 1e9;
}
示例14: force_reannounce
void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const
{
TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now()
+ seconds(duration.total_seconds()), -1);
}
示例15: run
void run( S* stream )
{
static const unsigned int timeSize = 12;
boost::mt19937 generator;
boost::uniform_real< float > distribution( 0, 1 );
boost::variate_generator< boost::mt19937&, boost::uniform_real< float > > random( generator, distribution );
comma::uint64 count = 0;
comma::uint64 dropped_count = 0;
double compression = 0;
velodyne::packet packet;
comma::signal_flag isShutdown;
velodyne::scan_tick tick;
comma::uint32 scan_id = 0;
while( !isShutdown && std::cin.good() && !std::cin.eof() && std::cout.good() && !std::cout.eof() )
{
const char* p = velodyne::impl::stream_traits< S >::read( *stream, sizeof( velodyne::packet ) );
if( p == NULL ) { break; }
::memcpy( &packet, p, velodyne::packet::size );
if( tick.is_new_scan( packet ) ) { ++scan_id; } // quick and dirty
boost::posix_time::ptime timestamp = stream->timestamp();
if( scan_rate ) { scan.thin( packet, *scan_rate, angularSpeed( packet ) ); }
if( !scan_rate || !scan.empty() )
{
if( focus ) { velodyne::thin::thin( packet, *focus, *db, angularSpeed( packet ), random ); }
if( rate ) { velodyne::thin::thin( packet, *rate, random ); }
}
const boost::posix_time::ptime base( snark::timing::epoch );
const boost::posix_time::time_duration d = timestamp - base;
comma::int64 seconds = d.total_seconds();
comma::int32 nanoseconds = static_cast< comma::int32 >( d.total_microseconds() % 1000000 ) * 1000;
if( outputRaw ) // real quick and dirty
{
static boost::array< char, 16 + timeSize + velodyne::packet::size + 4 > buf;
static const boost::array< char, 2 > start = {{ -78, 85 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
static const boost::array< char, 2 > end = {{ 117, -97 }}; // see QLib::Bytestreams::GetDefaultStartDelimiter()
::memcpy( &buf[0], &start[0], 2 );
::memcpy( &buf[0] + buf.size() - 2, &end[0], 2 );
::memcpy( &buf[0] + 16, &seconds, 8 );
::memcpy( &buf[0] + 16 + 8, &nanoseconds, 4 );
::memcpy( &buf[0] + 16 + 8 + 4, &packet, velodyne::packet::size );
if( publisher ) { publisher->write( &buf[0], buf.size() ); }
else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( &buf[0], buf.size() ), udp_destination ); }
else { std::cout.write( &buf[0], buf.size() ); }
}
else
{
// todo: certainly rewrite with the proper header using comma::packed
static char buf[ timeSize + sizeof( comma::uint16 ) + velodyne::thin::maxBufferSize ];
comma::uint16 size = velodyne::thin::serialize( packet, buf + timeSize + sizeof( comma::uint16 ), scan_id );
bool empty = size == ( sizeof( comma::uint32 ) + 1 ); // todo: atrocious... i.e. packet is not empty; refactor!!!
if( !empty )
{
size += timeSize;
::memcpy( buf, &size, sizeof( comma::uint16 ) );
size += sizeof( comma::uint16 );
::memcpy( buf + sizeof( comma::uint16 ), &seconds, sizeof( comma::int64 ) );
::memcpy( buf + sizeof( comma::uint16 ) + sizeof( comma::int64 ), &nanoseconds, sizeof( comma::int32 ) );
if( publisher ) { publisher->write( buf, size ); }
else if( publisher_udp_socket ) { publisher_udp_socket->send_to( boost::asio::buffer( buf, size ), udp_destination ); }
else { std::cout.write( buf, size ); }
}
else
{
++dropped_count;
}
if( verbose )
{
++count;
compression = 0.9 * compression + 0.1 * ( empty ? 0.0 : double( size + sizeof( comma::int16 ) ) / ( velodyne::packet::size + timeSize ) );
if( count % 10000 == 0 ) { std::cerr << "velodyne-thin: processed " << count << " packets; dropped " << ( double( dropped_count ) * 100. / count ) << "% full packets; compression rate " << compression << std::endl; }
}
}
}
if( publisher ) { publisher->close(); }
std::cerr << "velodyne-thin: " << ( isShutdown ? "signal received" : "no more data" ) << "; shutdown" << std::endl;
}