Files
bluflame/aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.h
2026-04-18 22:31:51 +02:00

74 lines
2.3 KiB
C++

#pragma once
#include "IEngine.h"
#include "IFileSystem.h"
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
class CFileLoader
{
public:
CFileLoader(IEngine* ar_Engine_) : m_Engine(ar_Engine_),m_CurrentLineOfCode(0), m_File(NULL),m_EndSectionMarker("}") {}
virtual ~CFileLoader();
bool LoadFile(string16 argFilename);
const std::string& get_CurrentSection() const { return m_CurrentSection; }
virtual bool OnSectionBegin(const std::string& argContentName, const std::vector<std::string>& argContentToken) { return true; }
virtual bool OnContentReceived(const std::vector<std::string>& argContentToken, const std::string& argContentData) { return true; }
virtual bool OnSectionEnd(const std::string& argContentName) { return true; }
unsigned int get_CurrentLineNumber() const { return m_CurrentLineOfCode; }
protected:
std::vector<std::string> SplitString(const std::string & argString, const std::string & argDelimiters=", \t\r")
{
// Skip delims at beginning, find start of first token
std::string::size_type lastPos = argString.find_first_not_of(argDelimiters, 0);
// Find next delimiter @ end of token
std::string::size_type pos = argString.find_first_of(argDelimiters, lastPos);
// output vector
std::vector<std::string> tokens;
while (std::string::npos != pos || std::string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(argString.substr(lastPos, pos - lastPos));
// Skip delims. Note the "not_of". this is beginning of token
lastPos = argString.find_first_not_of(argDelimiters, pos);
// Find next delimiter at end of token.
pos = argString.find_first_of(argDelimiters, lastPos);
}
return tokens;
}
std::wstring ConvertToString16(const std::string& argString) const
{
int codePage = 0;
if (argString.size() == 0)
return std::wstring();
int length = ::MultiByteToWideChar(codePage, 0, argString.c_str(), argString.size() + 1, NULL, 0);
if (length == 0)
return std::wstring();
wchar_t* newString = new wchar_t[length];
::MultiByteToWideChar(codePage, 0, argString.c_str(), argString.size() + 1, newString, length);
return std::wstring(newString);
}
IEngine* m_Engine;
void FreeFile();
private:
std::string m_CurrentSection;
IFile* m_File;
std::string m_EndSectionMarker;
unsigned int m_CurrentLineOfCode;
};