⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getpot.h

📁 一个用来实现偏微分方程中网格的计算库
💻 H
📖 第 1 页 / 共 5 页
字号:
    // error    if( Var->name == "" ) {          // make a copy of the string if an error occured      // (since the error variable is a static variable inside get_variable())      return std::string(Var->original);    }    double x = __convert_to_type(A[1], 1e37);    // last element is always the default argument    if (x == 1e37 || x < 0 || x >= Var->value.size() )      return "<<1st index out of range>>";    if ( A.size() > 2) {      double y = __convert_to_type(A[2], 1e37);      int    begin = int(x+0.5);      int    end = 0;      if ( y != 1e37 && y > 0 && y <= Var->value.size() && y > x)	end = int(y+1.5);      else if( y == -1 )	end = Var->value.size();      else	return "<<2nd index out of range>>";	    	          std::string result = *(Var->get_element(begin));      for(int i = begin+1; i < end; i++) 	result += std::string(" ") + *(Var->get_element(i));      return result;    }    else      return *(Var->get_element(int(x+0.5)));  }  const std::vector<std::string>    A = __DBE_get_expr_list(expr, 1);  const GetPot::variable* B = __DBE_get_variable(A[0]);  // make a copy of the string if an error occured  // (since the error variable is a static variable inside get_variable())  if( B->name == "" )    return std::string(B->original);    //else  return B->original;}///////////////////////////////////////////////////////////////////////////////// (*) unidentified flying objects//.............................................................................//inline boolGetPot::__search_string_vector(const std::vector<std::string>& VecStr, const std::string& Str) const{  victorate(std::string, VecStr, itk) {    if( *itk == Str ) return true;  }  return false;}#ifdef GETPOT_ALLOW_VARGS  inline std::vector<std::string>   GetPot::unidentified_arguments(unsigned Number,       const char* KnownArgument1, ...) const  {    std::vector<std::string> known_arguments;      // (1) create a vector of known arguments    if( Number == 0 ) return std::vector<std::string>();      std::va_list ap;    va_start(ap, KnownArgument1);    known_arguments.push_back(std::string(KnownArgument1));    for(unsigned i=1; i<Number; i++)      known_arguments.push_back(std::string(va_arg(ap, char *)));    va_end(ap);      return unidentified_arguments(known_arguments);  }      inline std::vector<std::string>   GetPot::unidentified_options(unsigned Number,       const char* KnownOption1, ...) const  {    std::vector<std::string> known_options;      // (1) create a vector of known arguments    if( Number == 0 ) return std::vector<std::string>();      std::va_list ap;    va_start(ap, KnownOption1);    known_options.push_back(std::string(KnownOption1));    for(unsigned i=1; i<Number; i++)      known_options.push_back(std::string(va_arg(ap, char *)));    va_end(ap);      return unidentified_options(known_options);  }    inline std::vector<std::string>   GetPot::unidentified_variables(unsigned Number,     const char* KnownVariable1, ...) const  {    std::vector<std::string> known_variables;      // create vector of known arguments    if( Number == 0 ) return std::vector<std::string>();      std::va_list ap;    va_start(ap, KnownVariable1);    known_variables.push_back(std::string(KnownVariable1));    for(unsigned i=1; i<Number; i++)      known_variables.push_back(std::string(va_arg(ap, char *)));    va_end(ap);      return unidentified_variables(known_variables);  }    inline std::vector<std::string>   GetPot::unidentified_sections(unsigned Number,       const char* KnownSection1, ...) const  {    std::vector<std::string> known_sections;      // (1) create a vector of known arguments    if( Number == 0 ) return std::vector<std::string>();      std::va_list ap;    va_start(ap, KnownSection1);    known_sections.push_back(std::string(KnownSection1));    for(unsigned i=1; i<Number; i++) {      std::string tmp = std::string(va_arg(ap, char *));      if( tmp.length() == 0 ) continue;      if( tmp[tmp.length()-1] != '/' ) tmp += '/';      known_sections.push_back(tmp);    }    va_end(ap);      return unidentified_sections(known_sections);  }    inline std::vector<std::string>   GetPot::unidentified_nominuses(unsigned Number, const char* Known, ...) const  {    std::vector<std::string> known_nominuses;      // create vector of known arguments    if( Number == 0 ) return std::vector<std::string>();      std::va_list ap;    va_start(ap, Known);    known_nominuses.push_back(std::string(Known));    for(unsigned i=1; i<Number; i++) {      std::string tmp = std::string(va_arg(ap, char *));      if( tmp.length() == 0 ) continue;      known_nominuses.push_back(tmp);    }    va_end(ap);      return unidentified_nominuses(known_nominuses);  }  #endif //GETPOT_ALLOW_VARGSinline std::stringGetPot::unidentified_flags(const char* KnownFlagList, int ArgumentNumber=-1) const// Two modes://  ArgumentNumber >= 0 check specific argument //  ArgumentNumber == -1 check all options starting with one '-' //                       for flags{  std::string         ufos;  std::vector<std::string> known_arguments;  std::string         KFL(KnownFlagList);  // (2) iteration over '-' arguments (options)  if( ArgumentNumber == -1 ) {    std::vector<std::string>::const_iterator it = argv.begin();    it++; // forget about argv[0] (application or filename)    for(; it != argv.end(); it++) {      // -- argument belongs to prefixed section ?      const std::string arg = __get_remaining_string(*it, prefix);      if( arg == "" ) continue;      // -- does arguments start with '-' (but not '--')      if     ( arg.length() < 2 ) continue;      else if( arg[0] != '-' )    continue;      else if( arg[1] == '-' )    continue;      // -- check out if flags inside option are contained in KnownFlagList      const char* p=arg.c_str();      p++; // skip starting minus      for(; *p != '\0' ; p++)	if( KFL.find(*p) == std::string::npos ) ufos += *p;    }  }  // (1) check specific argument  else {    // -- only check arguments that start with prefix    int no_matches = 0;    for(unsigned i=1; i<argv.size(); i++) {      const std::string Remain = __get_remaining_string(argv[i], prefix);      if( Remain != "") {	no_matches++;	if( no_matches == ArgumentNumber) {	  // -- the right argument number inside the section is found	  // => check it for flags	  const char* p = Remain.c_str();	  p++; // skip starting minus	  for(; *p != '\0' ; p++)	    if( KFL.find(*p) == std::string::npos ) ufos += *p;	  return ufos;	}      }    }  }  return ufos;}inline std::vector<std::string> GetPot::unidentified_arguments(const std::vector<std::string>& Knowns) const{  std::vector<std::string> ufos;  std::vector<std::string>::const_iterator it = argv.begin();  it++; // forget about argv[0] (application or filename)  for(; it != argv.end(); it++) {    // -- argument belongs to prefixed section ?    const std::string arg = __get_remaining_string(*it, prefix);    if( arg == "" ) continue;    // -- check if in list    if( __search_string_vector(Knowns, arg) == false)      ufos.push_back(*it);  }  return ufos;}inline std::vector<std::string> GetPot::unidentified_options(const std::vector<std::string>& Knowns) const{  std::vector<std::string> ufos;  std::vector<std::string>::const_iterator it = argv.begin();  it++; // forget about argv[0] (application or filename)  for(; it != argv.end(); it++) {    // -- argument belongs to prefixed section ?    const std::string arg = __get_remaining_string(*it, prefix);    if( arg == "" ) continue;    // is argument really an option (starting with '-') ?    if( arg.length() < 1 || arg[0] != '-' ) continue;    if( __search_string_vector(Knowns, arg) == false)      ufos.push_back(*it);  }  return ufos;}inline std::vector<std::string> GetPot::unidentified_variables(const std::vector<std::string>& Knowns) const{  std::vector<std::string> ufos;  victorate(GetPot::variable, variables, it) {    // -- check if variable has specific prefix    const std::string var_name = __get_remaining_string((*it).name, prefix);    if( var_name == "" ) continue;    // -- check if variable is known    if( __search_string_vector(Knowns, var_name) == false)      ufos.push_back((*it).name);  }  return ufos;    }inline std::vector<std::string> GetPot::unidentified_sections(const std::vector<std::string>& Knowns) const{  std::vector<std::string> ufos;  victorate(std::string, section_list, it) {    // -- check if section conform to prefix    const std::string sec_name = __get_remaining_string(*it, prefix);    if( sec_name == "" ) continue;    // -- check if section is known    if( __search_string_vector(Knowns, sec_name) == false )      ufos.push_back(*it);  }  return ufos;    }inline std::vector<std::string> GetPot::unidentified_nominuses(const std::vector<std::string>& Knowns) const{  std::vector<std::string> ufos;  // (2) iterate over all arguments   std::vector<std::string>::const_iterator it = argv.begin();  it++; // forget about argv[0] (application or filename)  for(; it != argv.end(); it++) {    // -- check if nominus part of prefix    const std::string arg = __get_remaining_string(*it, prefix);    if( arg == "" ) continue;    if( arg.length() < 1 )                                  continue;    // option ? --> not a nomius     if( arg[0] == '-' )                                     continue;    // section ? --> not a real nominus    if( arg[0] == '[' && arg[arg.length()-1] == ']' ) continue;    // variable definition ? --> not a real nominus    bool continue_f = false;    for(unsigned i=0; i<arg.length() ; i++)      if( arg[i] == '=' ) { continue_f = true; break; }    if( continue_f )                                           continue;    // real nominuses are compared with the given list    if( __search_string_vector(Knowns, arg) == false )      ufos.push_back(*it);  }      return ufos;}///////////////////////////////////////////////////////////////////////////////// (*) variable class//.............................................................................//inlineGetPot::variable::variable(){}inlineGetPot::variable::variable(const variable& Other){ #ifdef WIN32  operator=(Other); #else  GetPot::variable::operator=(Other); #endif}inlineGetPot::variable::variable(const char* Name, const char* Value): name(Name) {   // make a copy of the 'Value'  take(Value);}inline const std::string*GetPot::variable::get_element(unsigned Idx) const{ if( Idx >= value.size() ) return 0; else return &(value[Idx]); }inline voidGetPot::variable::take(const char* Value){   original = std::string(Value);  // separate string by white space delimiters using 'strtok'  // thread safe usage of strtok (no static members)  char* spt = 0;   // make a copy of the 'Value'  char* copy = new char[std::strlen(Value)+1];  std::strcpy(copy, Value);  char* follow_token = strtok_r(copy, " \t\n", &spt);  if( value.size() != 0 ) value.erase(value.begin(), value.end());  while(follow_token != 0) {    value.push_back(std::string(follow_token));    follow_token = strtok_r(NULL, " \t\n", &spt);  }  delete [] copy;}inlineGetPot::variable::~variable(){}inline GetPot::variable& GetPot::variable::operator=(const GetPot::variable& Other){  if( &Other != this) {    name     = Other.name;    value    = Other.value;    original = Other.original;  }  return *this;}//using namespace __GetPot_namespace__;#undef victorate#undef reduce#endif // __GETPOT_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -