OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdMeshMaterialSubLoader Class Reference

Public Member Functions

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

Detailed Description

Definition at line 242 of file StdMeshMaterial.cpp.

Constructor & Destructor Documentation

StdMeshMaterialSubLoader::StdMeshMaterialSubLoader ( )

Definition at line 528 of file StdMeshMaterial.cpp.

529  : CurIndex(0)
530 {
531 }

Member Function Documentation

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

Definition at line 534 of file StdMeshMaterial.cpp.

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().

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

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: