56 : doc(d), options(opt), datastream(ds) {}
64 std::vector<char>
tok;
68 bool title_found =
false;
70 void ProcessChar(
const char c);
73 void BeginToken(
const char c);
74 void UpdateComment(
const char c);
75 void UpdateString(
const char c);
76 void UpdateNumber(
const char c);
77 void UpdateBool(
const char c);
78 void UpdateKeyword(
const char c);
79 void UpdateTitle(
const char c);
80 void UpdateGarbage(
const char c);
82 void DiscontinueBool();
83 void DiscontinueNumber();
84 void DiscontinueKeyword();
86 void FlushNumericToken();
272 fmt::format(
"{}, line {}, pos {}: stray character '{}'", datastream->getName(), line_num, line_pos, c));
343 fmt::format(
"{}, line {}, pos {}: quoted string interrupted by newline", datastream->getName(), line_num, line_pos));
419 fmt::format(
"{}, line {}, pos {}: stray character '{}' in string", datastream->getName(), line_num, line_pos, c));
440 this->FlushNumericToken();
453 this->FlushNumericToken();
471 this->FlushNumericToken();
476 this->DiscontinueNumber();
492 this->FlushNumericToken();
497 this->DiscontinueNumber();
511 this->DiscontinueNumber();
526 this->DiscontinueNumber();
539 this->DiscontinueNumber();
569 this->DiscontinueNumber();
579 fmt::format(
"{}, line {}, pos {}: stray character '{}' in number", datastream->getName(), line_num, line_pos, c));
596 fmt::format(
"{}, line {}, pos {}: discarding incomplete boolean token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
606 fmt::format(
"{}, line {}, pos {}: discarding incomplete boolean token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
621 fmt::format(
"{}, line {}, pos {}: discarding incomplete boolean token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
639 fmt::format(
"{}, line {}, pos {}: discarding incomplete boolean token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
654 this->DiscontinueBool();
663 this->DiscontinueBool();
672 this->DiscontinueBool();
681 this->DiscontinueBool();
690 this->DiscontinueBool();
711 this->DiscontinueBool();
718 this->DiscontinueBool();
727 fmt::format(
"{}, line {}, pos {}: stray character '{}' in boolean", datastream->getName(), line_num, line_pos, c));
786 this->DiscontinueKeyword();
799 this->DiscontinueKeyword();
833 this->DiscontinueKeyword();
842 this->DiscontinueKeyword();
852 fmt::format(
"{}, line {}, pos {}: stray character '{}' in keyword", datastream->getName(), line_num, line_pos, c));
891 fmt::format(
"{}, line {}, pos {}: discarding garbage token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
906 doc.tokens.push_back({ type, (float)doc.string_pool.size() });
908 std::copy(tok.begin(), tok.end(), std::back_inserter(doc.string_pool));
916 doc.tokens.push_back({
TokenType::NUMBER, (float)Ogre::StringConverter::parseReal(tok.data()) });
923 switch (partial_tok_type)
932 this->UpdateComment(c);
938 this->UpdateString(c);
947 this->UpdateNumber(c);
957 this->UpdateKeyword(c);
961 this->UpdateTitle(c);
965 this->UpdateGarbage(c);
973 switch (partial_tok_type)
986 this->ProcessChar(
' ');
1001 string_pool.clear();
1009 while (!datastream->eof())
1012 for (
size_t i = 0; i < buf_len; i++)
1014 const char c = buf[i];
1022 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
1030 std::string separator;
1031 const char* pool_str =
nullptr;
1032 const size_t BUF_MAX = 100;
1035 for (
Token& tok : tokens)
1045 datastream->write(
";", 1);
1046 pool_str = string_pool.data() + (size_t)tok.data;
1047 datastream->write(pool_str, strlen(pool_str));
1051 datastream->write(separator.data(), separator.size());
1052 pool_str = string_pool.data() + (size_t)tok.data;
1053 datastream->write(pool_str, strlen(pool_str));
1058 datastream->write(separator.data(), separator.size());
1059 snprintf(buf, BUF_MAX,
"%f", tok.data);
1060 datastream->write(buf, strlen(buf));
1065 datastream->write(separator.data(), separator.size());
1066 snprintf(buf, BUF_MAX,
"%s", tok.data == 1.f ?
"true" :
"false");
1067 datastream->write(buf, strlen(buf));
1072 pool_str = string_pool.data() + (size_t)tok.data;
1073 datastream->write(pool_str, strlen(pool_str));
1084 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().openResource(resource_name, resource_group_name);
1085 this->loadFromDataStream(datastream, options);
1088 catch (Ogre::Exception& eeh)
1091 fmt::format(
"GenericDocument: could not load file '{}' from resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1100 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().createResource(resource_name, resource_group_name);
1101 this->saveToDataStream(datastream);
1104 catch (Ogre::Exception& eeh)
1107 fmt::format(
"GenericDocument: could not write file '{}' to resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1121 while (!this->endOfFile() && !this->isTokString() && !this->isTokFloat() && !this->isTokBool() && !this->isTokKeyword())
1126 return this->endOfFile();
1142 if (endOfFile(offset))
1145 doc->tokens.insert(doc->tokens.begin() + token_pos + offset, { TokenType::NONE, 0.f });
1151 if (endOfFile(offset))
1157 doc->tokens.erase(doc->tokens.begin() + token_pos + offset);
1163 if (endOfFile(offset))
1169 doc->tokens[token_pos + offset] = { type, (float)doc->string_pool.size() };
1170 std::copy(data.begin(), data.end(), std::back_inserter(doc->string_pool));
1171 doc->string_pool.push_back(
'\0');
1177 if (endOfFile(offset))
1180 doc->tokens[token_pos + offset] = { type, data };