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 209 of file StdMeshMaterial.cpp.

Constructor & Destructor Documentation

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

Definition at line 252 of file StdMeshMaterial.cpp.

252  :
253  Line(1), Script(mat_script), Manager(manager), FileName(filename), Loader(loader)
254 {
255 }
StdMeshMatManager & Manager
StdMeshMaterialLoader & Loader

Member Function Documentation

Token StdMeshMaterialParserCtx::Advance ( StdStrBuf name)

Definition at line 299 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().

300 {
301  SkipWhitespace();
302 
303  switch (*Script)
304  {
305  case '\0':
306  name.Clear();
307  return TOKEN_EOF;
308  case '{':
309  ++Script;
310  name = "{";
311  return TOKEN_BRACE_OPEN;
312  case '}':
313  ++Script;
314  name = "}";
315  return TOKEN_BRACE_CLOSE;
316  case ':':
317  ++Script;
318  name = ":";
319  return TOKEN_COLON;
320  default:
321  const char* begin = Script;
322  // Advance to next whitespace
323  do { ++Script; }
324  while (!isspace(*Script) && *Script != '{' && *Script != '}' && *Script != ':');
325  name.Copy(begin, Script - begin);
326  return TOKEN_IDTF;
327  }
328 }
void Clear()
Definition: StdBuf.h:474
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool StdMeshMaterialParserCtx::AdvanceBoolean ( )

Definition at line 423 of file StdMeshMaterial.cpp.

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

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

424 {
425  StdCopyStrBuf buf;
427  if (buf == "on") return true;
428  if (buf == "off") return false;
429  Error(StdCopyStrBuf("Expected either 'on' or 'off', but not '") + buf + "'");
430  return false; // Never reached
431 }
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 415 of file StdMeshMaterial.cpp.

References AdvanceFloat(), and AdvanceFloatOptional().

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

416 {
417  Color[0] = AdvanceFloat();
418  Color[1] = AdvanceFloat();
419  Color[2] = AdvanceFloat();
420  if (with_alpha) AdvanceFloatOptional(Color[3]);
421 }
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 434 of file StdMeshMaterial.cpp.

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

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

435 {
436  StdCopyStrBuf buf;
438 
439  for (const Enumerator<EnumType>* cur = enumerators; cur->Name; ++cur)
440  if (buf == cur->Name)
441  return cur->Value;
442 
444  return EnumType(); // avoid compiler warning
445 }
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 448 of file StdMeshMaterial.cpp.

References AdvanceEnum().

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

449 {
450  for (int i = 0; i < Num; ++i)
451  enums[i] = AdvanceEnum(enumerators);
452 }
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 455 of file StdMeshMaterial.cpp.

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

456 {
457  StdCopyStrBuf buf;
459 
460  const Enumerator<EnumType>* cenum;
461  const EnumeratorShortcut<Num, EnumType>* cshort;
462 
463  for (cenum = enumerators; cenum->Name; ++cenum)
464  if (buf == cenum->Name)
465  break;
466  for (cshort = shortcuts; cshort->Name; ++cshort)
467  if (buf == cshort->Name)
468  break;
469 
470  if (!cenum->Name && !cshort->Name)
471  {
473  }
474  else if (!cenum->Name && cshort->Name)
475  {
476  for (int i = 0; i < Num; ++i)
477  enums[i] = cshort->Values[i];
478  }
479  else if (cenum->Name && (!cshort->Name || Num == 1))
480  {
481  enums[0] = cenum->Value;
482  for (int i = 1; i < Num; ++i)
483  enums[i] = AdvanceEnum(enumerators);
484  }
485  else
486  {
487  // Both enumerator and shortcut are possible, determine by look-ahead
488  const Enumerator<EnumType>* cenum2 = nullptr;
489  Token tok = Peek(buf);
490  if (tok == TOKEN_IDTF)
491  {
492  for (cenum2 = enumerators; cenum2->Name; ++cenum2)
493  if (buf == cenum2->Name)
494  break;
495  }
496 
497  if (cenum2 && cenum2->Name)
498  {
499  // The next item is an enumerator, so load as enumerators
500  enums[0] = cenum->Value;
501  for (int i = 1; i < Num; ++i)
502  enums[i] = AdvanceEnum(enumerators);
503  }
504  else
505  {
506  // The next item is something else, so load the shortcut
507  for (int i = 0; i < Num; ++i)
508  enums[i] = cshort->Values[i];
509  }
510  }
511 }
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 385 of file StdMeshMaterial.cpp.

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

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

386 {
387  StdStrBuf buf;
389  float f;
390 #ifdef WITH_GLIB
391  char* end;
392  f = g_ascii_strtod(buf.getData(), &end);
393  if (*end != '\0')
394 #else
395  if (!(std::istringstream(buf.getData()) >> f))
396 #endif
397  Error(StdStrBuf("Floating point value expected"));
398  return f;
399 }
const char * getData() const
Definition: StdBuf.h:450
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 401 of file StdMeshMaterial.cpp.

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

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

402 {
403  StdStrBuf buf;
404  Token tok = Peek(buf);
405 
406  if (tok == TOKEN_IDTF && isdigit(buf[0]))
407  {
408  value = AdvanceFloat();
409  return true;
410  }
411 
412  return false;
413 }
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 354 of file StdMeshMaterial.cpp.

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

Referenced by AdvanceIntOptional().

355 {
356  StdStrBuf buf;
358  int i;
359 #ifdef WITH_GLIB
360  char* end;
361  i = g_ascii_strtoll(buf.getData(), &end, 10);
362  if (*end != '\0')
363 #else
364  if (!(std::istringstream(buf.getData()) >> i))
365 #endif
366  Error(StdStrBuf("Integer value expected"));
367 
368  return i;
369 }
const char * getData() const
Definition: StdBuf.h:450
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 371 of file StdMeshMaterial.cpp.

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

Referenced by StdMeshMaterialTextureUnit::Load().

372 {
373  StdStrBuf buf;
374  Token tok = Peek(buf);
375 
376  if (tok == TOKEN_IDTF && isdigit(buf[0]))
377  {
378  value = AdvanceInt();
379  return true;
380  }
381 
382  return false;
383 }
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 330 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().

331 {
332  Token token = Advance(name);
333  if (token == TOKEN_EOF) Error(StdCopyStrBuf("Unexpected end of file"));
334  return token;
335 }
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 337 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().

338 {
339  Token token = AdvanceNonEOF(name);
340  // TODO: Explain what was actually expected
341  if (token != expect) Error(StdCopyStrBuf("'") + name + "' unexpected");
342  return token;
343 }
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 345 of file StdMeshMaterial.cpp.

References AdvanceNonEOF(), and Error().

346 {
347  Token token = AdvanceNonEOF(name);
348  // TODO: Explain what was actually expected
349  if (token != expect1 && token != expect2)
350  Error(StdStrBuf("'") + name + "' unexpected");
351  return token;
352 }
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 513 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().

514 {
515  throw StdMeshMaterialError(message, FileName.getData(), Line);
516 }
const char * getData() const
Definition: StdBuf.h:450

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 518 of file StdMeshMaterial.cpp.

References Error().

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

519 {
520  Error(StdCopyStrBuf("Unexpected identifier: '") + identifier + "'");
521 }
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 289 of file StdMeshMaterial.cpp.

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

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

290 {
291  SkipWhitespace();
292 
293  const char* before = Script;
294  Token tok = Advance(name);
295  Script = before;
296  return tok;
297 }
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 257 of file StdMeshMaterial.cpp.

References Line, and Script.

Referenced by Advance(), and Peek().

258 {
259  while (isspace(*Script))
260  {
261  if (*Script == '\n') ++Line;
262  ++Script;
263  }
264 
265  if (*Script == '/')
266  {
267  if (*(Script+1) == '/')
268  {
269  Script += 2;
270  while (*Script != '\n' && *Script != '\0')
271  ++Script;
272  SkipWhitespace();
273  }
274  else if (*Script == '*')
275  {
276  for (Script += 2; *Script != '\0'; ++Script)
277  if (*Script == '*' && *(Script+1) == '/')
278  break;
279 
280  if (*Script == '*')
281  {
282  Script += 2;
283  SkipWhitespace();
284  }
285  }
286  }
287 }

Here is the caller graph for this function:

void StdMeshMaterialParserCtx::WarningNotSupported ( const char *  identifier)

Definition at line 523 of file StdMeshMaterial.cpp.

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

Referenced by StdMeshMaterialPass::Load().

524 {
525  DebugLogF("%s:%d: Warning: \"%s\" is not supported!", FileName.getData(), Line, identifier);
526 }
const char * getData() const
Definition: StdBuf.h:450
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:281

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 238 of file StdMeshMaterial.cpp.

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

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

Definition at line 239 of file StdMeshMaterial.cpp.

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

StdMeshMatManager& StdMeshMaterialParserCtx::Manager

Definition at line 237 of file StdMeshMaterial.cpp.

Referenced by LoadShader().

const char* StdMeshMaterialParserCtx::Script

Definition at line 235 of file StdMeshMaterial.cpp.

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


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