本文整理汇总了C#中SourceCode.BracketStart方法的典型用法代码示例。如果您正苦于以下问题:C# SourceCode.BracketStart方法的具体用法?C# SourceCode.BracketStart怎么用?C# SourceCode.BracketStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceCode
的用法示例。
在下文中一共展示了SourceCode.BracketStart方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateParseCode
public SourceCode GenerateParseCode()
{
var code = new SourceCode();
code.Append(GenerateParsePrototypeCode());
code.BracketStart();
{
code.Append("if (root_node == nullptr) return;");
code.BracketStart("for (TiXmlElement* each_node = root_node->FirstChildElement(); each_node != nullptr; each_node = each_node->NextSiblingElement())");
{
code.Append("{0}* ptr = new {0};", QualifiedTypeName);
foreach (var field in Fields.Values)
code.Append(field.GenerateParseCode());
if (HasContent)
code.Append("ptr->{0} = std::string(each_node->GetText() != nullptr? each_node->GetText(): \"\");", IsNameContent ? "name" : "content");
code.NewLine();
if (IsTopMost)
code.Append("{0}_data::add(ptr);", SimpleName);
else
{
code.Append(HasId ? "parent->{0}.insert(std::make_pair(ptr->id, ptr));" : "parent->{0}.push_back(ptr);", CollectionName);
}
if (NeedLinker)
code.NewLine();
foreach (var field in ReferenceFields)
code.Append(field.GenerateParseRefCode());
}
code.BracketEnd();
}
code.BracketEnd();
foreach (var field in DataClassFields)
code.Append(field.GenerateParseBodyCode());
return code;
}
示例2: GenerateReloaderImplCode
public SourceCode GenerateReloaderImplCode()
{
var code = new SourceCode();
code.Append("template <>");
code.Append("inline void data_referer<{0}>::add()", TypeName);
code.BracketStart();
code.Append("data_depend_map::instance().add(data::type_id::{0});", SimpleName);
code.BracketEnd();
code.NewLine();
code.Append("template <>");
code.Append("inline void data_referer<{0}>::release()", TypeName);
code.BracketStart();
code.Append("data_depend_map::instance().release(data::type_id::{0});", SimpleName);
code.BracketEnd();
code.NewLine();
code.Append("template <>");
code.Append("inline bool data_reloader_impl<{0}>::is_reloadable()", TypeName);
code.BracketStart();
code.Append("return !({0});", string.Join(" \n && ", from clazz in DataDepender.Instance[this] select clazz.GenerateDependMapCheckCode().Generate()));
code.BracketEnd();
code.NewLine();
code.Append("template <>");
code.Append("inline void data_reloader_impl<{0}>::reload()", TypeName);
code.BracketStart();
code.Append("data_center<{0}>::clear();", TypeName);
code.Append("data_center<{0}>::load();", TypeName);
code.Append("data_center<{0}>::link();", TypeName);
code.BracketEnd();
return code;
}
示例3: GenerateCpp
private void GenerateCpp()
{
_cppCode = new SourceCode();
_cppCode.Append("#include \"{0}\"", Configuration.Stdafx);
foreach (var dependancy in new[] {"singleton.h", "cbes/attribute.h"})
_cppCode.Append("#include \"{0}\"", dependancy);
_cppCode.NewLine();
_cppCode.Append("#pragma warning (disable: 4189 4100 4505)");
_cppCode.NewLine();
foreach (var attributeClass in _attributes)
_cppCode.Append("#include \"{0}\"", attributeClass.HeaderFileName);
_cppCode.NewLine();
#region factory
_cppCode.Append("#pragma region /* factory-register */");
_cppCode.StaticInitializerStart();
foreach (var attributeClass in _attributes)
_cppCode.Append("sys<attribute_factory>().factory_map.insert(std::make_pair(\"{0}\", [=] () {{ return attribute_ref(new {1}); }}));", attributeClass.Name,
attributeClass.StructName);
_cppCode.StaticInitializerEnd();
_cppCode.Append("#pragma endregion");
_cppCode.NewLine();
#endregion
foreach (var attributeClass in _attributes)
{
_cppCode.Append("#pragma region /* {0} */", attributeClass.Name);
#region from_bson
{
var nonVolatiles = attributeClass.NonVolatileFields.ToArray();
if (nonVolatiles.Any())
{
_cppCode.Append("void {0}::from_bson(bson_iterator*)", attributeClass.StructName);
_cppCode.Append("{");
_cppCode.Append("}");
}
else
{
_cppCode.Append("void {0}::from_bson(bson_iterator* iterator)", attributeClass.StructName);
_cppCode.BracketStart();
_cppCode.BracketStart("while (bson_iterator_next(iterator))");
_cppCode.Append("const char* field_name = bson_iterator_key(iterator);");
_cppCode.Append("const char* field_value = bson_iterator_string(iterator);");
foreach (var attributeField in nonVolatiles)
{
_cppCode.Append("if (stricmp(\"{0}\", field_name) == 0) {0} = boost::lexical_cast<{1}>(field_value);",
attributeField.Name, TypeUtil.ToDeclareTypeName(attributeField.Type));
}
_cppCode.BracketEnd();
_cppCode.BracketEnd();
}
}
#endregion
#region to_bson
{
_cppCode.Append("void {0}::to_bson(bson* obj)", attributeClass.StructName);
_cppCode.BracketStart();
_cppCode.Append("bson_append_start_object(obj, \"{0}\");", attributeClass.Name);
foreach (var attributeField in attributeClass.NonVolatileFields)
{
_cppCode.Append("bson_append_string(obj, \"{0}\", boost::lexical_cast<std::string>({0}).c_str());",
attributeField.Name);
}
_cppCode.Append("bson_append_finish_object(obj);");
_cppCode.BracketEnd();
}
#endregion
#region from_xml
{
var nonVolatileFields = attributeClass.NonVolatileFields.ToArray();
var primitives = nonVolatileFields.Where(e => TypeUtil.IsPrimitiveType(e.Type)).ToArray();
var nonPrimitives = nonVolatileFields.Where(e => !TypeUtil.IsPrimitiveType(e.Type)).ToArray();
if (!primitives.Any() && !nonPrimitives.Any())
{
_cppCode.Append("void {0}::from_xml(TiXmlElement*)", attributeClass.StructName);
_cppCode.Append("{");
_cppCode.Append("}");
}
else
{
_cppCode.Append("void {0}::from_xml(TiXmlElement* node)", attributeClass.StructName);
_cppCode.BracketStart();
// primitive type은 attribute로 값을 넣어준다.
_cppCode.Append("const char* attr_value = nullptr;");
foreach (var attributeField in primitives)
{
if (attributeField.Type == TypeEnum.INT || attributeField.Type == TypeEnum.DOUBLE)
//.........这里部分代码省略.........
示例4: GenerateModelCode
public SourceCode GenerateModelCode()
{
var code = new SourceCode();
code.BracketStart("struct {0}", TypeName);
code.IndentRight();
foreach (var field in Fields.Values)
code.Append(field.GenerateModelCode());
if (HasContent)
code.Append("std::string {0};", IsNameContent ? "name" : "content");
if (NodeCount > 1)
{
code.NewLine();
code.Append("~{0}()", TypeName);
code.BracketStart();
foreach (var field in DataClassFields)
{
if (field.Class.HasId) code.Append("CLEAR_POINTER_MAP({0}, {1});", field.Class.CollectionTypeName, field.Class.CollectionName);
else code.Append("CLEAR_POINTER_LIST({0}, {1});", field.Class.TypeName, field.Class.CollectionName);
}
code.BracketEnd();
}
code.BracketEnd(";");
return code;
}
示例5: GenerateParserFile
private void GenerateParserFile()
{
const string clientCppFileName = "data_center_client.cpp";
const string serverCppFileName = "data_center_server.cpp";
// generate parser file
var parser = new SourceCode();
parser.Append("#include <data_expression.h>");
parser.Append("#include <data_center.h>");
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("#include \"{0}\"", clazz.HeaderFileName);
parser.NewLine();
parser.Append("#pragma warning( disable : 4996 )");
parser.NewLine();
parser.Append("using namespace data;");
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("template <> typename data_center<{0}>::storage_t* data_center<{0}>::storage = nullptr;", clazz.TypeName);
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("template <> data_linker_t data_center<{0}>::linker;", clazz.TypeName);
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append(clazz.GenerateParseDeclsCode().Generate());
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
{
parser.Append(clazz.GenerateParseCode().Generate());
parser.NewLine();
}
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
{
parser.Append("void data::__data_load(data_type_t<{0}>)", clazz.TypeName);
parser.BracketStart();
parser.Append("TiXmlDocument document;");
parser.Append("document.LoadFile(user_defined_path_resolver(\"{0}\"));", clazz.XmlFileName.Replace("\\", "\\\\"));
parser.Append("TiXmlElement* root_node = document.FirstChildElement(\"{0}\");", clazz.XmlRootName);
parser.Append("parse_{0}(root_node->FirstChildElement(\"{1}-list\"));", clazz.ParserName, clazz.XmlNodeName);
parser.BracketEnd();
parser.NewLine();
}
SourceCode.StaticInitializerSerial = 99;
parser.StaticInitializerStart();
{
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("data::__data_load(data_type_t<{0}>());", clazz.TypeName);
parser.NewLine();
foreach (var clazz in DataCenter.Instance.Values)
parser.Append("{0}_data::linker.link();", clazz.SimpleName);
}
parser.StaticInitializerEnd();
parser.NewLine();
parser.Append("#pragma warning( default : 4996 )");
parser.NewLine();
parser.WriteToFile(Path.Combine(_outputDirectory, clientCppFileName), "#include <clientpch.h>");
parser.WriteToFile(Path.Combine(_outputDirectory, serverCppFileName), "#include <serverpch.h>");
}
示例6: GenerateHeaders
private void GenerateHeaders(AttributeClass attributeClass)
{
var code = new SourceCode();
code.Append("#pragma once");
code.NewLine();
code.Append("#include \"cbes/attribute.h\"");
code.NewLine();
code.BracketStart("struct {0} : public attribute_t<{0}>", attributeClass.StructName);
foreach (var attributeField in attributeClass.Fields)
{
code.Append("{2}{0} {1};", TypeUtil.ToDeclareTypeName(attributeField.Type), attributeField.Name, attributeField.Volatile ? "volatile " : "");
}
code.NewLine();
code.Append("// default constructor");
var constructorArgs = attributeClass.Fields.Select(
e => string.Format("{0}({1})", e.Name, e.Default ?? TypeUtil.ToDefaultValueInInitializer(e.Type))).ToList();
if (constructorArgs.Count > 0)
{
code.Append("{0}()", attributeClass.StructName);
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", constructorArgs));
code.IndentLeft();
}
else code.Append("{0}() {{}}", attributeClass.StructName);
if (attributeClass.NonDefaultFields.Any())
{
code.NewLine();
code.Append("// argumented constructor");
var paramArgs = new List<string>();
var initializeArgs = new List<string>();
// default가 없는 field를 대상으로만 argumented constructor를 만들어준다.
foreach (var attributeField in attributeClass.Fields)
{
if (attributeField.Default == null)
{
paramArgs.Add(string.Format("{0} _{1}", TypeUtil.ToArgumentTypeName(attributeField.Type), attributeField.Name));
initializeArgs.Add(string.Format("{0}(_{0})", attributeField.Name));
}
else
{
initializeArgs.Add(string.Format("{0}({1})", attributeField.Name, attributeField.Default));
}
}
if (initializeArgs.Count > 0)
{
code.Append("{0}({1})", attributeClass.StructName, string.Join(", ", paramArgs));
code.IndentRight();
code.Append(": {0} {{}}", string.Join(", ", initializeArgs));
code.IndentLeft();
}
}
code.NewLine();
code.Append(SourceCode.Parse(@"
virtual void from_bson(bson_iterator*);
virtual void to_bson(bson*);
virtual void from_xml(TiXmlElement*);
virtual void to_xml(std::ostream&);".Trim()));
if (attributeClass.CustomCode != null)
{
code.NewLine();
code.Append(SourceCode.Parse(attributeClass.CustomCode));
}
code.BracketEnd(";");
code.Append("typedef boost::shared_ptr<{0}> {1};", attributeClass.StructName, attributeClass.ReferenceName);
code.NewLine();
var headerPath = Path.Combine(_outputDirectory, attributeClass.HeaderFileName);
code.WriteToFile(headerPath);
}
示例7: GenerateReaderWriter
private SourceCode GenerateReaderWriter(CodeContext context)
{
var code = new SourceCode();
code.Append("#pragma region /* reader & writer */");
code.NewLine();
foreach (var msg in SortedMessages)
{
var accessor = context.StartAccessor("msg");
code.Append("template <>");
code.Append("inline msg_writer& msg_writer::operator << (const {0}& {1})", msg.CanonicalName, accessor);
code.BracketStart();
code.Append("(*this) << {0};", msg.MessageTypeName);
msg.Fields.ForEach(field => code.Append(field.GenerateWriter(context)));
code.Append("return (*this);");
code.BracketEnd();
code.NewLine();
code.Append("template <>");
code.Append("inline msg_reader& msg_reader::operator >> ({0}& {1})", msg.CanonicalName, accessor);
code.BracketStart();
msg.Fields.ForEach(field => code.Append(field.GenerateReader(context)));
code.Append("return (*this);");
code.BracketEnd();
code.NewLine();
context.EndAccessor();
}
code.Append("#pragma endregion");
return code;
}
示例8: Generate
public void Generate(string outputDirectory, string directionName)
{
var msgFileName = Path.Combine(outputDirectory, Name + "_msg.h");
var code = new SourceCode();
code.Append("#pragma once");
code.NewLine();
code.Append("#include <msg_def.h>");
code.Append("#include <msg_reader.h>");
code.Append("#include <msg_writer.h>");
code.Append("#include <msg_session_ref.h>");
code.NewLine();
code.Append("#pragma warning (disable: 4100)");
code.NewLine();
code.Append(GenerateMsgType());
code.Append("namespace msg {");
code.NewLine();
var context = new CodeContext();
foreach (var msg in SortedMessages)
{
code.BracketStart("struct {0}", msg.ClassName);
code.Append("static const msg_type_t __type = msg_type::{0};", msg.Name);
code.NewLine();
context.StartAccessor("msg");
msg.Fields.ForEach(field => code.Append(field.GenerateField(context)));
code.NewLine();
code.Append(msg.GenerateArgumentedConstructor());
code.Append(msg.Fields.GenerateDefaultConstructor(msg.ClassName));
code.Append(msg.GenerateHandlerDeclaration());
context.EndAccessor();
code.BracketEnd(";");
code.NewLine();
}
code.Append("}");
code.NewLine();
code.NewLine();
code.Append(GenerateReaderWriter(context));
code.NewLine();
code.NewLine();
code.Append("namespace msg {");
foreach (var msg in SortedMessages)
{
context.StartAccessor("msg");
code.Append(msg.GenerateHandlerBody(context));
context.EndAccessor();
code.NewLine();
}
code.Append("}");
code.NewLine();
if (!String.IsNullOrWhiteSpace(directionName))
{
code.Append(GenerateEntityBindCode(directionName));
code.NewLine();
}
code.NewLine();
code.Append("#pragma warning (default: 4100)");
code.WriteToFile(msgFileName);
}
示例9: GenerateMsgType
private SourceCode GenerateMsgType()
{
var code = new SourceCode();
code.BracketStart("namespace msg_type");
var msgSerial = 0;
foreach (var msg in Messages)
{
code.Append("const msg_type_t {0} = {1};", msg.Name, _id*1000 + msgSerial);
++msgSerial;
}
code.BracketEnd();
code.NewLine();
code.NewLine();
return code;
}
示例10: GenerateParseCode
public override SourceCode GenerateParseCode()
{
var code = new SourceCode();
switch (ValueType)
{
case TypeEnum.BOOL:
code.BracketStart();
code.Append("const char* _temp = each_node->Attribute(\"{0}\");", CanonicalName);
code.Append("ptr->{0} = _temp == nullptr? false: boost::lexical_cast<bool>(_temp);", CanonicalName);
code.BracketEnd();
break;
case TypeEnum.DATA_ENUM:
code.BracketStart();
code.Append("const char* _temp = each_node->Attribute(\"{0}\");", CanonicalName);
foreach (var value in Values.Distinct())
code.Append("if (stricmp(_temp, \"{2}\") == 0) ptr->{0} = {1}::{2};", CanonicalName, OwnedClass.QualifiedTypeName, value.Substring(1).ToEnumName());
// remove leading _ char
code.BracketEnd();
break;
case TypeEnum.DATA_ID:
case TypeEnum.INT:
case TypeEnum.DOUBLE:
code.Append("each_node->Attribute(\"{0}\", &ptr->{0});", CanonicalName);
break;
case TypeEnum.DATA_POS:
code.Append("parse_data_xyz(each_node->Attribute(\"{0}\"), &ptr->{0});", CanonicalName);
break;
case TypeEnum.STRING:
code.Append("ptr->{0} = std::string(each_node->Attribute(\"{0}\"));", CanonicalName);
break;
case TypeEnum.DATA_REFERENCE:
code.Append("ptr->{0} = nullptr;", CanonicalName);
break;
case TypeEnum.DATA_EXPRESSION:
code.Append("ptr->{0} = expression_parser_t(each_node->Attribute(\"{0}\")).result();", CanonicalName);
break;
}
return code;
}
示例11: GenerateModelCode
public override SourceCode GenerateModelCode()
{
var code = new SourceCode();
if (ValueType == TypeEnum.DATA_ENUM)
{
code.BracketStart("enum {0}", EnumTypeName);
foreach (var value in Values.Distinct())
code.Append("{0},", value.Substring(1).ToEnumName()); // remove leading _ char
code.BracketEnd(";");
}
code.Append("{0} {1};", TypeString, CanonicalName);
return code;
}
示例12: GenerateHandlerBody
public SourceCode GenerateHandlerBody(CodeContext context)
{
var code = new SourceCode();
code.Append("inline void {0}::handle(msg_session_ref session, const type& msg)", CanonicalName);
code.BracketStart();
code.Append("_ASSERT(_handler != NULL);");
code.Append("_handler(session, msg);");
Fields.ForEach(field => code.Append(field.GenerateHandler(context)));
code.BracketEnd();
code.NewLine();
code.Append("inline void {0}::handle(msg_session_ref session, msg_reader reader)", CanonicalName);
code.BracketStart();
var accessor = context.StartAccessor("msg");
{
code.Append("{0} {1};", ClassName, accessor);
code.Append("reader >> {0};", accessor);
code.Append("handle(session, {0});", accessor);
}
context.EndAccessor();
code.BracketEnd();
code.NewLine();
code.Append("inline void {0}::broadcast(const type& msg)", CanonicalName);
code.BracketStart();
context.StartAccessor("msg");
{
code.Append(CodeUtil.ForEachCode("listener_list", "_listeners.", "iter", false));
code.IndentRight();
// not-recursive ref
code.Append("(*iter)(msg);");
code.BracketEnd();
}
context.EndAccessor();
code.BracketEnd();
return code;
}
示例13: GenerateEntityBindBodyCode
public SourceCode GenerateEntityBindBodyCode(Direction dir)
{
var operatorDir = dir == Direction.From ? "<<" : ">>";
var code = new SourceCode();
code.Append("inline void operator {2} ({0}{1}& msg, entity_ref entity)", dir == Direction.To ? "const " : "", CanonicalName, operatorDir);
code.BracketStart();
if (dir == Direction.From && Fields.Exists(e => e.Name.Equals("id")))
code.Append("msg.id = entity->id;");
foreach (var field in Fields.OfType<SimpleField>().Where(e => e.BindAttribute != null))
{
var msgVar = String.Format("msg.{0}", field.Name);
var entityVar = String.Format("entity->get<{0}_t>()->{1}", field.BindAttribute.AttributeName, field.BindAttribute.FieldName);
var format = String.Format("if (entity->has<{0}_t>()) ", field.BindAttribute.AttributeName) +
(dir == Direction.From ? "{0} = {1};" : "{1} = {0};");
code.Append(format, msgVar, entityVar);
}
var bindedRefMessageFields = Fields.OfType<RefField>().Where(e => e.Target != null && e.Target.HasAttributeBindedField && !(e is RefListField));
foreach (var field in bindedRefMessageFields)
code.Append("msg.{0} {1} entity;", field.TargetName, operatorDir);
code.BracketEnd();
code.NewLine();
return code;
}