当前位置: 首页>>代码示例>>C++>>正文


C++ TABLE::begin方法代码示例

本文整理汇总了C++中TABLE::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ TABLE::begin方法的具体用法?C++ TABLE::begin怎么用?C++ TABLE::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TABLE的用法示例。


在下文中一共展示了TABLE::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: make_full_report

int hourly_report::make_full_report()
{
  try{
    unsigned long long sum_in = 0;
    unsigned long long sum_out = 0;
    TABLE Tresult;
    TABLE::iterator i;
    ArchFlow archbuf;
    time_t tcur = getnexthour(from) - 1;
    unsigned long client_id = 0;
  
    vlog(LOG_DEBUG, "Timespan: %lu..%lu\n", tcur, to);
    while(tcur < to){
      Tresult[tcur].incoming = 0;
      Tresult[tcur].outcoming = 0;
      tcur = getnexthour(tcur + 1) - 1;
      }
    vlog(LOG_DEBUG, "get client_id\n");
    client_id = get_client_id();
    vlog(LOG_DEBUG, "Seeking for id %lu...", client_id);
    if(0 == cl_seek(f, client_id)){
      fprintf(stderr, "No data for client with id %lu\n", client_id);
      exit(-1);
      }
    vlog(LOG_DEBUG, "done\n");
    if(1 != fread(&archbuf, sizeof(ArchFlow), 1, f)){
      fprintf(stderr, "%s: make_full_report(): fread(): %s\n", prg, strerror(errno));
      exit(-1);
      }
    while(archbuf.client_id == client_id){
      if((time_t)archbuf.timestamp >= from && (time_t)archbuf.timestamp < to){
        tcur = getnexthour(archbuf.timestamp) - 1;
        Tresult[tcur].incoming += ((archbuf.dir == in) ? archbuf.d_octets : 0);
        Tresult[tcur].outcoming += ((archbuf.dir == out) ? archbuf.d_octets : 0);
        }
      if(1 != fread(&archbuf, sizeof(ArchFlow), 1, f)){
        break;
        }
      }
    cout << setw(15) << "Дата" << setw(12) << "Входящий" << setw(12) << "Исходящий" << endl;
    char hour[256];
    struct tm ttm;
    for(i = Tresult.begin(); i != Tresult.end(); i++){
      memcpy(&ttm, localtime(&((*i).first)), sizeof(struct tm));
      strftime(hour, sizeof(hour), "%Y-%m-%d %H", &ttm);
      cout.width(15);
      cout << hour;
      cout.width(12);
      cout << i->second.incoming;
      cout.width(12);
      cout << i->second.outcoming << endl;
      sum_in += i->second.incoming;
      sum_out += i->second.outcoming;
      }
    cout << endl << setw(11) << "Всего:";
    cout.width(12);
    cout << sum_in;
    cout.width(12);
    cout << sum_out << endl;
    return 0;
    }
  catch (Exception er){
    vlog(LOG_ERR, "Error: %s\n", er.what());
    exit(-1);
    }
}
开发者ID:akuzminsky,项目名称:netstore,代码行数:66,代码来源:report.cpp


注:本文中的TABLE::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。