OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshMaterialParserCtx Class Reference
Collaboration diagram for StdMeshMaterialParserCtx:
[legend]

Public Member Functions

 StdMeshMaterialParserCtx (StdMeshMatManager &manager, const char *mat_script, const char *filename, StdMeshMaterialLoader &loader)
 
void SkipWhitespace ()
 
Token Peek (StdStrBuf &name)
 
Token Advance (StdStrBuf &name)
 
Token AdvanceNonEOF (StdStrBuf &name)
 
Token AdvanceRequired (StdStrBuf &name, Token expect)
 
Token AdvanceRequired (StdStrBuf &name, Token expect1, Token expect2)
 
int AdvanceInt ()
 
bool AdvanceIntOptional (int &value)
 
float AdvanceFloat ()
 
bool AdvanceFloatOptional (float &value)
 
void AdvanceColor (bool with_alpha, float Color[4])
 
bool AdvanceBoolean ()
 
template<typename EnumType >
EnumType AdvanceEnum (const Enumerator< EnumType > *enumerators)
 
template<int Num, typename EnumType >
void AdvanceEnums (const Enumerator< EnumType > *enumerators, EnumType enums[Num])
 
template<int Num, typename EnumType >
void AdvanceEnums (const Enumerator< EnumType > *enumerators, const EnumeratorShortcut< Num, EnumType > *shortcuts, EnumType enums[Num])
 
void Error (const StdStrBuf &message)
 
void ErrorUnexpectedIdentifier (const StdStrBuf &identifier)
 
void WarningNotSupported (const char *identifier)
 

Public Attributes

unsigned int Line
 
const char * Script
 
StdMeshMatManagerManager
 
StdCopyStrBuf FileName
 
StdMeshMaterialLoaderLoader
 

Detailed Description

Definition at line 199 of file StdMeshMaterial.cpp.

Constructor & Destructor Documentation

StdMeshMaterialParserCtx::StdMeshMaterialParserCtx ( StdMeshMatManager manager,
const char *  mat_script,
const char *  filename,
StdMeshMaterialLoader loader 
)

Definition at line 242 of file StdMeshMaterial.cpp.

242  :
243  Line(1), Script(mat_script), Manager(manager), FileName(filename), Loader(loader)
244 {
245 }
StdMeshMatManager & Manager
StdMeshMaterialLoader & Loader

Member Function Documentation

Token StdMeshMaterialParserCtx::Advance ( StdStrBuf name)

Definition at line 289 of file StdMeshMaterial.cpp.

References StdStrBuf::Clear(), StdStrBuf::Copy(), Script, SkipWhitespace(), TOKEN_BRACE_CLOSE, TOKEN_BRACE_OPEN, TOKEN_COLON, TOKEN_EOF, and TOKEN_IDTF.

Referenced by AdvanceNonEOF(), StdMeshMatManager::Parse(), and Peek().

290 {
291  SkipWhitespace();
292 
293  switch (*Script)
294  {
295  case '\0':
296  name.Clear();
297  return TOKEN_EOF;
298  case '{':
299  ++Script;
300  name = "{";
301  return TOKEN_BRACE_OPEN;
302  case '}':
303  ++Script;
304  name = "}";
305  return TOKEN_BRACE_CLOSE;
306  case ':':
307  ++Script;
308  name = ":";
309  return TOKEN_COLON;
310  default:
311  const char* begin = Script;
312  // Advance to next whitespace
313  do { ++Script; }
314  while (!isspace(*Script) && *Script != '{' && *Script != '}' && *Script != ':');
315  name.Copy(begin, Script - begin);
316  return TOKEN_IDTF;
317  }
318 }
void Clear()
Definition: StdBuf.h:466
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshMaterialParserCtx::AdvanceBoolean ( )

Definition at line 413 of file StdMeshMaterial.cpp.

References AdvanceRequired(), Error(), and TOKEN_IDTF.

Referenced by StdMeshMaterialPass::Load(), and StdMeshMaterial::Load().

414 {
415  StdCopyStrBuf buf;
417  if (buf == "on") return true;
418  if (buf == "off") return false;
419  Error(StdCopyStrBuf("Expected either 'on' or 'off', but not '") + buf + "'");
420  return false; // Never reached
421 }
Token AdvanceRequired(StdStrBuf &name, Token expect)
void Error(const StdStrBuf &message)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshMaterialParserCtx::AdvanceColor ( bool  with_alpha,
float  Color[4] 
)

Definition at line 405 of file StdMeshMaterial.cpp.

References AdvanceFloat(), and AdvanceFloatOptional().

Referenced by StdMeshMaterialTextureUnit::Load(), and StdMeshMaterialPass::Load().

406 {
407  Color[0] = AdvanceFloat();
408  Color[1] = AdvanceFloat();
409  Color[2] = AdvanceFloat();
410  if (with_alpha) AdvanceFloatOptional(Color[3]);
411 }
bool AdvanceFloatOptional(float &value)

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename EnumType >
EnumType StdMeshMaterialParserCtx::AdvanceEnum ( const Enumerator< EnumType > *  enumerators)

Definition at line 424 of file StdMeshMaterial.cpp.

References AdvanceRequired(), ErrorUnexpectedIdentifier(), and TOKEN_IDTF.

Referenced by AdvanceEnums(), StdMeshMaterialTextureUnit::Load(), and StdMeshMaterialPass::Load().

425 {
426  StdCopyStrBuf buf;
428 
429  for (const Enumerator<EnumType>* cur = enumerators; cur->Name; ++cur)
430  if (buf == cur->Name)
431  return cur->Value;
432 
434  return EnumType(); // avoid compiler warning
435 }
Token AdvanceRequired(StdStrBuf &name, Token expect)
void ErrorUnexpectedIdentifier(const StdStrBuf &identifier)

Here is the call graph for this function:

Here is the caller graph for this function:

template<int Num, typename EnumType >
void StdMeshMaterialParserCtx::AdvanceEnums ( const Enumerator< EnumType > *  enumerators,
EnumType  enums[Num] 
)

Definition at line 438 of file StdMeshMaterial.cpp.

References AdvanceEnum().

Referenced by StdMeshMaterialTextureUnit::Load(), and StdMeshMaterialPass::Load().

439 {
440  for (int i = 0; i < Num; ++i)
441  enums[i] = AdvanceEnum(enumerators);
442 }
EnumType AdvanceEnum(const Enumerator< EnumType > *enumerators)

Here is the call graph for this function:

Here is the caller graph for this function:

template<int Num, typename EnumType >
void StdMeshMaterialParserCtx::AdvanceEnums ( const Enumerator< EnumType > *  enumerators,
const EnumeratorShortcut< Num, EnumType > *  shortcuts,
EnumType  enums[Num] 
)

Definition at line 445 of file StdMeshMaterial.cpp.

References AdvanceEnum(), AdvanceRequired(), ErrorUnexpectedIdentifier(), Peek(), and TOKEN_IDTF.

446 {
447  StdCopyStrBuf buf;
449 
450  const Enumerator<EnumType>* cenum;
451  const EnumeratorShortcut<Num, EnumType>* cshort;
452 
453  for (cenum = enumerators; cenum->Name; ++cenum)
454  if (buf == cenum->Name)
455  break;
456  for (cshort = shortcuts; cshort->Name; ++cshort)
457  if (buf == cshort->Name)
458  break;
459 
460  if (!cenum->Name && !cshort->Name)
461  {
463  }
464  else if (!cenum->Name && cshort->Name)
465  {
466  for (int i = 0; i < Num; ++i)
467  enums[i] = cshort->Values[i];
468  }
469  else if (cenum->Name && (!cshort->Name || Num == 1))
470  {
471  enums[0] = cenum->Value;
472  for (int i = 1; i < Num; ++i)
473  enums[i] = AdvanceEnum(enumerators);
474  }
475  else
476  {
477  // Both enumerator and shortcut are possible, determine by look-ahead
478  const Enumerator<EnumType>* cenum2 = nullptr;
479  Token tok = Peek(buf);
480  if (tok == TOKEN_IDTF)
481  {
482  for (cenum2 = enumerators; cenum2->Name; ++cenum2)
483  if (buf == cenum2->Name)
484  break;
485  }
486 
487  if (cenum2 && cenum2->Name)
488  {
489  // The next item is an enumerator, so load as enumerators
490  enums[0] = cenum->Value;
491  for (int i = 1; i < Num; ++i)
492  enums[i] = AdvanceEnum(enumerators);
493  }
494  else
495  {
496  // The next item is something else, so load the shortcut
497  for (int i = 0; i < Num; ++i)
498  enums[i] = cshort->Values[i];
499  }
500  }
501 }
Token AdvanceRequired(StdStrBuf &name, Token expect)
EnumType AdvanceEnum(const Enumerator< EnumType > *enumerators)
void ErrorUnexpectedIdentifier(const StdStrBuf &identifier)
Token Peek(StdStrBuf &name)

Here is the call graph for this function:

float StdMeshMaterialParserCtx::AdvanceFloat ( )

Definition at line 375 of file StdMeshMaterial.cpp.

References AdvanceRequired(), Error(), StdStrBuf::getData(), and TOKEN_IDTF.

Referenced by AdvanceColor(), AdvanceFloatOptional(), StdMeshMaterialTextureUnit::Load(), and StdMeshMaterialPass::Load().

376 {
377  StdStrBuf buf;
379  float f;
380 #ifdef WITH_GLIB
381  char* end;
382  f = g_ascii_strtod(buf.getData(), &end);
383  if (*end != '\0')
384 #else
385  if (!(std::istringstream(buf.getData()) >> f))
386 #endif
387  Error(StdStrBuf("Floating point value expected"));
388  return f;
389 }
const char * getData() const
Definition: StdBuf.h:442
Token AdvanceRequired(StdStrBuf &name, Token expect)
void Error(const StdStrBuf &message)

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshMaterialParserCtx::AdvanceFloatOptional ( float &  value)

Definition at line 391 of file StdMeshMaterial.cpp.

References AdvanceFloat(), Peek(), and TOKEN_IDTF.

Referenced by AdvanceColor(), StdMeshMaterialTextureUnit::Load(), and StdMeshMaterialPass::Load().

392 {
393  StdStrBuf buf;
394  Token tok = Peek(buf);
395 
396  if (tok == TOKEN_IDTF && isdigit(buf[0]))
397  {
398  value = AdvanceFloat();
399  return true;
400  }
401 
402  return false;
403 }
Token Peek(StdStrBuf &name)

Here is the call graph for this function:

Here is the caller graph for this function:

int StdMeshMaterialParserCtx::AdvanceInt ( )

Definition at line 344 of file StdMeshMaterial.cpp.

References AdvanceRequired(), Error(), StdStrBuf::getData(), and TOKEN_IDTF.

Referenced by AdvanceIntOptional().

345 {
346  StdStrBuf buf;
348  int i;
349 #ifdef WITH_GLIB
350  char* end;
351  i = g_ascii_strtoll(buf.getData(), &end, 10);
352  if (*end != '\0')
353 #else
354  if (!(std::istringstream(buf.getData()) >> i))
355 #endif
356  Error(StdStrBuf("Integer value expected"));
357 
358  return i;
359 }
const char * getData() const
Definition: StdBuf.h:442
Token AdvanceRequired(StdStrBuf &name, Token expect)
void Error(const StdStrBuf &message)

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshMaterialParserCtx::AdvanceIntOptional ( int &  value)

Definition at line 361 of file StdMeshMaterial.cpp.

References AdvanceInt(), Peek(), and TOKEN_IDTF.

Referenced by StdMeshMaterialTextureUnit::Load().

362 {
363  StdStrBuf buf;
364  Token tok = Peek(buf);
365 
366  if (tok == TOKEN_IDTF && isdigit(buf[0]))
367  {
368  value = AdvanceInt();
369  return true;
370  }
371 
372  return false;
373 }
Token Peek(StdStrBuf &name)

Here is the call graph for this function:

Here is the caller graph for this function:

Token StdMeshMaterialParserCtx::AdvanceNonEOF ( StdStrBuf name)

Definition at line 320 of file StdMeshMaterial.cpp.

References Advance(), Error(), and TOKEN_EOF.

Referenced by AdvanceRequired(), StdMeshMaterialShaderParameters::Load(), StdMeshMaterialTextureUnit::Load(), StdMeshMaterialPass::Load(), StdMeshMaterialTechnique::Load(), StdMeshMaterial::Load(), and LoadShader().

321 {
322  Token token = Advance(name);
323  if (token == TOKEN_EOF) Error(StdCopyStrBuf("Unexpected end of file"));
324  return token;
325 }
void Error(const StdStrBuf &message)
Token Advance(StdStrBuf &name)

Here is the call graph for this function:

Here is the caller graph for this function:

Token StdMeshMaterialParserCtx::AdvanceRequired ( StdStrBuf name,
Token  expect 
)

Definition at line 327 of file StdMeshMaterial.cpp.

References AdvanceNonEOF(), and Error().

Referenced by AdvanceBoolean(), AdvanceEnum(), AdvanceEnums(), AdvanceFloat(), AdvanceInt(), StdMeshMaterialShaderParameters::Load(), StdMeshMaterialSubLoader::Load(), StdMeshMaterialTextureUnit::Load(), StdMeshMaterialPass::Load(), LoadShader(), and StdMeshMatManager::Parse().

328 {
329  Token token = AdvanceNonEOF(name);
330  // TODO: Explain what was actually expected
331  if (token != expect) Error(StdCopyStrBuf("'") + name + "' unexpected");
332  return token;
333 }
void Error(const StdStrBuf &message)
Token AdvanceNonEOF(StdStrBuf &name)

Here is the call graph for this function:

Here is the caller graph for this function:

Token StdMeshMaterialParserCtx::AdvanceRequired ( StdStrBuf name,
Token  expect1,
Token  expect2 
)

Definition at line 335 of file StdMeshMaterial.cpp.

References AdvanceNonEOF(), and Error().

336 {
337  Token token = AdvanceNonEOF(name);
338  // TODO: Explain what was actually expected
339  if (token != expect1 && token != expect2)
340  Error(StdStrBuf("'") + name + "' unexpected");
341  return token;
342 }
void Error(const StdStrBuf &message)
Token AdvanceNonEOF(StdStrBuf &name)

Here is the call graph for this function:

void StdMeshMaterialParserCtx::Error ( const StdStrBuf message)

Definition at line 503 of file StdMeshMaterial.cpp.

References FileName, StdStrBuf::getData(), and Line.

Referenced by AdvanceBoolean(), AdvanceFloat(), AdvanceInt(), AdvanceNonEOF(), AdvanceRequired(), ErrorUnexpectedIdentifier(), StdMeshMaterialShaderParameters::Load(), StdMeshMaterialTextureUnit::Load(), StdMeshMaterialPass::Load(), StdMeshMaterialTechnique::Load(), StdMeshMaterial::Load(), LoadShader(), StdMeshMaterialTextureUnit::LoadTexture(), and StdMeshMatManager::Parse().

504 {
505  throw StdMeshMaterialError(message, FileName.getData(), Line);
506 }
const char * getData() const
Definition: StdBuf.h:442

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshMaterialParserCtx::ErrorUnexpectedIdentifier ( const StdStrBuf identifier)

Definition at line 508 of file StdMeshMaterial.cpp.

References Error().

Referenced by AdvanceEnum(), AdvanceEnums(), StdMeshMaterialShaderParameters::Load(), StdMeshMaterialTextureUnit::Load(), StdMeshMaterialPass::Load(), StdMeshMaterialTechnique::Load(), StdMeshMaterial::Load(), LoadShader(), and StdMeshMatManager::Parse().

509 {
510  Error(StdCopyStrBuf("Unexpected identifier: '") + identifier + "'");
511 }
void Error(const StdStrBuf &message)

Here is the call graph for this function:

Here is the caller graph for this function:

Token StdMeshMaterialParserCtx::Peek ( StdStrBuf name)

Definition at line 279 of file StdMeshMaterial.cpp.

References Advance(), Script, and SkipWhitespace().

Referenced by AdvanceEnums(), AdvanceFloatOptional(), and AdvanceIntOptional().

280 {
281  SkipWhitespace();
282 
283  const char* before = Script;
284  Token tok = Advance(name);
285  Script = before;
286  return tok;
287 }
Token Advance(StdStrBuf &name)

Here is the call graph for this function:

Here is the caller graph for this function:

void StdMeshMaterialParserCtx::SkipWhitespace ( )

Definition at line 247 of file StdMeshMaterial.cpp.

References Line, and Script.

Referenced by Advance(), and Peek().

248 {
249  while (isspace(*Script))
250  {
251  if (*Script == '\n') ++Line;
252  ++Script;
253  }
254 
255  if (*Script == '/')
256  {
257  if (*(Script+1) == '/')
258  {
259  Script += 2;
260  while (*Script != '\n' && *Script != '\0')
261  ++Script;
262  SkipWhitespace();
263  }
264  else if (*Script == '*')
265  {
266  for (Script += 2; *Script != '\0'; ++Script)
267  if (*Script == '*' && *(Script+1) == '/')
268  break;
269 
270  if (*Script == '*')
271  {
272  Script += 2;
273  SkipWhitespace();
274  }
275  }
276  }
277 }

Here is the caller graph for this function:

void StdMeshMaterialParserCtx::WarningNotSupported ( const char *  identifier)

Definition at line 513 of file StdMeshMaterial.cpp.

References DebugLogF(), FileName, StdStrBuf::getData(), and Line.

Referenced by StdMeshMaterialPass::Load().

514 {
515  DebugLogF(R"(%s:%d: Warning: "%s" is not supported!)", FileName.getData(), Line, identifier);
516 }
const char * getData() const
Definition: StdBuf.h:442
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

StdCopyStrBuf StdMeshMaterialParserCtx::FileName

Definition at line 228 of file StdMeshMaterial.cpp.

Referenced by Error(), StdMeshMatManager::Parse(), and WarningNotSupported().

unsigned int StdMeshMaterialParserCtx::Line
StdMeshMaterialLoader& StdMeshMaterialParserCtx::Loader

Definition at line 229 of file StdMeshMaterial.cpp.

Referenced by LoadShader(), and StdMeshMaterialTextureUnit::LoadTexture().

StdMeshMatManager& StdMeshMaterialParserCtx::Manager

Definition at line 227 of file StdMeshMaterial.cpp.

Referenced by LoadShader().

const char* StdMeshMaterialParserCtx::Script

Definition at line 225 of file StdMeshMaterial.cpp.

Referenced by Advance(), StdMeshMaterialSubLoader::Load(), Peek(), and SkipWhitespace().


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