예제 #1
0
        public static void GenerateClassMember(Behaviac.Design.VariableDef variable, StreamWriter stream, string indent, string var)
        {
            if (variable.ValueClass == Behaviac.Design.VariableDef.kConst)
            {
                Type type = variable.Value.GetType();
                if (Plugin.IsArrayType(type) || Plugin.IsCustomClassType(type) || Plugin.IsStringType(type))
                {
                    string nativeType = DataCsExporter.GetGeneratedNativeType(variable.NativeType);

                    bool setNull = Plugin.IsArrayType(type);
                    if (!setNull && Plugin.IsCustomClassType(type))
                    {
                        Attribute[] attributes = (Attribute[])type.GetCustomAttributes(typeof(Behaviac.Design.ClassDescAttribute), false);
                        if (attributes.Length > 0)
                        {
                            Behaviac.Design.ClassDescAttribute classDesc = (Behaviac.Design.ClassDescAttribute)attributes[0];
                            if (!classDesc.IsStruct)
                            {
                                setNull = true;
                            }
                        }
                    }

                    if (setNull)
                    {
                        var += " = null";
                    }

                    stream.WriteLine("{0}\t\t{1} {2};", indent, nativeType, var);
                }
            }
        }
예제 #2
0
        public static string GenerateCode(Behaviac.Design.VariableDef variable, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null)
        {
            string retStr = string.Empty;

            if (variable.ValueClass == Behaviac.Design.VariableDef.kConst || variable.ValueClass == Behaviac.Design.VariableDef.kPar)
            {
                bool shouldGenerate = true;
                if (variable.ValueClass == Behaviac.Design.VariableDef.kConst)
                {
                    Type type = variable.Value.GetType();
                    if (Plugin.IsArrayType(type) || Plugin.IsCustomClassType(type) || Plugin.IsStringType(type))
                    {
                        shouldGenerate = false;
                    }
                }

                if (shouldGenerate)
                {
                    retStr = DataCsExporter.GenerateCode(variable.Value, stream, indent, typename, var, caller, setValue);
                }
            }
            else if (variable.Property != null)
            {
                retStr = PropertyCsExporter.GenerateCode(variable.Property, stream, indent, typename, var, caller, setValue);
            }

            return(retStr);
        }
예제 #3
0
        public static void GenerateClassConstructor(Behaviac.Design.VariableDef variable, StreamWriter stream, string indent, string var)
        {
            if (variable.ValueClass == Behaviac.Design.VariableDef.kConst)
            {
                Type type = variable.Value.GetType();
                if (Plugin.IsArrayType(type) || Plugin.IsCustomClassType(type) || Plugin.IsStringType(type))
                {
                    if (Plugin.IsArrayType(type))
                    {
                        string nativeType = DataCsExporter.GetGeneratedNativeType(variable.NativeType);
                        int    startIndex = nativeType.IndexOf('<');
                        int    endIndex   = nativeType.LastIndexOf('>');
                        string itemType   = nativeType.Substring(startIndex + 1, endIndex - startIndex - 1);

                        ArrayCsExporter.GenerateCode(variable.Value, stream, indent + "\t\t\t", itemType, var);
                    }
                    else if (Plugin.IsCustomClassType(type))
                    {
                        StructCsExporter.GenerateCode(variable.Value, stream, indent + "\t\t\t", var, null, "");
                    }
                    else if (Plugin.IsStringType(type))
                    {
                        string nativeType = DataCsExporter.GetGeneratedNativeType(variable.NativeType);
                        string retStr     = DataCsExporter.GenerateCode(variable.Value, stream, indent + "\t\t\t", nativeType, string.Empty, string.Empty);
                        stream.WriteLine("{0}\t\t\t{1} = {2};", indent, var, retStr);
                    }
                }
            }
        }
예제 #4
0
 public static void GenerateClassMember(Behaviac.Design.VariableDef variable, StreamWriter stream, string indent, string var)
 {
     if (variable.ValueClass == Behaviac.Design.VariableDef.kConst)
     {
         Type type = variable.Value.GetType();
         if (Plugin.IsArrayType(type) || Plugin.IsCustomClassType(type) || Plugin.IsStringType(type))
         {
             string nativeType = DataCppExporter.GetBasicGeneratedNativeType(variable.NativeType);
             stream.WriteLine("{0}\t\t{1} {2};", indent, nativeType, var);
         }
     }
 }
예제 #5
0
 public static void PostGenerateCode(Behaviac.Design.VariableDef variable, StreamWriter stream, string indent, string typename, string var, string caller, object parent = null, string paramName = "", string setValue = null)
 {
     if (variable.ValueClass == Behaviac.Design.VariableDef.kConst)
     {
         Type type = variable.Value.GetType();
         if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(variable.Value, parent, paramName))
         {
             StructCsExporter.PostGenerateCode(variable.Value, stream, indent, var, parent, paramName);
         }
     }
     else if (variable.Property != null)
     {
         PropertyCsExporter.PostGenerateCode(variable.Property, variable.ArrayIndexElement, stream, indent, typename, var, caller, setValue);
     }
 }
예제 #6
0
        public static string GenerateCode(Behaviac.Design.MethodDef.Param param, StreamWriter stream, string indent, string typename, string var, string caller)
        {
            Behaviac.Design.ParInfo par = param.Value as Behaviac.Design.ParInfo;
            if (par != null)
            {
                return(ParInfoCsExporter.GenerateCode(par, stream, indent, typename, var, caller));
            }

            Behaviac.Design.VariableDef v = param.Value as Behaviac.Design.VariableDef;
            if (v != null)
            {
                return(VariableCsExporter.GenerateCode(v, stream, indent, typename, var, caller));
            }

            return(DataCsExporter.GenerateCode(param.Value, stream, indent, typename, var, caller));;
        }
예제 #7
0
        public static void PostGenerateCode(Behaviac.Design.MethodDef.Param param, StreamWriter stream, string indent, string typename, string var, string caller, object parent, string setValue)
        {
            Behaviac.Design.ParInfo par = param.Value as Behaviac.Design.ParInfo;
            if (par != null)
            {
                ParInfoCsExporter.PostGenerateCode(par, stream, indent, typename, var, caller);
                return;
            }

            Behaviac.Design.VariableDef v = param.Value as Behaviac.Design.VariableDef;
            if (v != null)
            {
                VariableCsExporter.PostGenerateCode(v, stream, indent, typename, var, caller, parent, param.Name, setValue);
                return;
            }

            Type type = param.Value.GetType();

            if (Plugin.IsCustomClassType(type) && !DesignerStruct.IsPureConstDatum(param.Value, parent, param.Name))
            {
                StructCsExporter.PostGenerateCode(param.Value, stream, indent, var, parent, param.Name);
            }
        }
예제 #8
0
        /// <summary>
        /// Generate code for the given value object.
        /// </summary>
        /// <param name="obj">The given object.</param>
        /// <param name="stream">The file stream for generating the codes.</param>
        /// <param name="indent">The indent string when generating the line of codes.</param>
        /// <param name="typename">The native type of the variable.</param>
        /// <param name="var">The variable for the given object when generating the codes.</param>
        /// <param name="caller">The caller for the method or the agent.</param>
        /// <returns>Returns the string generated value.</returns>
        public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller, string setValue = null)
        {
            string retStr = string.Empty;

            if (obj != null)
            {
                Type type = obj.GetType();

                if (obj is Behaviac.Design.MethodDef)
                {
                    Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef;
                    retStr = MethodCsExporter.GenerateCode(method, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.MethodDef.Param)
                {
                    Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param;
                    retStr = ParameterCsExporter.GenerateCode(param, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.ParInfo)
                {
                    Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo;
                    retStr = ParInfoCsExporter.GenerateCode(par, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.PropertyDef)
                {
                    Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef;
                    retStr = PropertyCsExporter.GenerateCode(property, stream, indent, typename, var, caller, setValue);
                }
                else if (obj is Behaviac.Design.VariableDef)
                {
                    Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef;
                    retStr = VariableCsExporter.GenerateCode(variable, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.RightValueDef)
                {
                    Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef;
                    retStr = RightValueCsExporter.GenerateCode(rightValue, stream, indent, typename, var, caller);
                }
                // Array type
                else if (Plugin.IsArrayType(type))
                {
                    retStr = var;

                    if (!string.IsNullOrEmpty(typename))
                    {
                        stream.WriteLine("{0}{1} {2};", indent, typename, var);
                    }
                    else
                    {
                        typename = DataCsExporter.GetGeneratedNativeType(type);
                    }

                    int    startIndex = typename.IndexOf('<');
                    int    endIndex   = typename.LastIndexOf('>');
                    string itemType   = typename.Substring(startIndex + 1, endIndex - startIndex - 1);

                    ArrayCsExporter.GenerateCode(obj, stream, indent, itemType, var);
                }
                // Struct type
                else if (Plugin.IsCustomClassType(type))
                {
                    retStr = var;

                    if (!string.IsNullOrEmpty(typename))
                    {
                        stream.WriteLine("{0}{1} {2};", indent, typename, var);
                    }

                    StructCsExporter.GenerateCode(obj, stream, indent, var, null, "");
                }
                // Other types
                else
                {
                    retStr = obj.ToString();

                    if (Plugin.IsStringType(type)) // string
                    {
                        retStr = string.Format("\"{0}\"", retStr);
                    }
                    else if (Plugin.IsCharType(type)) // char
                    {
                        char c = 'A';
                        if (retStr.Length >= 1)
                        {
                            c = retStr[0];
                        }

                        retStr = string.Format("\'{0}\'", c);
                    }
                    else if (Plugin.IsBooleanType(type)) // bool
                    {
                        retStr = retStr.ToLowerInvariant();
                    }
                    else if (Plugin.IsEnumType(type)) // enum
                    {
                        retStr = EnumCsExporter.GeneratedCode(obj);
                    }
                    else if (type == typeof(float)) // float
                    {
                        retStr += "f";
                    }

                    if (!string.IsNullOrEmpty(var))
                    {
                        if (string.IsNullOrEmpty(typename))
                        {
                            stream.WriteLine("{0}{1} = {2};", indent, var, retStr);
                        }
                        else
                        {
                            stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr);
                        }
                    }
                }
            }

            return(retStr);
        }
예제 #9
0
        /// <summary>
        /// WritePropertyValue
        /// </summary>
        /// <param name="file"></param>
        /// <param name="p"></param>
        /// <param name="o"></param>
        static private void WritePropertyValue(JArray file, DesignerPropertyInfo p, object o)
        {
            string str = p.GetExportValue(o);

            string[] tokens      = str.Split(' ');
            string   valueString = null;

            if (tokens.Length == 3 && tokens[0] == "const")
            {
                valueString = tokens[2];
            }
            else if (tokens.Length == 1)
            {
                valueString = str;
            }

            bool bW = false;

            if (valueString != null)
            {
                object obj = p.Property.GetValue(o, null);

                object v = null;

                Type valueType = null;
                Behaviac.Design.VariableDef varType = obj as Behaviac.Design.VariableDef;

                if (varType != null)
                {
                    valueType = varType.ValueType;
                }
                else
                {
                    Behaviac.Design.RightValueDef rvarType = obj as Behaviac.Design.RightValueDef;

                    if (rvarType != null)
                    {
                        if (rvarType.Method == null)
                        {
                            valueType = rvarType.ValueType;
                        }
                    }
                    else
                    {
                        Behaviac.Design.MethodDef mType = obj as Behaviac.Design.MethodDef;

                        if (mType != null)
                        {
                            Behaviac.Design.Debug.Check(true);
                        }
                        else
                        {
                            valueType = obj.GetType();
                        }
                    }
                }

                if (valueType != null && Plugin.InvokeTypeParser(null, valueType, valueString, (object value) => v = value, null))
                {
                    file.Add(new JObject {
                        { p.Property.Name, JsonConvert.SerializeObject(v) }
                    });
                    bW = true;
                }
            }

            if (!bW)
            {
                file.Add(new JObject {
                    { p.Property.Name, str }
                });
            }
        }
예제 #10
0
        /// <summary>
        /// Generate the native code for the given value object.
        /// </summary>
        /// <param name="obj">The given object.</param>
        /// <param name="stream">The file stream for generating the codes.</param>
        /// <param name="indent">The indent string when generating the line of codes.</param>
        /// <param name="typename">The native type of the variable.</param>
        /// <param name="var">The variable for the given object when generating the codes.</param>
        /// <param name="caller">The caller for the method or the agent.</param>
        /// <returns>Returns the string generated value.</returns>
        public static string GenerateCode(object obj, StreamWriter stream, string indent, string typename, string var, string caller)
        {
            string retStr = string.Empty;

            if (obj != null)
            {
                Type type = obj.GetType();

                if (obj is Behaviac.Design.MethodDef)
                {
                    Behaviac.Design.MethodDef method = obj as Behaviac.Design.MethodDef;
                    retStr = MethodCppExporter.GenerateCode(method, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.MethodDef.Param)
                {
                    Behaviac.Design.MethodDef.Param param = obj as Behaviac.Design.MethodDef.Param;
                    retStr = ParameterCppExporter.GenerateCode(param, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.ParInfo)
                {
                    Behaviac.Design.ParInfo par = obj as Behaviac.Design.ParInfo;
                    retStr = ParInfoCppExporter.GenerateCode(par, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.PropertyDef)
                {
                    Behaviac.Design.PropertyDef property = obj as Behaviac.Design.PropertyDef;
                    retStr = PropertyCppExporter.GenerateCode(property, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.VariableDef)
                {
                    Behaviac.Design.VariableDef variable = obj as Behaviac.Design.VariableDef;
                    retStr = VariableCppExporter.GenerateCode(variable, stream, indent, typename, var, caller);
                }
                else if (obj is Behaviac.Design.RightValueDef)
                {
                    Behaviac.Design.RightValueDef rightValue = obj as Behaviac.Design.RightValueDef;
                    retStr = RightValueCppExporter.GenerateCode(rightValue, stream, indent, typename, var, caller);
                }
                // Array type
                else if (Plugin.IsArrayType(type))
                {
                    retStr = var;

                    if (!string.IsNullOrEmpty(typename))
                    {
                        stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var);
                    }
                    else
                    {
                        typename = DataCppExporter.GetGeneratedNativeType(type);
                    }

                    int    startIndex = typename.IndexOf('<');
                    int    endIndex   = typename.LastIndexOf('>');
                    string itemType   = typename.Substring(startIndex + 1, endIndex - startIndex - 1);

                    ArrayCppExporter.GenerateCode(obj, stream, indent, itemType, var);
                }
                // Struct type
                else if (Plugin.IsCustomClassType(type))
                {
                    retStr = var;

                    if (!string.IsNullOrEmpty(typename))
                    {
                        if (typename.EndsWith("*"))
                        {
                            stream.WriteLine("{0}{1} {2} = NULL;", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var);
                        }
                        else
                        {
                            stream.WriteLine("{0}{1} {2};", indent, DataCppExporter.GetBasicGeneratedNativeType(typename), var);
                        }
                    }

                    StructCppExporter.GenerateCode(obj, stream, indent, var, null, "");
                }
                // Other types
                else
                {
                    retStr = obj.ToString();

                    if (Plugin.IsStringType(type)) // string
                    {
                        retStr = string.Format("\"{0}\"", retStr);
                        if (typename.StartsWith("behaviac::wstring"))
                        {
                            retStr = string.Format("StringUtils::MBSToWCS({0})", retStr);
                        }
                        else
                        {
                            retStr = string.Format("(char*)({0})", retStr);
                        }
                    }
                    else if (Plugin.IsBooleanType(type)) // bool
                    {
                        retStr = retStr.ToLowerInvariant();
                    }
                    else if (Plugin.IsEnumType(type)) // enum
                    {
                        retStr = EnumCppExporter.GeneratedCode(obj);
                    }
                    else if (Plugin.IsFloatType(type)) // float
                    {
                        if (retStr.Contains(".") && !retStr.EndsWith("f") && !retStr.EndsWith("F"))
                        {
                            retStr = retStr + "f";
                        }
                    }

                    if (!string.IsNullOrEmpty(var))
                    {
                        if (string.IsNullOrEmpty(typename))
                        {
                            stream.WriteLine("{0}{1} = {2};", indent, var, retStr);
                        }
                        else
                        {
                            typename = DataCppExporter.GetGeneratedNativeType(typename);

                            stream.WriteLine("{0}{1} {2} = {3};", indent, typename, var, retStr);
                        }
                    }
                }
            }

            return(retStr);
        }