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


C++ GetPot::unidentified_variables方法代码示例

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


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

示例1: testVariables

  void testVariables()
  {
    CPPUNIT_ASSERT( input.have_variable("Section1/var1") );
    Real var1 = input("Section1/var1", 1.0);
    CPPUNIT_ASSERT_EQUAL( var1, Real(5));

    CPPUNIT_ASSERT( input.have_variable("Section1/SubSection1/var2") );
    std::string var2 = input("Section1/SubSection1/var2", "DIE!");
    CPPUNIT_ASSERT_EQUAL( var2, std::string("blah") );

    // This variable is commented out in the input file so we shouldn't find it.
    CPPUNIT_ASSERT( !input.have_variable("Section2/var3") );
    int var3 = input("Section2/var3", 314);
    CPPUNIT_ASSERT_EQUAL( var3, 314 );

    CPPUNIT_ASSERT( input.have_variable("Section2/Subsection2/var4") );
    bool var4 = input("Section2/Subsection2/var4", true);
    CPPUNIT_ASSERT_EQUAL( var4, false );

    CPPUNIT_ASSERT( input.have_variable("Section2/Subsection2/Subsection3/var5") );
    Real var5 = input("Section2/Subsection2/Subsection3/var5", 3.1415);
    CPPUNIT_ASSERT_EQUAL( var5, Real(6.02e23));

    CPPUNIT_ASSERT( input.have_variable("Section2/Subsection4/var6") );
    unsigned int var6 = input("Section2/Subsection4/var6", 21);
    CPPUNIT_ASSERT_EQUAL( var6, (unsigned int)42 );

    // We didn't use Section3/unused_var so it should be a UFO
    std::vector<std::string> ufos = input.unidentified_variables();
    CPPUNIT_ASSERT_EQUAL( ufos.size(),  (std::vector<std::string>::size_type)1 );
    CPPUNIT_ASSERT_EQUAL( ufos[0], std::string("Section3/unused_var") );
  }
开发者ID:YSB330,项目名称:libmesh,代码行数:32,代码来源:getpot_test.C

示例2: check_for_unused_vars

  void Runner::check_for_unused_vars( const GetPot& input, bool warning_only )
  {
    /* Everything should be set up now, so check if there's any unused variables
       in the input file. If so, then tell the user what they were and error out. */
    std::vector<std::string> unused_vars = input.unidentified_variables();

    bool unused_vars_detected = false;

    // String we use to check if there is a variable in the Materials section
    std::string mat_string = "Materials/";

    // If we do have unused variables, make sure they are in the Materials
    // section since we're allowing those to be present and not used.
    if( !unused_vars.empty() )
      {
        int n_total = unused_vars.size();

        int n_mats = 0;

        for( int v = 0; v < n_total; v++ )
          if( (unused_vars[v]).find(mat_string) != std::string::npos )
            n_mats += 1;

        libmesh_assert_greater_equal( n_total, n_mats );

        if( n_mats < n_total )
          unused_vars_detected = true;
      }

    if( unused_vars_detected )
      {
        libMesh::err << "==========================================================" << std::endl;
        if( warning_only )
          libMesh::err << "Warning: ";
        else
          libMesh::err << "Error: ";

        libMesh::err << "Found unused variables!" << std::endl;

        for( std::vector<std::string>::const_iterator it = unused_vars.begin();
             it != unused_vars.end(); ++it )
          {
            // Don't print out any unused Material variables, since we allow these
            if( (*it).find(mat_string) != std::string::npos )
              continue;

            libMesh::err << *it << std::endl;
          }
        libMesh::err << "==========================================================" << std::endl;

        if( !warning_only )
          libmesh_error();
      }
  }
开发者ID:tradowsk,项目名称:grins,代码行数:54,代码来源:runner.C


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