本文整理汇总了C++中StringBuilder::ProduceString方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuilder::ProduceString方法的具体用法?C++ StringBuilder::ProduceString怎么用?C++ StringBuilder::ProduceString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder::ProduceString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToString
CoreLib::String ShaderLibFile::ToString()
{
StringBuilder writer;
writer << L"name " << MetaData.ShaderName << EndLine;
for (auto & world : MetaData.Worlds)
{
writer << L"world " << world.Key << EndLine << L"{" << EndLine;
writer << L"target " << world.Value.TargetName << EndLine;
for (auto & blk : world.Value.InputBlocks)
{
writer << L"in " << blk << L";\n";
}
writer << L"out " << world.Value.OutputBlock << L";\n";
for (auto & comp : world.Value.Components)
writer << L"comp " << comp << L";\n";
writer << L"}" << EndLine;
}
for (auto & ublock : MetaData.InterfaceBlocks)
{
writer << L"interface " << ublock.Key << L" size " << ublock.Value.Size << L"\n{\n";
for (auto & entry : ublock.Value.Entries)
{
writer << ILBaseTypeToString(entry.Type) << L" " << entry.Name << L" : " << entry.Offset << L"," << entry.Size;
if (entry.Attributes.Count())
{
writer << L"\n{\n";
for (auto & attrib : entry.Attributes)
{
writer << attrib.Key << L" : " << CoreLib::Text::Parser::EscapeStringLiteral(attrib.Value) << L";\n";
}
writer << L"}";
}
writer << L";\n";
}
writer << L"}\n";
}
writer << L"source" << EndLine << L"{" << EndLine;
for (auto & src : Sources)
{
writer << src.Key << EndLine;
writer << L"{" << EndLine;
writer << src.Value.GetAllCodeGLSL() << EndLine;
writer << L"}" << EndLine;
}
writer << L"}" << EndLine;
StringBuilder formatSB;
IndentString(formatSB, writer.ProduceString());
return formatSB.ProduceString();
}
示例2: EscapeCodeName
CoreLib::String EscapeCodeName(CoreLib::String str)
{
StringBuilder sb;
bool isUnderScore = false;
for (auto ch : str)
{
if (ch == '_' || !((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')))
{
if (isUnderScore)
sb << "I_";
else
sb << "_";
isUnderScore = true;
}
else
{
isUnderScore = false;
sb << ch;
}
}
if (isUnderScore)
sb << "I";
return sb.ProduceString();
}
示例3: definitions
//.........这里部分代码省略.........
// generate definitions
Dictionary<ShaderClosure*, ModuleInstanceIR*> moduleInstanceMap;
auto createModuleInstance = [&](ShaderClosure * closure)
{
ModuleInstanceIR * inst;
if (moduleInstanceMap.TryGetValue(closure, inst))
return inst;
List<String> namePath;
auto parent = closure;
while (parent)
{
if (parent->Name.Length())
namePath.Add(parent->Name);
else
namePath.Add(parent->ModuleSyntaxNode->Name.Content);
parent = parent->Parent;
}
StringBuilder sbBindingName;
for (int i = namePath.Count() - 2; i >= 0; i--)
{
sbBindingName << namePath[i];
if (i > 0)
sbBindingName << ".";
}
// if this is the root module, its binding name is module name.
if (namePath.Count() == 1)
sbBindingName << namePath[0];
inst = new ModuleInstanceIR();
inst->SyntaxNode = closure->ModuleSyntaxNode;
inst->BindingIndex = closure->BindingIndex;
inst->UsingPosition = closure->UsingPosition;
result->ModuleInstances.Add(inst);
inst->BindingName = sbBindingName.ProduceString();
moduleInstanceMap[closure] = inst;
return inst;
};
for (auto & comp : shader->AllComponents)
{
EnumerableDictionary<String, ComponentDefinitionIR*> defs;
Dictionary<String, ShaderComponentImplSymbol*> impls;
for (auto & impl : comp.Value.Symbol->Implementations)
{
auto createComponentDef = [&](const String & w)
{
RefPtr<ComponentDefinitionIR> def = new ComponentDefinitionIR();
def->OriginalName = comp.Value.Symbol->Name;
def->UniqueKey = comp.Value.Symbol->UniqueKey;
def->UniqueName = comp.Value.Symbol->UniqueName;
def->Type = comp.Value.Symbol->Type->DataType;
def->IsEntryPoint = (impl->ExportWorlds.Contains(w) || impl->SyntaxNode->IsParam() ||
(shader->Pipeline->IsAbstractWorld(w) &&
(impl->SyntaxNode->HasSimpleAttribute("Pinned") || shader->Pipeline->Worlds[w]()->HasSimpleAttribute("Pinned"))));
CloneContext cloneCtx;
def->SyntaxNode = impl->SyntaxNode->Clone(cloneCtx);
def->World = w;
def->ModuleInstance = createModuleInstance(comp.Value.Closure);
return def;
};
// parameter component will only have one defintion that is shared by all worlds
if (impl->SyntaxNode->IsParam())
{
auto def = createComponentDef("<uniform>");
result->Definitions.Add(def);
defs["<uniform>"] = def.Ptr();
}
示例4: InstantiateShaderTemplate
ShaderSyntaxNode * InstantiateShaderTemplate(DiagnosticSink* sink, SymbolTable* symTable, TemplateShaderSyntaxNode* ts, const List<String>& args)
{
if (ts->Parameters.Count() > args.Count())
{
sink->diagnose(ts->Position, Diagnostics::insufficientTemplateShaderArguments, ts->Name);
return nullptr;
}
if (ts->Parameters.Count() < args.Count())
{
sink->diagnose(ts->Position, Diagnostics::tooManyTemplateShaderArguments, ts->Name);
return nullptr;
}
// check semantics
bool hasErrors = false;
for (int i = 0; i < args.Count(); i++)
{
auto name = args[i];
if (auto module = symTable->Shaders.TryGetValue(name))
{
if (ts->Parameters[i]->InterfaceName.Content.Length())
{
if ((*module)->SyntaxNode->Name.Content != ts->Parameters[i]->InterfaceName.Content &&
(*module)->SyntaxNode->InterfaceNames.FindFirst([&](const Token & t) { return t.Content == ts->Parameters[i]->InterfaceName.Content; }) == -1)
{
hasErrors = true;
sink->diagnose(ts->Parameters[i]->Position, Diagnostics::templateShaderArgumentDidNotImplementRequiredInterface, name, ts->Parameters[i]->ModuleName, ts->Parameters[i]->InterfaceName);
sink->diagnose((*module)->SyntaxNode->Position, Diagnostics::seeDefinitionOf, (*module)->SyntaxNode->Name);
}
}
}
else
{
hasErrors = true;
sink->diagnose(ts->Parameters[i]->Position, Diagnostics::templateShaderArgumentIsNotDefined, args[i], ts->Parameters[i]->ModuleName.Content);
}
}
if (hasErrors)
return nullptr;
ShaderSyntaxNode * result = new ShaderSyntaxNode();
result->Name = ts->Name;
StringBuilder nameBuilder;
nameBuilder << ts->Name.Content << "<";
for (int i = 0; i < args.Count(); i++)
{
nameBuilder << args[i];
if (i < args.Count()-1)
nameBuilder << ",";
}
nameBuilder << ">";
result->Name.Content = nameBuilder.ProduceString();
result->ParentPipelineName = ts->ParentPipelineName;
for (auto & member : ts->Members)
{
if (auto import = member.As<ImportSyntaxNode>())
{
int index = ts->Parameters.FindFirst([&](RefPtr<TemplateShaderParameterSyntaxNode> p) { return p->ModuleName.Content == import->ShaderName.Content; });
if (index != -1)
{
CloneContext cloneCtx;
auto newImport = import->Clone(cloneCtx);
auto attribModifier = new SimpleAttribute();
attribModifier->Key = "Binding";
attribModifier->Value.Content = String(index);
newImport->modifiers.first = attribModifier;
newImport->Scope->Parent = result->Scope;
newImport->ShaderName.Content = args[index];
result->Members.Add(newImport);
continue;
}
}
result->Members.Add(member);
}
result->IsModule = false;
return result;
}