Ejemplo n.º 1
0
        private void ReflectSerializedStructs(ICodeWriter writer)
        {
            foreach (var typePair in _typeFields)
            {
                var type = typePair.Key;

                using (var typeBlock = new IndentLevel(writer, $"BEGIN_SERIALIZE_TYPE({type})", $"END_SERIALIZE_TYPE({type})"))
                {
                    foreach (var field in typePair.Value)
                    {
                        if (field.asFunc)
                        {
                            typeBlock.WriteLine($"SERIALIZE_FUNCTION({type}, {field.name})");
                        }
                        else if (field.asRef)
                        {
                            typeBlock.WriteLine($"SERIALIZE_FIELD_ALIAS({type}, {field.name})");
                        }
                        else
                        {
                            typeBlock.WriteLine($"SERIALIZE_FIELD({type}, {field.name})");
                        }
                    }
                }

                writer.WriteLine();
            }
        }
Ejemplo n.º 2
0
        private void ReflectSerializedVectors(ICodeWriter writer)
        {
            foreach (var vectorType in _serializedVectorTypes)
            {
                string type = $"hrt::vector<{vectorType}>";

                using (var vec = new IndentLevel(writer, $"BEGIN_SERIALIZE_TYPE({type})", $"END_SERIALIZE_TYPE({type})"))
                {
                    vec.WriteLine($"SERIALIZE_FUNCTION_ALIAS({type}, emplace_back<>)");
                    vec.WriteLine($"SERIALIZE_FUNCTION_ALIAS({type}, reserve)");
                }
                writer.WriteLine();
            }
        }
Ejemplo n.º 3
0
        private void ReflectBaseTypes(ICodeWriter writer)
        {
            var baseTypes = new[] { "int8_t", "uint8_t", "int16_t", "uint16_t", "int32_t", "uint32_t", "int64_t", "uint64_t", "bool", "float", "double" };

            foreach (var type in baseTypes)
            {
                using (var baseType = new IndentLevel(writer, $"BEGIN_SERIALIZE_TYPE({type})", $"END_SERIALIZE_TYPE({type})"))
                {
                    baseType.WriteLine($"SERIALIZE_SELF_ACCESS({type}, &ReflectionSet<{type}>, &ReflectionGet<{type}>)");

                    if (type == "uint32_t")
                    {
                        baseType.WriteLine("SERIALIZE_CONVERSION(uint32_t, int32_t)");
                        baseType.WriteLine("SERIALIZE_CONVERSION(uint32_t, int16_t)");
                        baseType.WriteLine("SERIALIZE_CONVERSION(uint32_t, int8_t)");
                    }
                    else if (type == "int32_t")
                    {
                        baseType.WriteLine("SERIALIZE_CONVERSION(int32_t, uint32_t)");
                        baseType.WriteLine("SERIALIZE_CONVERSION(int32_t, uint16_t)");
                        baseType.WriteLine("SERIALIZE_CONVERSION(int32_t, uint8_t)");
                    }
                }

                writer.WriteLine();
            }
        }
Ejemplo n.º 4
0
        private void ReflectSerializedStrings(ICodeWriter writer)
        {
            _serializedStringSizes.Add(SerializedDataPathSize);

            using (var baseType = new IndentLevel(writer, "BEGIN_SERIALIZE_TYPE_ADDITIVE(const char*)", "END_SERIALIZE_TYPE(const char*)"))
            {
                foreach (var size in _serializedStringSizes)
                {
                    baseType.WriteLine($"SERIALIZE_CONVERSION(const char*, &SerializedString<{size}>::CreateFromCString)");
                }
            }
            writer.WriteLine();

            foreach (var size in _serializedStringSizes)
            {
                using (var block = new IndentLevel(writer, $"BEGIN_SERIALIZE_TYPE_ADDITIVE(SerializedString<{size}>)", $"END_SERIALIZE_TYPE(SerializedString<{size}>)"))
                    block.WriteLine($"SERIALIZE_SELF_ACCESS(SerializedString<{size}>, &ReflectionSet<SerializedString<{size}>>, &ReflectionGet<SerializedString<{size}>>)");
                writer.WriteLine();
            }
        }
Ejemplo n.º 5
0
        private void WriteHeader(ICodeWriter writer)
        {
            writer.WriteLine("#include \"gen/gen.h\"");
            writer.WriteLine("#include <heart/codegen/codegen.h>");
            writer.WriteLine("#include <heart/deserialization/deserialization.h>");
            writer.WriteLine();
            foreach (var incl in _includes.Distinct())
            {
                writer.WriteLine($"#include \"{incl}\"");
            }
            writer.WriteLine();

            writer.WriteLine("template <typename T>");
            writer.WriteLine("void ReflectionSet(T& prop, T value)");
            using (var f = new IndentLevel(writer, "{", "}"))
                f.WriteLine("prop = value;");
            writer.WriteLine();

            writer.WriteLine("template <typename T>");
            writer.WriteLine("T ReflectionGet(T& prop)");
            using (var f = new IndentLevel(writer, "{", "}"))
                f.WriteLine("return prop;");
            writer.WriteLine();
        }