OpenClonk
StdMeshMaterialSubLoader Class Reference

Public Member Functions

 StdMeshMaterialSubLoader ()
 
template<typename SubT >
void Load (StdMeshMaterialParserCtx &ctx, std::vector< SubT > &vec)
 

Detailed Description

Definition at line 232 of file StdMeshMaterial.cpp.

Constructor & Destructor Documentation

◆ StdMeshMaterialSubLoader()

StdMeshMaterialSubLoader::StdMeshMaterialSubLoader ( )
default

Member Function Documentation

◆ Load()

template<typename SubT >
void StdMeshMaterialSubLoader::Load ( StdMeshMaterialParserCtx ctx,
std::vector< SubT > &  vec 
)

Definition at line 521 of file StdMeshMaterial.cpp.

522 {
523  std::vector<unsigned int> indices;
524 
525  StdCopyStrBuf token_name;
526  Token tok = ctx.AdvanceRequired(token_name, TOKEN_IDTF, TOKEN_BRACE_OPEN);
527  if(tok == TOKEN_BRACE_OPEN)
528  {
529  // Unnamed section, name by running index
530  indices.push_back(CurIndex);
531  assert(CurIndex <= vec.size());
532  if(CurIndex == vec.size())
533  {
534  vec.push_back(SubT());
535  vec.back().Name.Format("%u", CurIndex);
536  }
537 
538  ++CurIndex;
539  }
540  else
541  {
542  unsigned int size_before = indices.size();
543  for(unsigned int i = 0; i < vec.size(); ++i)
544  if(SWildcardMatchEx(vec[i].Name.getData(), token_name.getData()))
545  indices.push_back(i);
546 
547  // Only add new SubSection if no wildcard was given
548  if(indices.size() == size_before)
549  {
550  if(std::strchr(token_name.getData(), '*') == nullptr && std::strchr(token_name.getData(), '?') == nullptr)
551  {
552  indices.push_back(vec.size());
553  vec.push_back(SubT());
554  vec.back().Name = token_name;
555  }
556  }
557 
558  ctx.AdvanceRequired(token_name, TOKEN_BRACE_OPEN);
559  }
560 
561  if(indices.empty())
562  {
563  // Section is not used, parse anyway to advance script position
564  // This can happen if there is inheritance by a non-matching wildcard
565  SubT().Load(ctx);
566  }
567  else
568  {
569  // Parse section multiple times in case there is more than one match.
570  // Not particularly elegant but working.
571  for(unsigned int i = 0; i < indices.size()-1; ++i)
572  {
573  unsigned int old_line = ctx.Line;
574  const char* old_pos = ctx.Script;
575  vec[indices[i]].Load(ctx);
576  ctx.Line = old_line;
577  ctx.Script = old_pos;
578  }
579 
580  vec[indices.back()].Load(ctx);
581  }
582 }
bool SWildcardMatchEx(const char *szString, const char *szWildcard)
Definition: Standard.cpp:635
@ TOKEN_IDTF
@ TOKEN_BRACE_OPEN
Token AdvanceRequired(StdStrBuf &name, Token expect)
const char * getData() const
Definition: StdBuf.h:442

References StdMeshMaterialParserCtx::AdvanceRequired(), StdStrBuf::getData(), StdMeshMaterialParserCtx::Line, StdMeshMaterialParserCtx::Script, SWildcardMatchEx(), TOKEN_BRACE_OPEN, and TOKEN_IDTF.

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

Here is the call graph for this function:
Here is the caller graph for this function:

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