本文整理汇总了C++中time_duration类的典型用法代码示例。如果您正苦于以下问题:C++ time_duration类的具体用法?C++ time_duration怎么用?C++ time_duration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了time_duration类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: to_minutes
int User::to_minutes(time_duration duration)
{
return duration.total_seconds() / 60;
}
开发者ID:kire321,项目名称:d4d,代码行数:4,代码来源:user.cpp
示例2: localTime
int64_t localTime() {
static const ptime epoch(date(1970, 1, 1));
const time_duration diff = second_clock::local_time() - epoch;
return diff.total_seconds();
}
开发者ID:eamsen,项目名称:transit-planner,代码行数:5,代码来源:Utilities.cpp
示例3: seconds
namespace obelisk {
using namespace bc;
using namespace boost::posix_time;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
using std::placeholders::_4;
const time_duration retry_start_duration = seconds(30);
void log_to_file(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
if (body.empty())
return;
if (!log_requests && domain == LOG_REQUEST)
return;
file << level_repr(level);
if (!domain.empty())
file << " [" << domain << "]";
file << ": " << body << std::endl;
}
void log_to_both(std::ostream& device, std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
if (body.empty())
return;
if (!log_requests && domain == LOG_REQUEST)
return;
std::ostringstream output;
output << level_repr(level);
if (!domain.empty())
output << " [" << domain << "]";
output << ": " << body;
device << output.str() << std::endl;
file << output.str() << std::endl;
}
void output_file(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
log_to_file(file, level, domain, body, log_requests);
}
void output_both(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
log_to_both(std::cout, file, level, domain, body, log_requests);
}
void error_file(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
log_to_file(file, level, domain, body, log_requests);
}
void error_both(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
log_to_both(std::cerr, file, level, domain, body, log_requests);
}
node_impl::node_impl()
: network_pool_(1), disk_pool_(6), mem_pool_(1),
hosts_(network_pool_),
handshake_(network_pool_),
network_(network_pool_),
protocol_(network_pool_, hosts_, handshake_, network_),
chain_(disk_pool_),
poller_(mem_pool_, chain_),
txpool_(mem_pool_, chain_),
indexer_(mem_pool_),
session_(mem_pool_, {
handshake_, protocol_, chain_, poller_, txpool_}),
retry_start_timer_(mem_pool_.service())
{
}
bool node_impl::start(config_type& config)
{
auto file_mode = std::ofstream::out | std::ofstream::app;
outfile_.open(config.output_file, file_mode);
errfile_.open(config.error_file, file_mode);
log_debug().set_output_function(
std::bind(output_file, std::ref(outfile_),
_1, _2, _3, config.log_requests));
log_info().set_output_function(
std::bind(output_both, std::ref(outfile_),
_1, _2, _3, config.log_requests));
log_warning().set_output_function(
std::bind(error_file, std::ref(errfile_),
_1, _2, _3, config.log_requests));
log_error().set_output_function(
std::bind(error_both, std::ref(errfile_),
_1, _2, _3, config.log_requests));
log_fatal().set_output_function(
std::bind(error_both, std::ref(errfile_),
_1, _2, _3, config.log_requests));
protocol_.subscribe_channel(
std::bind(&node_impl::monitor_tx, this, _1, _2));
// Start blockchain.
//.........这里部分代码省略.........
开发者ID:BWallet,项目名称:obelisk,代码行数:101,代码来源:node_impl.cpp
示例4: toStringSec
string TimerStructs::toStringSec(time_duration & duration) {
return padded2DString(duration.seconds());
}
开发者ID:s12chung,项目名称:stopnow_c_plus_plus,代码行数:3,代码来源:Structs.cpp
示例5: str2time
int64_t str2time(const string& str) {
static const ptime epoch(date(1970, 1, 1));
const ptime string_time = from_iso_string(str);
const time_duration diff = string_time - epoch;
return diff.total_seconds();
}
开发者ID:eamsen,项目名称:transit-planner,代码行数:6,代码来源:Utilities.cpp
示例6: toStringMin
string TimerStructs::toStringMin(time_duration & duration) {
return padded2DString(duration.minutes());
}
开发者ID:s12chung,项目名称:stopnow_c_plus_plus,代码行数:3,代码来源:Structs.cpp
示例7: toStringHour
string TimerStructs::toStringHour(time_duration & duration) {
return padded2DString(duration.hours());
}
开发者ID:s12chung,项目名称:stopnow_c_plus_plus,代码行数:3,代码来源:Structs.cpp
示例8: insert
void ParametersMap::insert(
const std::string& parameterName,
const time_duration& value
){
insert(parameterName, value.is_not_a_date_time() ? string() : to_simple_string(value));
}
开发者ID:Tisseo,项目名称:synthese,代码行数:6,代码来源:ParametersMap.cpp
示例9: glGetIntegerv
//.........这里部分代码省略.........
for(;;) {
hm = orghm->GetLevel(-level);
w=hm->w-1;
GLint maxw;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxw);
if (w > maxw) level ++;
else break;
}
shadowLevelDif=0;
Heightmap *shadowhm = orghm->GetLevel(-(level+shadowLevelDif));
int shadowScale=1<<shadowLevelDif;
int shadowW=shadowhm->w-1;
assert (w/shadowW == shadowScale);
//float org2c = w/float(orghm->w-1);
//float c2org = (float)(orghm->w-1)/w;
float *centerhm = new float[w*w];
Vector3 *shading = new Vector3[w*w];
for (int y=0;y<w;y++)
for (int x=0;x<w;x++) {
centerhm[y*w+x] =/* hm->scale * */ 0.25f * ( (int)hm->at(x,y)+ (int)hm->at(x+1,y)+ (int)hm->at(x,y+1) + (int)hm->at(x+1,y+1) ); //+ hm->offset;
shading[y*w+x] = li->ambient;
}
uchar *lightMap = new uchar[shadowW*shadowW];
for (std::vector<StaticLight>::const_iterator l=li->staticLights.begin();l!=li->staticLights.end();++l)
{
float lightx;
float lighty;
if (l->directional) {
lightx = l->position.x;
lighty = l->position.y;
} else {
lightx = (int)(l->position.x / shadowhm->squareSize);
lighty = (int)(l->position.z / shadowhm->squareSize);
}
CalculateShadows(lightMap, shadowW, lightx, lighty,
l->position.y, centerhm, w, shadowScale, l->directional);
for (int y=0;y<w;y++)
{
for (int x=0;x<w;x++)
{
if (!lightMap[(y*shadowW+x)/shadowScale])
continue;
Vector3 wp;
if (l->directional)
wp = l->position;
else
wp = l->position - Vector3((x+0.5f)*hm->squareSize,centerhm[y*w+x],(y+0.5f)*hm->squareSize);
uchar* normal = hm->GetNormal (x,y);
Vector3 normv((2 * (int)normal[0] - 256)/255.0f, (2 * (int)normal[1] - 256)/255.0f, (2 * (int)normal[2] - 256)/255.0f);
wp.ANormalize();
float dot = wp.dot(normv);
if(dot < 0.0f) dot = 0.0f;
if(dot > 1.0f) dot = 1.0f;
dot *= lightMap[(y*shadowW+x)/shadowScale]*(1.0f/255.0f);
shading[y*w+x] += l->color * dot;
}
}
}
delete[] lightMap;
glGenTextures(1,&shadingTex);
glBindTexture (GL_TEXTURE_2D, shadingTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
uchar *shadingTexData=new uchar[w*w*4];
for(int y=0;y<w;y++) {
for (int x=0;x<w;x++) {
shadingTexData[(y*w+x)*4+0] = (uchar)(min(1.0f, shading[y*w+x].x) * 255);
shadingTexData[(y*w+x)*4+1] = (uchar)(min(1.0f, shading[y*w+x].y) * 255);
shadingTexData[(y*w+x)*4+2] = (uchar)(min(1.0f, shading[y*w+x].z) * 255);
shadingTexData[(y*w+x)*4+3] = CReadMap::EncodeHeight(centerhm[w*y+x]);
}
}
SaveImage ("lightmap.png", 4, IL_UNSIGNED_BYTE, w,w, shadingTexData);
glBuildMipmaps(GL_TEXTURE_2D, 4, w,w, GL_RGBA, GL_UNSIGNED_BYTE, shadingTexData);
delete[] shadingTexData;
id = shadingTex;
delete[] shading;
delete[] centerhm;
const time_duration numTicks = microsec_clock::local_time() - startTicks;
d_trace ("Lightmap generation: %2.3f seconds\n", numTicks.total_milliseconds() * 0.001f);
}
开发者ID:Gepard,项目名称:spring,代码行数:101,代码来源:Lightcalc.cpp
示例10: seconds
namespace server {
using namespace bc::chain;
using namespace bc::node;
using namespace boost::posix_time;
using boost::format;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
using std::placeholders::_4;
const time_duration retry_start_duration = seconds(30);
constexpr auto append = std::ofstream::out | std::ofstream::app;
server_node::server_node(settings_type& config)
: outfile_(config.debug_file.string(), append),
errfile_(config.error_file.string(), append),
// Threadpools, the number of threads they spawn and priorities.
network_pool_(1, thread_priority::normal),
disk_pool_(6, thread_priority::low),
mem_pool_(1, thread_priority::low),
// Networking related services.
hosts_(network_pool_, config.hosts_file.string(), 1000),
handshake_(network_pool_),
network_(network_pool_),
protocol_(network_pool_, hosts_, handshake_, network_,
config.out_connections),
// Blockchain database service.
chain_(disk_pool_, config.blockchain_path.string(),
{ config.history_height }, 20),
// Poll new blocks, tx memory pool and tx indexer.
poller_(mem_pool_, chain_),
txpool_(mem_pool_, chain_, config.tx_pool_capacity),
indexer_(mem_pool_),
// Session manager service.
session_(mem_pool_, handshake_, protocol_, chain_, poller_, txpool_),
retry_start_timer_(mem_pool_.service())
{
}
bool server_node::start(settings_type& config)
{
// Set up logging for node background threads (add to config).
const auto skip_log = if_else(config.log_requests, "", LOG_REQUEST);
initialize_logging(outfile_, errfile_, bc::cout, bc::cerr, skip_log);
// Start blockchain.
if (!chain_.start())
{
log_error(LOG_NODE) << "Couldn't start blockchain.";
return false;
}
chain_.subscribe_reorganize(
std::bind(&server_node::reorganize, this, _1, _2, _3, _4));
// Start transaction pool
txpool_.start();
// Outgoing connections setting in config file before we
// start p2p network subsystem.
protocol_.set_hosts_filename(config.hosts_file.string());
if (!config.listener_enabled)
protocol_.disable_listener();
for (const auto& endpoint: config.peers)
{
const auto host = endpoint.get_host();
const auto port = endpoint.get_port();
log_info(LOG_NODE) << "Adding node: " << host << " " << port;
protocol_.maintain_connection(host, port);
}
start_session();
return true;
}
void server_node::start_session()
{
// Start session
const auto session_started = [this](const std::error_code& ec)
{
if (ec)
wait_and_retry_start(ec);
};
session_.start(session_started);
}
void server_node::wait_and_retry_start(const std::error_code& ec)
{
BITCOIN_ASSERT(ec);
log_error(LOG_NODE) << "Unable to start session: " << ec.message();
log_error(LOG_NODE) << "Retrying in "
<< retry_start_duration.seconds() << " seconds.";
retry_start_timer_.expires_from_now(retry_start_duration);
retry_start_timer_.async_wait(
std::bind(&server_node::start_session, this));
//.........这里部分代码省略.........
开发者ID:libmetrocoin,项目名称:libmetrocoin-server,代码行数:101,代码来源:server_node.cpp
注:本文中的time_duration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论