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


C++ KeyValue::close方法代码示例

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


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

示例1: run

void run ()
{

  const std::string path = argument[0];

  Tractography::Properties properties;
  Tractography::Reader<float> reader (path, properties);

  size_t init_count = 0;
  if (properties.find ("count") == properties.end()) {
    INFO ("\"count\" field not set in file " + path);
  } else {
    init_count = to<size_t>(properties["count"]);
    INFO ("Value of \"count\" in file " + path + " is " + str(init_count));
  }

  // Read the actual number of streamlines in the file
  Tractography::Streamline<float> tck;
  size_t count = 0;
  {
    ProgressBar progress ("evaluating actual streamline data count...");
    while (reader (tck)) {
      ++count;
      ++progress;
    }
  }
  reader.close();
  INFO ("Actual number of streamlines read is " + str(count));

  // Find the appropriate file offset in the header
  KeyValue kv (argument[0], "mrtrix tracks");
  std::string data_file;
  int64_t count_offset = 0;
  int64_t current_offset = 0;
  while (kv.next()) {
    std::string key = lowercase (kv.key());
    if (key == "count")
      count_offset = current_offset;
    current_offset = kv.tellg();
  }
  kv.close();

  if (!count_offset)
    throw Exception ("could not find location of \"count\" field in file \"" + path + "\"");
  DEBUG ("File offset for \"count\" field is " + str(count_offset));

  // Overwrite this data
  // Used C-style file access here as ofstream would either wipe the file contents, or
  //   append the data instead of inserting it
  FILE* fp;
  fp = fopen (path.c_str(), "r+");
  if (!fp)
    throw Exception ("could not open tracks file \"" + path + "\" for repair");
  if (fseek (fp, count_offset, SEEK_SET)) {
    fclose (fp);
    throw Exception ("unable to seek to the appropriate position in the file");
  }
  const std::string string = "count: " + str(count) + "\ntotal_count: " + str(count) + "\nEND\n";
  const int rvalue = fputs (string.c_str(), fp);
  fclose (fp);
  if (rvalue == EOF) {
    WARN ("\"count\" field may not have been properly updated");
  } else {
    INFO ("\"count\" field updated successfully");
  }

}
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:67,代码来源:tckfixcount.cpp


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