56 : doc(d), options(opt), datastream(ds) {}
64 std::vector<char>
tok;
68 bool title_found =
false;
70 void ProcessChar(
const char c);
72 void ProcessSeparatorWithinBool();
74 void BeginToken(
const char c);
75 void UpdateComment(
const char c);
76 void UpdateString(
const char c);
77 void UpdateNumber(
const char c);
78 void UpdateBool(
const char c);
79 void UpdateKeyword(
const char c);
80 void UpdateTitle(
const char c);
81 void UpdateGarbage(
const char c);
83 void DiscontinueBool();
84 void DiscontinueNumber();
85 void DiscontinueKeyword();
87 void FlushNumericToken();
273 fmt::format(
"{}, line {}, pos {}: stray character '{}'", datastream->getName(), line_num, line_pos, c));
344 fmt::format(
"{}, line {}, pos {}: quoted string interrupted by newline", datastream->getName(), line_num, line_pos));
420 fmt::format(
"{}, line {}, pos {}: stray character '{}' in string", datastream->getName(), line_num, line_pos, c));
441 this->FlushNumericToken();
454 this->FlushNumericToken();
472 this->FlushNumericToken();
477 this->DiscontinueNumber();
493 this->FlushNumericToken();
498 this->DiscontinueNumber();
512 this->DiscontinueNumber();
527 this->DiscontinueNumber();
540 this->DiscontinueNumber();
570 this->DiscontinueNumber();
580 fmt::format(
"{}, line {}, pos {}: stray character '{}' in number", datastream->getName(), line_num, line_pos, c));
586 this->DiscontinueBool();
587 switch (partial_tok_type)
599 fmt::format(
"{}, line {}, pos {}: discarding incomplete boolean token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
616 this->ProcessSeparatorWithinBool();
621 this->ProcessSeparatorWithinBool();
631 this->ProcessSeparatorWithinBool();
635 this->DiscontinueBool();
644 this->ProcessSeparatorWithinBool();
648 this->DiscontinueBool();
657 this->DiscontinueBool();
666 this->DiscontinueBool();
675 this->DiscontinueBool();
684 this->DiscontinueBool();
693 this->DiscontinueBool();
714 this->DiscontinueBool();
721 this->DiscontinueBool();
730 fmt::format(
"{}, line {}, pos {}: stray character '{}' in boolean", datastream->getName(), line_num, line_pos, c));
789 this->DiscontinueKeyword();
802 this->DiscontinueKeyword();
836 this->DiscontinueKeyword();
845 this->DiscontinueKeyword();
855 fmt::format(
"{}, line {}, pos {}: stray character '{}' in keyword", datastream->getName(), line_num, line_pos, c));
894 fmt::format(
"{}, line {}, pos {}: discarding garbage token '{}'", datastream->getName(), line_num, line_pos, tok.data()));
909 doc.tokens.push_back({ type, (float)doc.string_pool.size() });
911 std::copy(tok.begin(), tok.end(), std::back_inserter(doc.string_pool));
921 doc.tokens.push_back({
TokenType::INT, (float)Ogre::StringConverter::parseInt(tok.data()) });
925 doc.tokens.push_back({
TokenType::FLOAT, (float)Ogre::StringConverter::parseReal(tok.data()) });
933 switch (partial_tok_type)
942 this->UpdateComment(c);
948 this->UpdateString(c);
957 this->UpdateNumber(c);
967 this->UpdateKeyword(c);
971 this->UpdateTitle(c);
975 this->UpdateGarbage(c);
983 switch (partial_tok_type)
996 this->ProcessChar(
' ');
1011 string_pool.clear();
1019 while (!datastream->eof())
1022 for (
size_t i = 0; i < buf_len; i++)
1024 const char c = buf[i];
1032 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
1040 std::string separator;
1041 const char* pool_str =
nullptr;
1042 const size_t BUF_MAX = 100;
1045 for (
Token& tok : tokens)
1055 datastream->write(
";", 1);
1056 pool_str = string_pool.data() + (size_t)tok.data;
1057 datastream->write(pool_str, strlen(pool_str));
1061 datastream->write(separator.data(), separator.size());
1062 pool_str = string_pool.data() + (size_t)tok.data;
1063 datastream->write(pool_str, strlen(pool_str));
1068 datastream->write(separator.data(), separator.size());
1069 snprintf(buf, BUF_MAX,
"%f", tok.data);
1070 datastream->write(buf, strlen(buf));
1075 datastream->write(separator.data(), separator.size());
1076 snprintf(buf, BUF_MAX,
"%d", (
int)tok.data);
1077 datastream->write(buf, strlen(buf));
1082 datastream->write(separator.data(), separator.size());
1083 snprintf(buf, BUF_MAX,
"%s", tok.data == 1.f ?
"true" :
"false");
1084 datastream->write(buf, strlen(buf));
1089 pool_str = string_pool.data() + (size_t)tok.data;
1090 datastream->write(pool_str, strlen(pool_str));
1101 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().openResource(resource_name, resource_group_name);
1102 this->loadFromDataStream(datastream, options);
1105 catch (Ogre::Exception& eeh)
1108 fmt::format(
"GenericDocument: could not load file '{}' from resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1117 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().createResource(resource_name, resource_group_name);
1118 this->saveToDataStream(datastream);
1121 catch (Ogre::Exception& eeh)
1124 fmt::format(
"GenericDocument: could not write file '{}' to resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1139 while (!this->endOfFile() && (this->isTokComment(0) || this->isTokLineBreak(0)))
1144 return this->endOfFile();
1163 token_pos = (int)doc->tokens.size();
1164 for (
int i = 0; i < count; i++)
1172 if (endOfFile(offset))
1175 doc->tokens.insert(doc->tokens.begin() + token_pos + offset, { TokenType::NONE, 0.f });
1181 if (endOfFile(offset))
1187 doc->tokens.erase(doc->tokens.begin() + token_pos + offset);
1193 if (endOfFile(offset))
1199 doc->tokens[token_pos + offset] = { type, (float)doc->string_pool.size() };
1200 std::copy(data.begin(), data.end(), std::back_inserter(doc->string_pool));
1201 doc->string_pool.push_back(
'\0');
1207 if (endOfFile(offset))
1210 doc->tokens[token_pos + offset] = { type, data };