CSEngine
Loading...
Searching...
No Matches
CSE::XMLParser Class Reference

Static Public Member Functions

static void parse (std::vector< std::string > values, void *dst, SType type)
 
static int parseInt (const char *value)
 
static float parseFloat (const char *value)
 
static bool parseBool (const char *value)
 
static vec2 parseVec2 (std::vector< std::string > values)
 
static vec3 parseVec3 (std::vector< std::string > values)
 
static vec4 parseVec4 (std::vector< std::string > values)
 
template<class TYPE >
static TYPE * parseResources (const char *value)
 
static STextureparseTexture (const char *value)
 
static SFrameBufferparseFrameBuffer (const char *value)
 
static SMaterialparseMaterial (const char *value)
 
static SComponentparseComponent (const char *value)
 
static SGameObjectparseGameObject (const char *value)
 
static SType GetType (std::string type)
 
static SType GetType (unsigned int type)
 
static std::string ToString (SType type)
 

Detailed Description

Definition at line 20 of file XMLParser.h.

Member Function Documentation

◆ GetType() [1/2]

SType XMLParser::GetType ( std::string  type)
static

Definition at line 100 of file XMLParser.cpp.

100 {
101 static const std::unordered_map<std::string, SType> typeMap = {
102 {"str", SType::STRING},
103 {"bool", SType::BOOL},
104 {"float", SType::FLOAT},
105 {"int", SType::INT},
106 {"res", SType::RESOURCE},
107 {"tex", SType::TEXTURE},
108 {"mat", SType::MATERIAL},
109 {"comp", SType::COMPONENT},
110 {"gobj", SType::GAME_OBJECT},
111 {"vec2", SType::VEC2},
112 {"vec3", SType::VEC3},
113 {"vec4", SType::VEC4},
114 {"mat2", SType::MAT2},
115 {"mat3", SType::MAT3},
116 {"mat4", SType::MAT4}
117 };
118
119 auto it = typeMap.find(type);
120 if (it != typeMap.end()) {
121 return it->second;
122 } else {
123 return SType::UNKNOWN;
124 }
125}

◆ GetType() [2/2]

SType XMLParser::GetType ( unsigned int  type)
static

Definition at line 127 of file XMLParser.cpp.

127 {
128 switch (type) {
129 case GL_BOOL: return SType::BOOL;
130 case GL_FLOAT: return SType::FLOAT;
131 case GL_INT: return SType::INT;
132 case GL_SAMPLER_2D: return SType::TEXTURE;
133 case GL_FLOAT_VEC2: return SType::VEC2;
134 case GL_FLOAT_VEC3: return SType::VEC3;
135 case GL_FLOAT_VEC4: return SType::VEC4;
136 case GL_FLOAT_MAT2: return SType::MAT2;
137 case GL_FLOAT_MAT3: return SType::MAT3;
138 case GL_FLOAT_MAT4: return SType::MAT4;
139 default: return SType::UNKNOWN;
140 }
141}

◆ parse()

void XMLParser::parse ( std::vector< std::string >  values,
void *  dst,
SType  type 
)
static

Definition at line 12 of file XMLParser.cpp.

12 {
13 if (type == SType::STRING) dst = (void*) values[0].c_str();
14 else if (type == SType::BOOL) *static_cast<bool*>(dst) = parseBool(values[0].c_str());
15 else if (type == SType::FLOAT) *static_cast<float*>(dst) = parseFloat(values[0].c_str());
16 else if (type == SType::INT) *static_cast<int*>(dst) = parseInt(values[0].c_str());
17 // else if(type == "arr") dst = (void*)parseInt(values[0].c_str());
18
19 else if (type == SType::RESOURCE) dst = (void*) parseResources<SResource>(values[0].c_str());
20 else if (type == SType::MATERIAL) dst = (void*) parseMaterial(values[0].c_str());
21 else if (type == SType::TEXTURE) {
22 dst = (void*) parseTexture(values[0].c_str());
23 if (dst == nullptr) dst = (void*) parseFrameBuffer(values[0].c_str());
24 } else if (type == SType::COMPONENT) dst = (void*) parseComponent(values[0].c_str());
25 else if (type == SType::GAME_OBJECT) dst = (void*) parseGameObject(values[0].c_str());
26
27 else if (type == SType::VEC2) *static_cast<vec2*>(dst) = parseVec2(values);
28 else if (type == SType::VEC3) *static_cast<vec3*>(dst) = parseVec3(values);
29 else if (type == SType::VEC4) *static_cast<vec4*>(dst) = parseVec4(values);
30
31// else if (type == SType::MAT2) *static_cast<mat2*>(dst) = parseMat2(values);
32// else if (type == SType::MAT3) *static_cast<mat3*>(dst) = parseMat3(values);
33// else if (type == SType::MAT4) *static_cast<mat4*>(dst) = parseMat4(values);
34}

◆ parseBool()

bool XMLParser::parseBool ( const char *  value)
static

Definition at line 44 of file XMLParser.cpp.

44 {
45 return strncmp(value, "t", 1);
46}

◆ parseComponent()

SComponent * XMLParser::parseComponent ( const char *  value)
static

Definition at line 90 of file XMLParser.cpp.

90 {
91 SComponent* comp = CORE->GetCore(GameObjectMgr)->FindComponentByID(value);
92 return comp;
93}

◆ parseFloat()

float XMLParser::parseFloat ( const char *  value)
static

Definition at line 40 of file XMLParser.cpp.

40 {
41 return std::stof(value);
42}

◆ parseFrameBuffer()

SFrameBuffer * XMLParser::parseFrameBuffer ( const char *  value)
static

Definition at line 73 of file XMLParser.cpp.

73 {
74 std::string value_result = value;
75 const auto split_index = value_result.rfind('?');
76 if (split_index != std::string::npos)
77 value_result = value_result.substr(0, split_index - 1);
78
79 const auto& asset = CORE->GetCore(ResMgr)->GetAssetReference(value_result);
80 if (asset->type != AssetMgr::FRAMEBUFFER) {
81 return nullptr;
82 }
83 return SResource::Create<SFrameBuffer>(asset);
84}

◆ parseGameObject()

SGameObject * XMLParser::parseGameObject ( const char *  value)
static

Definition at line 95 of file XMLParser.cpp.

95 {
96 SGameObject* obj = CORE->GetCore(GameObjectMgr)->FindByID(ConvertSpaceStr(value, true));
97 return obj;
98}

◆ parseInt()

int XMLParser::parseInt ( const char *  value)
static

Definition at line 36 of file XMLParser.cpp.

36 {
37 return std::stoi(value);
38}

◆ parseMaterial()

SMaterial * XMLParser::parseMaterial ( const char *  value)
static

Definition at line 86 of file XMLParser.cpp.

86 {
87 return SResource::Create<SMaterial>(value);
88}

◆ parseResources()

template<class TYPE >
TYPE * CSE::XMLParser::parseResources ( const char *  value)
static

Definition at line 55 of file XMLParser.h.

55 {
56 TYPE* res = CORE->GetCore(ResMgr)->GetObjectByHash<TYPE>(value);
57 return res;
58 }

◆ parseTexture()

STexture * XMLParser::parseTexture ( const char *  value)
static

Definition at line 60 of file XMLParser.cpp.

60 {
61 const auto& asset = CORE->GetCore(ResMgr)->GetAssetReference(value);
62 if (asset == nullptr || asset->type == AssetMgr::FRAMEBUFFER) {
63 const auto value_split = split(value, '?');
64 if (value_split.size() <= 1)
65 return SResource::Create<STexture>(value);
66
67 const auto& frameBuffer = SResource::Create<SFrameBuffer>(value_split[0]);
68 return frameBuffer->GetTexture(value);
69 }
70 return SResource::Create<STexture>(value);
71}

◆ parseVec2()

vec2 XMLParser::parseVec2 ( std::vector< std::string >  values)
static

Definition at line 48 of file XMLParser.cpp.

48 {
49 return {std::stof(values[0]), std::stof(values[1])};
50}

◆ parseVec3()

vec3 XMLParser::parseVec3 ( std::vector< std::string >  values)
static

Definition at line 52 of file XMLParser.cpp.

52 {
53 return {std::stof(values[0]), std::stof(values[1]), std::stof(values[2])};
54}

◆ parseVec4()

vec4 XMLParser::parseVec4 ( std::vector< std::string >  values)
static

Definition at line 56 of file XMLParser.cpp.

56 {
57 return {std::stof(values[0]), std::stof(values[1]), std::stof(values[2]), std::stof(values[3])};
58}

◆ ToString()

std::string XMLParser::ToString ( SType  type)
static

Definition at line 143 of file XMLParser.cpp.

143 {
144 switch (type) {
145 case SType::STRING: return "str";
146 case SType::BOOL: return "bool";
147 case SType::FLOAT: return "float";
148 case SType::INT: return "int";
149 case SType::RESOURCE: return "res";
150 case SType::TEXTURE: return "tex";
151 case SType::MATERIAL: return "mat";
152 case SType::COMPONENT: return "comp";
153 case SType::GAME_OBJECT: return "gobj";
154 case SType::VEC2: return "vec2";
155 case SType::VEC3: return "vec3";
156 case SType::VEC4: return "vec4";
157 case SType::MAT2: return "mat2";
158 case SType::MAT3: return "mat3";
159 case SType::MAT4: return "mat4";
160 default: return "str";
161 }
162}

The documentation for this class was generated from the following files: