// // Created by black on 06.07.25. // #include "ProgramLoader.h" #include ProgramLoader *ProgramLoader::getInstance() { static ProgramLoader instance; return &instance; } [[nodiscard]] std::vector ProgramLoader::parseLine(const std::string &input) { if (input.empty()) return std::vector{}; std::vector output{}; /// Konvertiere den Input String in einen IStringStream, damit dieser bei Leerzeichen gesplittet werden kann std::istringstream iss(input); std::string out; do { out.clear(); /// Trenne den IStringStream bei jedem Leerzeichen und füge die Befehl(e)/-sargumente dem Output hinzu std::getline(iss, out, ' '); if (out.empty()) break; /// Stoppe, sobald ein Kommentar im Source Code vorkommt if (out.at(0) != '#') { if (out.at(out.length() - 1) == ',') { out.erase(out.length() - 1); } output.push_back(out); } else { break; } } while (!out.empty()); return output; } void ProgramLoader::indexFile(std::ifstream &m_programFile) { m_programFile.clear(); m_programFile.seekg(0); std::string line; /// Parse Zeile für Zeile while (std::getline(m_programFile, line)) { auto lineVector = parseLine(line); if (lineVector.empty()) continue; /// Sobald ein Label gefunden wurde, speichere die Position des Streams if (const auto first = lineVector.begin(); first->at(first->length() - 1) == ':') { m_labels[first->substr(0, first->length() - 1)] = m_programFile.tellg(); } } } std::streampos ProgramLoader::getStreamPosition(const std::string &label) const { return m_labels.find(label)->second; }