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


C++ To::correct方法代码示例

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


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

示例1: Error

/* Dynamic constructor returns a pointer to a new instance of one of the
   Archive derived classes.   Derived classes must be registered using
   an Archive::Agent.

   \param filename path to the file containing a pulsar archive

   Note: the definition of this static member function is contained in a 
   source code file separate from all other archive methods so that it will
   be linked into executables only when called directly.
*/
Pulsar::Archive* Pulsar::Archive::load (const string& filename)
{
  string use_filename = expand (filename);

  // check if file can be opened for reading
  FILE* fptr = fopen (use_filename.c_str(), "r");

  if (!fptr) throw Error (FailedSys, "Pulsar::Archive::load",
			  "cannot open '%s'", use_filename.c_str());
  fclose (fptr);

  Registry::List<Agent>& registry = Registry::List<Agent>::get_registry();
  
  if (registry.size() == 0)
    throw Error (InvalidState, "Pulsar::Archive::load", "no Agents loaded");

  // see if any of the derived classes recognize the file
  Reference::To<Archive> archive;

  if (verbose == 3)
    cerr << "Pulsar::Archive::load with " << registry.size() 
         << " Agents" << endl;

  for (unsigned agent=0; agent<registry.size(); agent++) try {

    if (verbose == 3)
      cerr << "Pulsar::Archive::load testing "
           << registry[agent]->get_name() << endl;

    if (registry[agent]->advocate (use_filename.c_str())) {

      if (verbose == 3)
        cerr << "Pulsar::Archive::load using " 
	     << registry[agent]->get_name() << endl;

      archive = registry[agent]->new_Archive();
      
      archive -> __load_filename = use_filename;
      archive -> load_header (use_filename.c_str());
      archive -> set_filename (use_filename);

      // perform all checks
      archive->correct();

      return archive.release();

    }

  }
  catch (Error& error) {
    if (verbose == 3)
      cerr << "Pulsar::Archive::load error " << error << endl;
    throw error += "Pulsar::Archive::load";
  }
  catch (string& error) {
    throw Error (FailedCall, "Pulsar::Archive::load", error);
  }
  
  // none of the registered agents advocates the use of a derived
  // class for the interpretation of this file
  throw Error (InvalidParam, "Pulsar::Archive::load", 
	       "'%s' not a recognized file format", use_filename.c_str());
}
开发者ID:SkyTian13,项目名称:psrchive,代码行数:73,代码来源:Archive_load.C


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