TestGrammar/src/ParseObjects.cpp
// validating basic information on container (stream, arrray, dictionary)
// going through all objects and check
// - type
// - indirect
// - possible value
validating basic information on container (stream, arrray, dictionary)
going through all objects and check
type
indirect
possible value
validating basic information on container ( stream arrray dictionary ) going through all objects and check type indirect possible value
void CParsePDF::check_basics(PdsObject *object, const std::vector<std::string> &vec, const std::string &grammar_file) {
  if ((vec[TSV_INDIRECTREF] == "TRUE") && (object->GetId() == 0) && (object->GetObjectType() != kPdsNull)) {
    output << "Error: not indirect: ";
    output << vec[TSV_KEYNAME] << " (" << grammar_file << ")" << std::endl;
  }
  int index = get_type_index(object, vec[TSV_TYPE]);
  if ((object->GetObjectType() != kPdsNull) && (index == -1) ) {
    int index2 = get_type_index(object, vec[TSV_TYPE]);
    output << "Error: wrong type: " << vec[TSV_KEYNAME] << " (" << grammar_file << ")";
    output << " should be: " << vec[TSV_TYPE] << " and is " << get_type_string(object);
    if (object->GetId() != 0) {
      output << " for object " << object->GetId();
    }
    output << std::endl;
  }
  if (vec[TSV_POSSIBLEVALUES] != "" && index!=-1) {
    std::wstring str_value;
    if (!check_possible_values(object, vec[TSV_POSSIBLEVALUES], index, str_value)) {
      output << "Error: wrong value: " << vec[TSV_KEYNAME] << " (" << grammar_file << ")";
      output << " should be: " << vec[TSV_TYPE] << " " << vec[TSV_POSSIBLEVALUES] << " and is ";
      output << get_type_string(object) << " (" << ToUtf8(str_value) << ")";
      if (object->GetId() != 0) {
        output << " for object " << object->GetId();
      }
      output << std::endl;
    }
  }
}
void CParsePDF :: check_basics ( PdsObject * object , const std :: vector < std :: string > & vec , const std :: string & grammar_file ) { if ( ( vec [ TSV_INDIRECTREF ] == " " ) && ( object -> GetId ( ) == 0 ) && ( object -> GetObjectType ( ) != kPdsNull ) ) { output << " " ; output << vec [ TSV_KEYNAME ] << " " << grammar_file << " " << std :: endl ; } int index = get_type_index ( object , vec [ TSV_TYPE ] ) ; if ( ( object -> GetObjectType ( ) != kPdsNull ) && ( index == -1 ) ) { int index2 = get_type_index ( object , vec [ TSV_TYPE ] ) ; output << " " << vec [ TSV_KEYNAME ] << " " << grammar_file << " " ; output << " " << vec [ TSV_TYPE ] << " " << get_type_string ( object ) ; if ( object -> GetId ( ) != 0 ) { output << " " << object -> GetId ( ) ; } output << std :: endl ; } if ( vec [ TSV_POSSIBLEVALUES ] != " " && index != -1 ) { std :: wstring str_value ; if ( ! check_possible_values ( object , vec [ TSV_POSSIBLEVALUES ] , index , str_value ) ) { output << " " << vec [ TSV_KEYNAME ] << " " << grammar_file << " " ; output << " " << vec [ TSV_TYPE ] << " " << vec [ TSV_POSSIBLEVALUES ] << " " ; output << get_type_string ( object ) << " " << ToUtf8 ( str_value ) << " " ; if ( object -> GetId ( ) != 0 ) { output << " " << object -> GetId ( ) ; } output << std :: endl ; } } }
validating basic information on container (stream, arrray, dictionary)
going through all objects and check
 type
 indirect
 possible value
validating basic information on container ( stream arrray dictionary ) going through all objects and check type indirect possible value
// Treat null object as though the key is not present (i.e. don't report an error) // check type. "null" is always valid and same as not present so ignore. /*&& vec[TSV_TYPE]!="ANY"*/ // possible value, could be one of many  // could be a pattern array;name --- [];[name1,name2] // could be single reference -- name1,name2 // we should cover also single reference in brackets [name1,name2] //std::wstring str_value; //double num_value; //if (object->GetObjectType() == kPdsBoolean) { //  if (((PdsBoolean*)object)->GetValue()) //    str_value = L"TRUE"; //  else str_value = L"FALSE"; //} //if (object->GetObjectType() == kPdsNumber) { //  num_value = ((PdsNumber*)object)->GetValue(); //  //      str_value = std::to_wstring(((PdsNumber*)object)->GetValue()); //} //if (object->GetObjectType() == kPdsName) { //  str_value.resize(((PdsName*)object)->GetText(nullptr, 0)); //  ((PdsName*)object)->GetText((wchar_t*)str_value.c_str(), (int)str_value.size()); //} //if (object->GetObjectType() == kPdsString) { //  str_value.resize(((PdsString*)object)->GetText(nullptr, 0)); //  ((PdsString*)object)->GetText((wchar_t*)str_value.c_str(), (int)str_value.size()); //} //std::vector<std::string> options; //std::string def = vec[TSV_POSSIBLEVALUES]; //if (def[0] == '[') { //  std::vector<std::string> all_defaults = split(vec[TSV_POSSIBLEVALUES], ';'); //  def = all_defaults[index]; //  def = def.substr(1, def.size() - 2); //} //bool is_value = (def.find("value") != std::string::npos) || (def.find("Value") != std::string::npos); //bool is_interval = def.find("<") != std::string::npos; //if (def != "" && !is_value && !is_interval) { //  options = split(def, ','); //  bool found = false; //  for (auto opt : options) //    if (object->GetObjectType() == kPdsNumber) { //      try { //        auto double_val = std::stod(opt); //        if (num_value == double_val) { //          found = true; //          break; //        } //      } //      catch (...) { //        break; //      } //    } //    else //      if (opt == ToUtf8(str_value)) { //        found = true; //        break; //      } //  if (!found) { //    output << "Error: wrong value: " << vec[TSV_KEYNAME] << " (" << grammar_file << ")"; //    output << " should be:" << vec[TSV_POSSIBLEVALUES] << " and is " << ToUtf8(str_value); //    if (object->GetId() != 0) { //      output << " for object " << object->GetId(); //    } //    output << std::endl; //  } //}