Esempio n. 1
0
 public override SourceCode GenerateField(CodeContext context)
 {
     var code = new SourceCode();
     code.Append("typedef std::vector<{0}> {1};", CanonicalTarget, TypeName);
     code.Append("{0} {1};", TypeName, VarName);
     return code;
 }
Esempio n. 2
0
 public override SourceCode GenerateReader(CodeContext context)
 {
     var code = new SourceCode();
     code.Append("this->skip(static_cast<msg_size_t>(sizeof(msg_type_t)));");
     code.Append("(*this) >> {0};", GetVarAccessor(context));
     return code;
 }
Esempio n. 3
0
 public override SourceCode GenerateHandler(CodeContext context)
 {
     var code = new SourceCode();
     var listAccessor = GetVarAccessor(context);
     var iteratorName = context.StartIterator();
     code.Append(CodeUtil.ForEachCode(TypeName, listAccessor, iteratorName, true));
     code.IndentRight();
     code.Append("{0}::handle(session, *{1});", CanonicalTarget, iteratorName);
     code.BracketEnd();
     context.EndIterator();
     return code;
 }
Esempio n. 4
0
 public override SourceCode GenerateField(CodeContext context)
 {
     var code = new SourceCode();
     code.Append("struct {0} {{", Name);
     code.IndentRight();
     Fields.ForEach(field => code.Append(field.GenerateField(context)));
     code.NewLine();
     code.Append(Fields.GenerateDefaultConstructor(Name));
     code.BracketEnd(";");
     code.Append("typedef std::vector<{0}> {1};", Name, TypeName);
     code.Append("{0} {1};", TypeName, VarName);
     return code;
 }
Esempio n. 5
0
 public override SourceCode GenerateWriter(CodeContext context)
 {
     var code = new SourceCode();
     var listAccessor = GetVarAccessor(context);
     var iteratorName = context.StartIterator();
     code.Append("(*this) << static_cast<uint32_t>({0}size());", listAccessor);
     code.Append(CodeUtil.ForEachCode(CanonicalType, listAccessor, iteratorName, true));
     code.IndentRight();
     code.Append("(*this) << (*{0});", iteratorName);
     code.BracketEnd();
     context.EndIterator();
     return code;
 }
Esempio n. 6
0
        public override SourceCode GenerateHandler(CodeContext context)
        {
            var code = new SourceCode();
            if (Fields.Count(field => field is RefField) == 0)
                return code;

            var listAccessor = GetVarAccessor(context);
            var iteratorName = context.StartIterator();
            code.Append(CodeUtil.ForEachCode(TypeName, listAccessor, iteratorName, true));
            code.IndentRight();
            Fields.ForEach(field => code.Append(field.GenerateHandler(context)));
            code.BracketEnd();
            context.EndIterator();
            return code;
        }
Esempio n. 7
0
        public override SourceCode GenerateReader(CodeContext context)
        {
            var code = new SourceCode();
            var countVar = Name + "_count";
            code.Append("uint32_t {0};", countVar);
            code.Append("(*this) >> {0};", countVar);

            code.Append("for (uint32_t index = 0; index < {0}; ++index) {{", countVar);
            code.IndentRight();

            var listAccessor = GetVarAccessor(context);
            var eachVariable = context.StartAccessor("each");
            code.Append("{0} {1};", CanonicalName, eachVariable);
            Fields.ForEach(field => code.Append(field.GenerateReader(context)));
            code.Append("{0}push_back({1});", listAccessor, eachVariable);
            code.BracketEnd();
            context.EndAccessor();
            return code;
        }
Esempio n. 8
0
        public override SourceCode GenerateReader(CodeContext context)
        {
            var code = new SourceCode();
            var countVar = Name + "_count";
            code.Append("uint32_t {0};", countVar);
            code.Append("(*this) >> {0};", countVar);

            var listAccessor = GetVarAccessor(context);
            code.Append("for (uint32_t index = 0; index < {0}; ++index) {{", countVar);
            code.IndentRight();
            var eachVariable = context.StartAccessor("each");
            code.Append("{0} {1};", CanonicalTarget, eachVariable);
            code.Append("this->skip(static_cast<msg_size_t>(sizeof(msg_type_t)));");
            code.Append("(*this) >> {0};", eachVariable);
            code.Append("{0}push_back({1});", listAccessor, eachVariable);
            context.EndAccessor();
            code.BracketEnd();
            return code;
        }
Esempio n. 9
0
 private string GetVarAccessor(CodeContext context)
 {
     return context.Accessor + VarName + ".";
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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;
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
File: Field.cs Progetto: ktj007/mmo
 public abstract SourceCode GenerateField(CodeContext context);
Esempio n. 14
0
 public override SourceCode GenerateHandler(CodeContext context)
 {
     return new SourceCode();
 }
Esempio n. 15
0
 public override SourceCode GenerateHandler(CodeContext context)
 {
     return new SourceCode().Append("{0}::handle(session, {1});", CanonicalTarget, GetVarAccessor(context));
 }
Esempio n. 16
0
 public override SourceCode GenerateField(CodeContext context)
 {
     return new SourceCode().Append("{0} {1};", CanonicalTarget, Name);
 }
Esempio n. 17
0
File: Field.cs Progetto: ktj007/mmo
 public abstract SourceCode GenerateWriter(CodeContext context);
Esempio n. 18
0
File: Field.cs Progetto: ktj007/mmo
 public abstract SourceCode GenerateReader(CodeContext context);
Esempio n. 19
0
File: Field.cs Progetto: ktj007/mmo
 public abstract SourceCode GenerateHandler(CodeContext context);
Esempio n. 20
0
 public override SourceCode GenerateWriter(CodeContext context)
 {
     return new SourceCode().Append("(*this) << {0};", GetVarAccessor(context));
 }
Esempio n. 21
0
 public override SourceCode GenerateField(CodeContext context)
 {
     return new SourceCode().Append("{0} {1};", TypeUtil.ToDeclareTypeName(Type), Name);
 }