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));
919 doc.tokens.push_back({
TokenType::NUMBER, (float)Ogre::StringConverter::parseReal(tok.data()) });
926 switch (partial_tok_type)
935 this->UpdateComment(c);
941 this->UpdateString(c);
950 this->UpdateNumber(c);
960 this->UpdateKeyword(c);
964 this->UpdateTitle(c);
968 this->UpdateGarbage(c);
976 switch (partial_tok_type)
989 this->ProcessChar(
' ');
1004 string_pool.clear();
1012 while (!datastream->eof())
1015 for (
size_t i = 0; i < buf_len; i++)
1017 const char c = buf[i];
1025 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
1033 std::string separator;
1034 const char* pool_str =
nullptr;
1035 const size_t BUF_MAX = 100;
1038 for (
Token& tok : tokens)
1048 datastream->write(
";", 1);
1049 pool_str = string_pool.data() + (size_t)tok.data;
1050 datastream->write(pool_str, strlen(pool_str));
1054 datastream->write(separator.data(), separator.size());
1055 pool_str = string_pool.data() + (size_t)tok.data;
1056 datastream->write(pool_str, strlen(pool_str));
1061 datastream->write(separator.data(), separator.size());
1062 snprintf(buf, BUF_MAX,
"%f", tok.data);
1063 datastream->write(buf, strlen(buf));
1068 datastream->write(separator.data(), separator.size());
1069 snprintf(buf, BUF_MAX,
"%s", tok.data == 1.f ?
"true" :
"false");
1070 datastream->write(buf, strlen(buf));
1075 pool_str = string_pool.data() + (size_t)tok.data;
1076 datastream->write(pool_str, strlen(pool_str));
1087 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().openResource(resource_name, resource_group_name);
1088 this->loadFromDataStream(datastream, options);
1091 catch (Ogre::Exception& eeh)
1094 fmt::format(
"GenericDocument: could not load file '{}' from resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1103 Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().createResource(resource_name, resource_group_name);
1104 this->saveToDataStream(datastream);
1107 catch (Ogre::Exception& eeh)
1110 fmt::format(
"GenericDocument: could not write file '{}' to resource group '{}': {}", resource_name, resource_group_name, eeh.getDescription()));
1124 while (!this->endOfFile() && !this->isTokString() && !this->isTokFloat() && !this->isTokBool() && !this->isTokKeyword())
1129 return this->endOfFile();
1145 if (endOfFile(offset))
1148 doc->tokens.insert(doc->tokens.begin() + token_pos + offset, { TokenType::NONE, 0.f });
1154 if (endOfFile(offset))
1160 doc->tokens.erase(doc->tokens.begin() + token_pos + offset);
1166 if (endOfFile(offset))
1172 doc->tokens[token_pos + offset] = { type, (float)doc->string_pool.size() };
1173 std::copy(data.begin(), data.end(), std::back_inserter(doc->string_pool));
1174 doc->string_pool.push_back(
'\0');
1180 if (endOfFile(offset))
1183 doc->tokens[token_pos + offset] = { type, data };