diff --git a/projs/shadow-file-format/src/SFFElement.cpp b/projs/shadow-file-format/src/SFFElement.cpp index f8d01ec..05d0844 100644 --- a/projs/shadow-file-format/src/SFFElement.cpp +++ b/projs/shadow-file-format/src/SFFElement.cpp @@ -1,37 +1,15 @@ -module; - -import ; - -import shadow_utils; +/* +module; module Shadow.FileFormat:SFFElement; +import ; +import shadow_utils; namespace Shadow::SFF { - SFFElement* SFFElement::GetFirstChild() - { - return children.size() > 0 ? children.begin()->second : nullptr; - } - SFFElement* SFFElement::GetChildByIndex(int index) - { - ChildrenMap::iterator it = children.begin(); - for (size_t i = 0; i < index; i++) - { - it++; - } - return it->second; - } - SFFElement* SFFElement::GetChildByName(std::string name) - { - ChildrenMap::iterator it = children.find(name); - if (it != children.end()) { - return it->second; - } - return nullptr; - } - -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/projs/shadow-file-format/src/SFFElement.ixx b/projs/shadow-file-format/src/SFFElement.ixx index 7098821..85a7112 100644 --- a/projs/shadow-file-format/src/SFFElement.ixx +++ b/projs/shadow-file-format/src/SFFElement.ixx @@ -1,15 +1,14 @@ module; +export module Shadow.FileFormat:SFFElement; + import ; import ; import ; -export module Shadow.FileFormat:SFFElement; + namespace Shadow::SFF { - -export namespace Shadow::SFF { - - class SFFElement + export class SFFElement { public: SFFElement* parent; @@ -26,12 +25,29 @@ export namespace Shadow::SFF { std::string GetStringProperty(std::string name); + SFFElement* GetFirstChild() + { + return children.size() > 0 ? children.begin()->second : nullptr; + } - SFFElement* GetFirstChild(); + SFFElement* GetChildByIndex(int index) + { + ChildrenMap::iterator it = children.begin(); + for (size_t i = 0; i < index; i++) + { + it++; + } + return it->second; + } - SFFElement* GetChildByIndex(int index); - - SFFElement* GetChildByName(std::string name); + SFFElement* GetChildByName(std::string name) + { + ChildrenMap::iterator it = children.find(name); + if (it != children.end()) { + return it->second; + } + return nullptr; + } ~SFFElement(); diff --git a/projs/shadow-file-format/src/SFFParser.cpp b/projs/shadow-file-format/src/SFFParser.cpp index 367e1ec..a7bc6eb 100644 --- a/projs/shadow-file-format/src/SFFParser.cpp +++ b/projs/shadow-file-format/src/SFFParser.cpp @@ -1,3 +1,4 @@ +/* module; import ; import ; @@ -13,112 +14,5 @@ import :SFFVersion; namespace Shadow::SFF { - SFFElement* SFFParser::ReadFromStream(std::istream& stream) - { - auto version = ReadVersionFromHeader(stream); - if (version.invalid) { - //SH_CORE_WARN("Shadow File is invalid"); - return nullptr; - } - - - //The current node that we are building - auto* context = new SFFElement; - - //Top level Element - SFFElement* base = context; - - //The new node that will be a child of the context - auto* current = new SFFElement; - - - std::string buffer; - - char c; - while (!stream.eof()) - { - stream.get(c); - if (c == ':') - { - //The stuff in the buffer is a parameter name - std::cout << "Name: " << buffer; - current->name = buffer; - buffer = ""; - } - else if (c == '{') - { - //Start of a new block - current->isBlock = true; - current->parent = context; - context->children[current->name] = current; - context = current; - - current = new SFFElement; - } - else if (c == ',') - { - // End of a property - //The stuff is the value - std::cout << "Value: " << buffer << std::endl; - current->value = buffer; - current->parent = context; - current->isBlock = false; - buffer = ""; - - context->children[current->name] = current; - - current = new SFFElement(); - } - else if (c == '}') - { - // End of a block - context = context->parent; - } - else - { - if (std::isspace(c) == 0) - { - buffer += c; - } - } - } - - std::cout << "END" << std::endl; - - return base; - } - - SFFVersion SFFParser::ReadVersionFromHeader(std::istream& stream) { - std::string line; - std::getline(stream, line); - auto parts = explode(line, '_'); - if (parts[0] != "ShadowFileFormat") { - return SFFVersion(-1,-1,-1); - } - else { - int mayor = std::stoi(parts[1]); - int minor = std::stoi(parts[2]); - int patch = std::stoi(parts[3]); - return SFFVersion(mayor, minor, patch); - } - - } - - - - SFFElement* SFFParser::ReadFromFile(std::string path) - { - std::ifstream inputFileStream(path); - - if (errno) - { - //SH_CORE_ERROR("Error: {0} | File: {1}", strerror(errno), path); - //std::cerr << "Error: " << strerror(errno) << std::endl; - //std::cerr << "File: " << path << std::endl; - return nullptr; - } - - return ReadFromStream(inputFileStream); - } - } +*/ \ No newline at end of file diff --git a/projs/shadow-file-format/src/SFFParser.ixx b/projs/shadow-file-format/src/SFFParser.ixx index 53621ed..9ea2d43 100644 --- a/projs/shadow-file-format/src/SFFParser.ixx +++ b/projs/shadow-file-format/src/SFFParser.ixx @@ -1,24 +1,130 @@ module; +export module Shadow.FileFormat:SFFParser; + import ; import ; - -export module Shadow.FileFormat:SFFParser; +import ; +import ; +import shadow_utils; import :SFFElement; import :SFFVersion; -export namespace Shadow::SFF { +namespace Shadow::SFF { - class SFFParser + export class SFFParser { public: - static SFFElement* ReadFromStream(std::istream& stream); + static SFFElement* ReadFromStream(std::istream& stream) + { + auto version = ReadVersionFromHeader(stream); + if (version.invalid) { + //SH_CORE_WARN("Shadow File is invalid"); + return nullptr; + } - static SFFVersion ReadVersionFromHeader(std::istream& stream); - static SFFElement* ReadFromFile(std::string path); + //The current node that we are building + auto* context = new SFFElement; + + //Top level Element + SFFElement* base = context; + + //The new node that will be a child of the context + auto* current = new SFFElement; + + + std::string buffer; + + char c; + while (!stream.eof()) + { + stream.get(c); + if (c == ':') + { + //The stuff in the buffer is a parameter name + std::cout << "Name: " << buffer; + current->name = buffer; + buffer = ""; + } + else if (c == '{') + { + //Start of a new block + current->isBlock = true; + current->parent = context; + context->children[current->name] = current; + context = current; + + current = new SFFElement; + } + else if (c == ',') + { + // End of a property + //The stuff is the value + std::cout << "Value: " << buffer << std::endl; + current->value = buffer; + current->parent = context; + current->isBlock = false; + buffer = ""; + + context->children[current->name] = current; + + current = new SFFElement(); + } + else if (c == '}') + { + // End of a block + context = context->parent; + } + else + { + if (std::isspace(c) == 0) + { + buffer += c; + } + } + } + + std::cout << "END" << std::endl; + + return base; + } + + static SFFVersion ReadVersionFromHeader(std::istream& stream) { + std::string line; + std::getline(stream, line); + auto parts = explode(line, '_'); + if (parts[0] != "ShadowFileFormat") { + return SFFVersion(-1, -1, -1); + } + else { + int mayor = std::stoi(parts[1]); + int minor = std::stoi(parts[2]); + int patch = std::stoi(parts[3]); + return SFFVersion(mayor, minor, patch); + } + + } + + + + static SFFElement* ReadFromFile(std::string path) + { + std::ifstream inputFileStream(path); + + if (errno) + { + //SH_CORE_ERROR("Error: {0} | File: {1}", strerror(errno), path); + //std::cerr << "Error: " << strerror(errno) << std::endl; + //std::cerr << "File: " << path << std::endl; + return nullptr; + } + + return ReadFromStream(inputFileStream); + } + }; } diff --git a/projs/shadow-utility/string-helpers.cpp b/projs/shadow-utility/string-helpers.cpp index 6a5ce44..a7ba77d 100644 --- a/projs/shadow-utility/string-helpers.cpp +++ b/projs/shadow-utility/string-helpers.cpp @@ -1,10 +1,10 @@ module; +module shadow_utils; + import ; import ; -module shadow_utils; - inline std::vector explode(const std::string& s, const char& c) { std::string buff;