Exemplo n.º 1
0
        private static string BoxedType(fieldType node, string suffix)
        {
            switch (node.type)
            {
            case typeType.nestedMessage:
                return(node.messageType + suffix);

            case typeType.referenceMessage:
                return(node.messageType + suffix);

            case typeType.@enum:
                return(node.enumType);

            case typeType.uint32:
                return("Integer");

            case typeType.int32:
                return("Integer");

            case typeType.@string:
                return("String");

            case typeType.@bool:
                return("Boolean");

            default:
                return(node.type.ToString());
            }
        }
Exemplo n.º 2
0
        private static Type TranslateFieldType(fieldType type)
        {
            switch (type)
            {
            case fieldType.@double:
            case fieldType.percent:
                return(typeof(double));

            case fieldType.@int:
                return(typeof(int));

            case fieldType.boolean:
                return(typeof(bool));

            case fieldType.currency:
                return(typeof(decimal));

            case fieldType.date:
            case fieldType.datetime:
            case fieldType.time:
                return(typeof(DateTime));

            default:
                return(typeof(string));
            }
        }
Exemplo n.º 3
0
        private static string FieldType(fieldType node)
        {
            switch (node.type)
            {
            case typeType.nestedMessage:
                return(node.messageType);

            case typeType.referenceMessage:
                return(node.messageType);

            case typeType.@enum:
                return(node.enumType);

            case typeType.uint64:
                return("unsigned long");

            case typeType.uint32:
                return("unsigned int");

            case typeType.int64:
                return("long");

            case typeType.int32:
                return("int");

            case typeType.@string:
                return("std::string");

            default:
                return(node.type.ToString());
            }
        }
Exemplo n.º 4
0
        public parameter AddParameter(string Name, object Value, fieldType FieldType, inoutType InOut, int Size = 0)
        {
            if (this.parameters == null)
                this.parameters = new parameters();

            if (this.parameters.parameter == null)
                this.parameters.parameter = new List<parameter>();

            var parm = new parameter() { name = Name, type = FieldType, inout = InOut };

            var temp = this.parameters.parameter.Where(a => a.name == Name).FirstOrDefault();
            if (temp != null)
                this.parameters.parameter.Remove(temp);

            this.parameters.parameter.Add(parm);
            parm.Text = new List<string>();

            if(Size != 0) {
                parm.size = Size;
                parm.sizeSpecified = true;
            }

            if (Value != null)
                parm.Text.Add(Value.ToString());

            return parm;

        }
Exemplo n.º 5
0
        private static string FieldType(fieldType node)
        {
            switch (node.type)
            {
            case typeType.nestedMessage:
                return(node.messageType);

            case typeType.referenceMessage:
                return(node.messageType);

            case typeType.@enum:
                return(node.enumType);

            case typeType.uint32:
                return("int");

            case typeType.int32:
                return("int");

            case typeType.@string:
                return("String");

            case typeType.@bool:
                return("boolean");

            default:
                return(node.type.ToString());
            }
        }
Exemplo n.º 6
0
 // Set type of field item
 public void setFieldType(fieldType f)
 {
     if (this.iTypeMain == itemType.FIELD || this.iTypeSub == itemType.FIELD)
     {
         this.fType = f;
     }
     return;
 }
Exemplo n.º 7
0
        public void updateTextBox(string protocol, fieldType field, string value)
        {
            string txtBxName = protocol + "_" + field.ToString() + "_textBox";

            Control[] controls = this.Controls.Find(txtBxName, true);
            TextBox   txtBox   = controls[0] as TextBox;

            if (txtBox != null)
            {
                txtBox.Text = value;
            }
        }
Exemplo n.º 8
0
        private static bool HasBoxedType(fieldType node)
        {
            switch (node.type)
            {
            case typeType.uint32:
            case typeType.int32:
            case typeType.@bool:
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 9
0
        public override string val_toqry(string value, fieldType coltype, dbType type, string nullstr = null, bool add_operator = false, bool tostring = false)
        {
            if (value == null || (nullstr != null && value == nullstr))
            {
                return((add_operator ? " IS " : "") + "NULL");
            }

            string op = add_operator ? " = " : "", ap = !tostring ? "'" : "";

            if (coltype == fieldType.DATETIME)
            {
                return(op + ap + DateTime.Parse(value).ToString(_dateFormatToQuery) + ap);
            }
            else if (coltype == fieldType.DATETIME2)
            {
                return(op + ap + DateTime.Parse(value).ToString(_dateFormatToQuery2) + ap);
            }
            else if (coltype == fieldType.INTEGER || coltype == fieldType.LONG ||
                     coltype == fieldType.SINGLE || coltype == fieldType.SMALLINT)
            {
                return(op + value);
            }
            else if (coltype == fieldType.CHAR || coltype == fieldType.TEXT || coltype == fieldType.VARCHAR)
            {
                return(op + ap + value.Replace("'", "''") + ap);
            }
            else if (coltype == fieldType.XML)
            {
                return(op + ap + value.Replace("'", "''") + ap);
            }
            else if (coltype == fieldType.BOOL)
            {
                return(op + (bool.Parse(value) ? "1" : "0"));
            }
            else if (coltype == fieldType.DECIMAL || coltype == fieldType.DOUBLE || coltype == fieldType.MONEY)
            {
                return(op + value.Replace(",", "."));
            }
            else
            {
                throw new Exception("tipo di dati '" + coltype.ToString() + "' non supportato per l'importazione dei dati");
            }
        }
Exemplo n.º 10
0
        private DataType CreateFieldType(fieldType fieldType)
        {
            string        format     = fieldType.fieldFormat;
            List <string> nullValues = fieldType.nullValues == null ? null : new List <string>(fieldType.nullValues);

            string dataType = fieldType.dataType;

            if (dataType == null)
            {
                return(null);
            }

            switch (dataType.ToLower())
            {
            case "string":
                return(new StringDataType(format, nullValues));

            case "integer":
                return(new IntegerDataType(format, nullValues));

            case "float":
                return(new FloatDataType(format, nullValues));

            case "date":
                return(new DateDataType(format, nullValues));

            case "time":
                return(new TimeDataType(format, nullValues));

            case "boolean":
                return(new BooleanDataType(format, nullValues));

            case "link":
                return(new LinkDataType());

            default:
                throw new AddmlDefinitionParseException("Unknown datatype " + fieldType.dataType);
            }
        }
Exemplo n.º 11
0
        private static string FieldType(fieldType node, string suffix = "")
        {
            switch (node.type)
            {
            case typeType.nestedMessage:
                return(node.messageType + suffix);

            case typeType.referenceMessage:
                return(node.messageType + suffix);

            case typeType.@enum:
                return(node.enumType);

            case typeType.uint32:
                return("uint");

            case typeType.int32:
                return("int");

            default:
                return(node.type.ToString());
            }
        }
Exemplo n.º 12
0
        public override string val_toqry(string value, fieldType coltype, dbType type, string nullstr = null, bool add_operator = false, bool tostring = false)
        {
            if (value == null || (nullstr != null && value == nullstr))
            {
                return((add_operator ? " IS " : "") + "NULL");
            }

            string op = add_operator ? " = " : "", ap = !tostring ? "'" : "";

            if (coltype == fieldType.DATETIME)
            {
                return(op + "Format(#" + DateTime.Parse(value).ToString("yyyy/MM/dd HH:mm:ss") + "#, \"yyyy/mm/dd hh:nn:ss\")");
            }
            else if (coltype == fieldType.INTEGER || coltype == fieldType.LONG ||
                     coltype == fieldType.SMALLINT)
            {
                return(op + value);
            }
            else if (coltype == fieldType.CHAR || coltype == fieldType.VARCHAR ||
                     coltype == fieldType.TEXT)
            {
                return(op + ap + (!tostring ? value.Replace("'", "''") : value) + ap);
            }
            else if (coltype == fieldType.BOOL)
            {
                return(op + (bool.Parse(value) ? "True" : "False"));
            }
            else if (coltype == fieldType.DOUBLE || coltype == fieldType.SINGLE ||
                     coltype == fieldType.DECIMAL || coltype == fieldType.MONEY)
            {
                return(op + value.Replace(",", "."));
            }
            else
            {
                throw new Exception("tipo di dati '" + coltype.ToString() + "' non supportato per l'importazione dei dati");
            }
        }
Exemplo n.º 13
0
 private static string FieldType(fieldType node)
 {
     switch (node.type)
     {
         case typeType.nestedMessage:
             return node.messageType;
         case typeType.referenceMessage:
             return node.messageType;
         case typeType.@enum:
             return node.enumType;
         case typeType.uint32:
             return "int";
         case typeType.int32:
             return "int";
         case typeType.@string:
             return "String";
         case typeType.@bool:
             return "boolean";
         default:
             return node.type.ToString();
     }
 }
        public static string TranslateSFDCDataTypeToOracle10gDataType(fieldType SFDCType
            , int length, int precision, int scale)
        {
            string tmpReturn = "";
            string tmpDType = "VARCHAR2";
            string tmpPrecision = "";
            string tmpScale = "";

            switch (SFDCType)
            {
                case fieldType.id:
                    break;

                case fieldType.base64:
                    tmpDType = "BLOB";
                    break;

                // NOTE:
                // Let's actually display FALSE/TRUE as it comes from SFDC
                case fieldType.boolean:
                    tmpDType = "VARCHAR2";
                    length = 5;
                    break;

                case fieldType.currency:
                case fieldType.@double:
                case fieldType.percent:
                    tmpDType = "DECIMAL";
                    tmpPrecision = precision.ToString();
                    tmpScale = scale.ToString();
                    break;

                case fieldType.date:
                    tmpDType = "DATE";     //should be DT_DBDATE
                    break;

                case fieldType.datetime:
                    tmpDType = "TIMESTAMP";
                    break;

                case fieldType.@int:
                    tmpDType = "INT";
                    break;

                //    case fieldType.multipicklist:
                //    case fieldType.picklist:
                //        tmpDType = DataType.DT_WSTR;
                //        break;

            };

            // Modify some data types based on pure logic and constraints
            if (tmpDType == "VARCHAR2" || tmpDType=="LONG")
            {
                if (length > 4000)
                {
                    tmpDType = "LONG";
                    length = 0;
                }
            }

            if (tmpDType == "DECIMAL" || tmpDType == "VARCHAR2")
            {
                tmpReturn = tmpDType + "(";
                if (tmpDType == "DECIMAL")
                    tmpReturn += precision + "," + scale;
                else if (tmpDType == "VARCHAR2")
                    tmpReturn += length;
                tmpReturn += ")";
            }
            else
                tmpReturn = tmpDType;

            return tmpReturn;
        }
Exemplo n.º 15
0
 private static bool HasBoxedType(fieldType node)
 {
     switch (node.type)
     {
         case typeType.uint32:
         case typeType.int32:
         case typeType.@bool:
             return true;
         default:
             return false;
     }
 }
Exemplo n.º 16
0
 public schema_field create_schema_field(string table, string field, fieldType fld_tp)
 {
     return(new_schema_field(add_field(table, field, fld_tp)));
 }
Exemplo n.º 17
0
 public void set_original_type(dbType type_db, fieldType type)
 {
     _original_type = type_to_original(type_db, type);
 }
Exemplo n.º 18
0
        protected override void GenerateClassReferenceField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
                    @"        void add{1}({2}& item);
        void remove{1}({2}& item);
        std::vector<{2}*> {0}List();
        {2}& get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
                    @"        void Abstract{4}::add{1}({3}& item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            if (m_root != item.getRoot())
                throw std::runtime_error(""All objects should share the same root"");
            m_header.add_{2}()->CopyFrom(item.getLocalMessageDescriptor());
        }}

        void Abstract{4}::remove{1}({3}& item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto vals = m_header.mutable_{2}();
            auto newEnd = std::remove_if(vals->begin(), vals->end(), [this, &item](const LocalMessageDescriptor& check) 
            {{ 
                return getRoot()->decode(check) == &item; 
            }});
            vals->DeleteSubrange(newEnd - vals->begin(), vals->end() - newEnd);
        }}

        std::vector<{3}*> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}*>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(&get{1}(i));
            }}
            return list;
        }}

        {3}& Abstract{4}::get{1}(int index)
        {{
            return *dynamic_cast<{3}*>(getRoot()->decode(m_header.{2}(index)));
        }}

        int Abstract{4}::{0}Count() const
        {{
            return m_header.{2}_size();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
                    @"        bool has{0}() const {{ return m_header.has_{1}(); }}
        void clear{0}() {{ m_header.clear_{1}(); }}
"
                    , field.name.Capitalize(), field.name.ToLowerInvariant());
            }

            IncludeWriter.WriteLine(
                @"        void set{1}({2}& value);
        {2}* {0}();
"
                , field.name, field.name.Capitalize(), fieldType);

            CppWriter.WriteLine(
                @"        void Abstract{4}::set{1}({3}& value)
        {{
            if (m_root != value.getRoot())
                throw std::runtime_error(""All objects should share the same root"");
            m_header.clear_{2}();
            m_header.mutable_{2}()->CopyFrom(value.getLocalMessageDescriptor());
            // TODO see if that works // m_header.set_allocated_{2}(value.getLocalMessageDescriptor());
        }}

        {3}* Abstract{4}::{0}()
        {{
            return dynamic_cast<{3}*>(getRoot()->decode(m_header.{2}()));
        }}
"
                , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name);
        }
Exemplo n.º 19
0
        static public string getFieldAccess(string name, fieldType type, string numprec, string numscale, string maxlength, bool nullable, string defaultval, bool autonumber)
        {
            string sql = "[" + name + "]";

            if (autonumber)
            {
                sql += " AUTOINCREMENT";
            }
            else if (type == fieldType.BINARY)
            {
                sql += " BINARY";
            }
            else if (type == fieldType.BOOL)
            {
                sql += " BIT";
            }
            else if (type == fieldType.SMALLINT)
            {
                sql += " SMALLINT";
            }
            else if (type == fieldType.MONEY)
            {
                sql += " MONEY";
            }
            else if (type == fieldType.DATETIME)
            {
                sql += " DATETIME";
            }
            else if (type == fieldType.GUID)
            {
                sql += " UNIQUEIDENTIFIER";
            }
            else if (type == fieldType.DOUBLE)
            {
                sql += " DOUBLE";
            }
            else if (type == fieldType.SINGLE)
            {
                sql += " SINGLE";
            }
            else if (type == fieldType.INTEGER)
            {
                sql += " INTEGER";
            }
            else if (type == fieldType.LONG)
            {
                sql += " LONG";
            }
            else if (type == fieldType.DECIMAL)
            {
                sql += " DECIMAL(" + numprec + ", " + numscale + ")";
            }
            else if (type == fieldType.VARCHAR || type == fieldType.CHAR)
            {
                if (maxlength == "0")
                {
                    sql += " MEMO";
                }
                else
                {
                    sql += " VARCHAR(" + (maxlength == "-1" ? "255" : maxlength) + ")";
                }
            }
            else
            {
                throw new Exception("il campo '" + type.ToString() + "' di access non viene gestito per l'aggiornamento struttura tabelle");
            }

            if (defaultval != "")
            {
                sql += " DEFAULT " + defaultval;
            }
            if (!nullable)
            {
                sql += " NOT NULL";
            }

            return(sql);
        }
Exemplo n.º 20
0
        protected override void GenerateClassReferenceField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
@"        /// <summary>
        /// {2}
        /// </summary>
        public void Add{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.Add{0}(item.LocalMessageDescriptor);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public void Remove{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.{0}List.Remove(item.LocalMessageDescriptor);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public {1} Get{0}(int index)
        {{
            return ({1})Root.Decode(_header.Get{0}(index));
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public IEnumerable<{1}> {0}List
        {{
            get
            {{
                return Enumerable.Range(0, {0}Count).Select(Get{0});
            }}
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public int {0}Count
        {{
            get
            {{
                return _header.{0}Count;
            }}
        }}
"
                    , field.name.Capitalize(), fieldType, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
@"        /// <summary>
        /// {1}
        /// </summary>
        public bool Has{0}
        {{
            get
            {{
                return _header.Has{0};
            }}
        }}

        /// <summary>
        /// {1}
        /// </summary>
        public void Clear{0}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.Clear{0}();
        }}
"
                    , field.name.Capitalize(), field.description.Safe());
            }

            Writer.WriteLine(
@"        /// <summary>
        /// {2}
        /// </summary>
        public {1} {0}
        {{
            get
            {{
                return ({1})Root.Decode(_header.{0});
            }}
            set
            {{
                Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
                Builder.{0} = value.LocalMessageDescriptor;
            }}
        }}
"
                , field.name.Capitalize(), fieldType, field.description.Safe());
        }
Exemplo n.º 21
0
 private static string FieldType(fieldType node, string suffix = "")
 {
     switch (node.type)
     {
         case typeType.nestedMessage:
             return node.messageType + suffix;
         case typeType.referenceMessage:
             return node.messageType + suffix;
         case typeType.@enum:
             return node.enumType;
         case typeType.uint32:
             return "uint";
         case typeType.int32:
             return "int";
         default:
             return node.type.ToString();
     }
 }
Exemplo n.º 22
0
 protected abstract void GenerateClassNestedField(messageType message, fieldType field);
Exemplo n.º 23
0
 protected abstract void GenerateClassReferenceField(messageType message, fieldType field);
Exemplo n.º 24
0
 public parameter AddParameter(string Name, object Value, fieldType FieldType, inoutType InOut)
 {
     return AddParameter(Name, Value, FieldType, InOut, 0);
 }
Exemplo n.º 25
0
 public virtual string val_toqry(string value, fieldType coltype, string nullstr = null, bool add_operator = false, bool tostring = false)
 {
     return(val_toqry(value, coltype, _dbType, nullstr, add_operator, tostring));
 }
Exemplo n.º 26
0
 public void setOriginalType(dbType typeDb, fieldType type)
 {
     _originaltype = typeToOriginal(typeDb, type);
 }
Exemplo n.º 27
0
        protected override void GenerateClassNestedField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);
            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
@"        /// <summary>
        /// {4}
        /// </summary>
        public {2} Add{1}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");

            {2} item = new {2}()
            {{
                FieldId = {3}, 
                Index = _{0}.Count, 
                Parent = this
            }};

            _{0}.Add(item);
            return item;
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public IEnumerable<{2}> {1}List
        {{
            get
            {{
                return Enumerable.Range(0, {1}Count).Select(Get{1});
            }}
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public {2} Get{1}(int index)
        {{
            if (index >= {1}Count) return null;

            var {0} = _{0}[index];
            if ({0} == null)
            {{
                {0} = {2}.ParseFrom(ContentStream, _header.Get{1}(index));
                _{0}[index] = {0};
                {0}.FieldId = {3};
                {0}.Index = index;
                {0}.Parent = this;
            }}
            return {0};
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public int {1}Count
        {{
            get
            {{
                return !IsBuilt? _{0}.Count : _header.{1}Count;
            }}
        }}"
                    , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
@"        /// <summary>
        /// {3}
        /// </summary>
        public {2} Add{1}()
        {{
            if (_{0} == null)
            {{
                if (IsBuilt && Has{1})
                {{
                    {1}.Equals(null); // decode from body (C# needs a function call)
                }}
                else
                {{
                    Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
                    _{0} = new {2}()
                    {{
                        FieldId = {3}, 
                        Parent = this
                    }};
                }}
            }}
            return _{0};
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public {2} {1}
        {{
            get
            {{
                if (IsBuilt && Has{1} && _{0} == null)
                {{
                    _{0} = {2}.ParseFrom(ContentStream, _header.{1});
                    _{0}.FieldId = {3};
                    _{0}.Parent = this;
                }}
                return _{0};
            }}
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public bool Has{1}
        {{
            get
            {{
                return (IsBuilt && _header.Has{1}) || (!IsBuilt && _{0} != null);
            }}
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public void Clear{1}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            _{0} = null;
        }}
"
                    , field.name, field.name.Capitalize(), fieldType, field.id);
                return;
            }

            Writer.WriteLine(
@"        /// <summary>
        /// {4}
        /// </summary>
        public {2} {1}
        {{
            get
            {{
                if (_{0} == null)
                {{
                    if (IsBuilt)
                    {{
                        _{0} = {2}.ParseFrom(ContentStream, _header.{1});
                    }}
                    else
                    {{
                        _{0} = new {2}();
                    }}

                    _{0}.FieldId = {3};
                    _{0}.Parent = this;
                }}
                return _{0};
            }}
        }}
"
                , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
        }
Exemplo n.º 28
0
        /// <summary>
        /// Adds a new Parameter to the Parameter list
        /// guarantees the object and list are created
        /// and return the newly created parameter back for 
        /// convenience of setting additional parameters
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Value"></param>
        /// <param name="FieldType"></param>
        /// <returns></returns>
        public parameter AddParameter(string Name, object Value, fieldType FieldType)
        {
            if (this.parameters == null)
                this.parameters = new parameters();

            if (this.parameters.parameter == null)
                this.parameters.parameter = new List<parameter>();

            var parm = new parameter() { name = Name, type = FieldType };
            this.parameters.parameter.Add(parm);

            parm.Text = new List<string>();

            if(Value != null)
                parm.Text.Add(Value.ToString());

            return parm;
        }
Exemplo n.º 29
0
        protected override void GenerateClassSimpleField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {2}
        /// </summary>
        public void Add{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.Add{0}(item);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public void Remove{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.{0}List.Remove(item);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public {1} Get{0}(int index)
        {{
            return _header.Get{0}(index);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public IEnumerable<{1}> {0}List
        {{
            get
            {{
                return Enumerable.Range(0, {0}Count).Select(Get{0});
            }}
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public int {0}Count
        {{
            get
            {{
                return _header.{0}Count;
            }}
        }}
"
                    , field.name.Capitalize(), fieldType, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {1}
        /// </summary>
        public bool Has{0}
        {{
            get
            {{
                return _header.Has{0};
            }}
        }}        

        /// <summary>
        /// {1}
        /// </summary>
        public void Clear{0}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.Clear{0}();
        }}
"
                    , field.name.Capitalize(), field.description.Safe());
            }

            Writer.WriteLine(
                @"        /// <summary>
        /// {2}
        /// </summary>
        public {1} {0}
        {{
            get
            {{
                return _header.{0};
            }}
            set
            {{
                Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
                Builder.{0} = value;
            }}
        }}
"
                , field.name.Capitalize(), fieldType, field.description);
        }
Exemplo n.º 30
0
        protected override void GenerateClassNestedField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
                    @"        {2}& add{1}();
        std::vector<{2}*> {0}List();
        {2}& get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
                    @"        {3}& Abstract{4}::add{1}()
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto index = m_{0}List.size();
            auto {0} = std::make_unique<{3}>();
            {0}->setFieldId({5});
            {0}->setIndex(index);
            {0}->setParent(this);
            m_{0}List.set(index, std::move({0}));
            return *m_{0}List.get(index);
        }}

        std::vector<{3}*> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}*>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(&get{1}(i));
            }}
            return list;
        }}

        {3}& Abstract{4}::get{1}(int index)
        {{
            if (!m_{0}List.get(index))
            {{
                auto {0} = {3}::ParseFrom(contentStream(), m_header.{2}(index));
                {0}->setFieldId({5});
                {0}->setIndex(index);
                {0}->setParent(this);
                m_{0}List.set(index, std::move({0}));
            }}
            return *m_{0}List.get(index);
        }}

        int Abstract{4}::{0}Count() const
        {{
            return !isBuilt() ? m_{0}List.size() : m_header.{2}_size();
        }}"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, field.id);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
                    @"        {2}& add{1}(); // adds the optional {1}
        {2}* {0}();
        bool has{1}() const;
        void clear{1}();
        
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
                    @"        {3}& Abstract{4}::add{1}()
        {{
            if (m_{0} == nullptr)
            {{
                if (isBuilt() && has{1}())
                {{
                    {0}(); // decode from body
                }}
                else
                {{
                    assert((""Can't modify an already built object!"", !isBuilt()));
                    m_{0} = std::make_unique<{6}::{3}>();
                    m_{0}->setFieldId({5});
                    m_{0}->setParent(this);
                }}
            }}
            return *m_{0};
        }}

        {3}* Abstract{4}::{0}()
        {{
            if (isBuilt() && has{1}() && m_{0} == nullptr)
            {{
                m_{0} = {3}::ParseFrom(contentStream(), m_header.{2}());
                m_{0}->setFieldId({5});
                m_{0}->setParent(this);
            }}
            return m_{0}.get();
        }}

        bool Abstract{4}::has{1}() const
        {{
            return (isBuilt() && m_header.has_{2}()) || (!isBuilt() && m_{0} != nullptr);
        }}

        void Abstract{4}::clear{1}()
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            m_{0}.reset();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, field.id, Namespace);
                return;
            }

            IncludeWriter.WriteLine(@"        {1}& {0}();", field.name, fieldType);
            CppWriter.WriteLine(
                @"        {2}& Abstract{3}::{0}()
        {{
            if (m_{0} == nullptr)
            {{
                if (isBuilt())
                {{
                    m_{0} = {2}::ParseFrom(contentStream(), m_header.{1}());
                }}
                else
                {{
                    m_{0} = std::make_unique<{2}>();
                }}
                m_{0}->setFieldId({4});
                m_{0}->setParent(this);
            }}
            return *m_{0};
        }}
"
                , field.name, field.name.ToLowerInvariant(), fieldType, message.name, field.id);
        }
Exemplo n.º 31
0
        protected override void GenerateClassReferenceField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {2}
        /// </summary>
        public void Add{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            if (!ReferenceEquals(Root, item.Root))
                throw new ArgumentException(""All objects have to share the same root"");
            Builder.Add{0}(item.LocalMessageDescriptor);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public void Remove{0}({1} item)
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.{0}List.Remove(item.LocalMessageDescriptor);
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public {1} Get{0}(int index)
        {{
            return ({1})Root.Decode(_header.Get{0}(index));
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public IEnumerable<{1}> {0}List
        {{
            get
            {{
                return Enumerable.Range(0, {0}Count).Select(Get{0});
            }}
        }}

        /// <summary>
        /// {2}
        /// </summary>
        public int {0}Count
        {{
            get
            {{
                return _header.{0}Count;
            }}
        }}
"
                    , field.name.Capitalize(), fieldType, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {1}
        /// </summary>
        public bool Has{0}
        {{
            get
            {{
                return _header.Has{0};
            }}
        }}

        /// <summary>
        /// {1}
        /// </summary>
        public void Clear{0}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            Builder.Clear{0}();
        }}
"
                    , field.name.Capitalize(), field.description.Safe());
            }

            Writer.WriteLine(
                @"        /// <summary>
        /// {2}
        /// </summary>
        public {1} {0}
        {{
            get
            {{
                return ({1})Root.Decode(_header.{0});
            }}
            set
            {{
                Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
                if (!ReferenceEquals(Root, value.Root))
                    throw new ArgumentException(""All objects have to share the same root"");
                Builder.{0} = value.LocalMessageDescriptor;
            }}
        }}
"
                , field.name.Capitalize(), fieldType, field.description.Safe());
        }
Exemplo n.º 32
0
        public static string type_to_original(dbType type_db, fieldType type)
        {
            if (type_db == dbType.access)
            {
                if (type == fieldType.BINARY)
                {
                    return("binary");
                }
                else if (type == fieldType.BOOL)
                {
                    return("boolean");
                }
                else if (type == fieldType.MONEY)
                {
                    return("currency");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("date");
                }
                else if (type == fieldType.GUID)
                {
                    return("guid");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("double");
                }
                else if (type == fieldType.SINGLE)
                {
                    return("single");
                }
                else if (type == fieldType.SMALLINT)
                {
                    return("smallint");
                }
                else if (type == fieldType.INTEGER)
                {
                    return("integer");
                }
                else if (type == fieldType.DECIMAL)
                {
                    return("decimal");
                }
                else if (type == fieldType.VARCHAR)
                {
                    return("varchar");
                }
                else if (type == fieldType.CHAR)
                {
                    return("char");
                }
            }
            else if (type_db == dbType.sqlserver)
            {
                if (type == fieldType.BINARY)
                {
                    return("varbinary");
                }
                else if (type == fieldType.BOOL)
                {
                    return("bit");
                }
                else if (type == fieldType.MONEY)
                {
                    return("money");
                }
                else if (type == fieldType.SMALLDATETIME)
                {
                    return("smalldatetime");
                }
                else if (type == fieldType.VARIANT)
                {
                    return("sql_variant");
                }
                else if (type == fieldType.TIMESTAMP)
                {
                    return("timestamp");
                }
                else if (type == fieldType.DATE)
                {
                    return("date");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("datetime");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("float");
                }
                else if (type == fieldType.SMALLINT)
                {
                    return("smallint");
                }
                else if (type == fieldType.INTEGER)
                {
                    return("int");
                }
                else if (type == fieldType.LONG)
                {
                    return("bigint");
                }
                else if (type == fieldType.DECIMAL)
                {
                    return("decimal");
                }
                else if (type == fieldType.VARCHAR)
                {
                    return("varchar");
                }
                else if (type == fieldType.CHAR)
                {
                    return("char");
                }
                else if (type == fieldType.TEXT)
                {
                    return("text");
                }
                else if (type == fieldType.IMAGE)
                {
                    return("image");
                }
                else if (type == fieldType.XML)
                {
                    return("xml");
                }
                else if (type == fieldType.GUID)
                {
                    return("uniqueidentifier");
                }
            }
            else if (type_db == dbType.mysql)
            {
                if (type == fieldType.BINARY)
                {
                    return("varbinary");
                }
                else if (type == fieldType.BOOL)
                {
                    return("bit");
                }
                else if (type == fieldType.MONEY)
                {
                    return("decimal");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("datetime");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("double");
                }
                else if (type == fieldType.SMALLINT)
                {
                    return("smallint");
                }
                else if (type == fieldType.INTEGER)
                {
                    return("int");
                }
                else if (type == fieldType.LONG)
                {
                    return("bigint");
                }
                else if (type == fieldType.DECIMAL)
                {
                    return("decimal");
                }
                else if (type == fieldType.VARCHAR)
                {
                    return("varchar");
                }
                else if (type == fieldType.CHAR)
                {
                    return("char");
                }
                else if (type == fieldType.TEXT)
                {
                    return("text");
                }
                else if (type == fieldType.XML)
                {
                    return("varchar");
                }
            }
            else if (type_db == dbType.odbc)
            {
                if (type == fieldType.VARCHAR)
                {
                    return("System.String");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("System.Double");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("System.DateTime");
                }
                else if (type == fieldType.BOOL)
                {
                    return("System.Boolean");
                }
            }

            throw new Exception("type field '" + type.ToString() + "' not supported for '" + type_db.ToString() + "'");
        }
Exemplo n.º 33
0
        protected override void GenerateClassNestedField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {4}
        /// </summary>
        public {2} Add{1}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");

            {2} item = new {2}()
            {{
                FieldId = {3}, 
                Index = _{0}.Count, 
                Parent = this
            }};

            _{0}.Add(item);
            return item;
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public IEnumerable<{2}> {1}List
        {{
            get
            {{
                return Enumerable.Range(0, {1}Count).Select(Get{1});
            }}
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public {2} Get{1}(int index)
        {{
            if (index >= {1}Count) return null;

            var {0} = _{0}[index];
            if ({0} == null)
            {{
                {0} = {2}.ParseFrom(ContentStream, _header.Get{1}(index));
                _{0}[index] = {0};
                {0}.FieldId = {3};
                {0}.Index = index;
                {0}.Parent = this;
            }}
            return {0};
        }}

        /// <summary>
        /// {4}
        /// </summary>
        public int {1}Count
        {{
            get
            {{
                return !IsBuilt? _{0}.Count : _header.{1}Count;
            }}
        }}"
                    , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
                    @"        /// <summary>
        /// {3}
        /// </summary>
        public {2} Add{1}()
        {{
            if (_{0} == null)
            {{
                if (IsBuilt && Has{1})
                {{
                    {1}.Equals(null); // decode from body (C# needs a function call)
                }}
                else
                {{
                    Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
                    _{0} = new {2}()
                    {{
                        FieldId = {3}, 
                        Parent = this
                    }};
                }}
            }}
            return _{0};
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public {2} {1}
        {{
            get
            {{
                if (IsBuilt && Has{1} && _{0} == null)
                {{
                    _{0} = {2}.ParseFrom(ContentStream, _header.{1});
                    _{0}.FieldId = {3};
                    _{0}.Parent = this;
                }}
                return _{0};
            }}
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public bool Has{1}
        {{
            get
            {{
                return (IsBuilt && _header.Has{1}) || (!IsBuilt && _{0} != null);
            }}
        }}

        /// <summary>
        /// {3}
        /// </summary>
        public void Clear{1}()
        {{
            Debug.Assert(!IsBuilt, ""Can't modify an already built object!"");
            _{0} = null;
        }}
"
                    , field.name, field.name.Capitalize(), fieldType, field.id);
                return;
            }

            Writer.WriteLine(
                @"        /// <summary>
        /// {4}
        /// </summary>
        public {2} {1}
        {{
            get
            {{
                if (_{0} == null)
                {{
                    if (IsBuilt)
                    {{
                        _{0} = {2}.ParseFrom(ContentStream, _header.{1});
                    }}
                    else
                    {{
                        _{0} = new {2}();
                    }}

                    _{0}.FieldId = {3};
                    _{0}.Parent = this;
                }}
                return _{0};
            }}
        }}
"
                , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
        }
Exemplo n.º 34
0
 protected XmlNode add_field(string table, string fld, fieldType type)
 {
     return(_doc.add_xml("/root/tables/table[@name-upper='" + table.ToUpper() + "']/cols"
                         , "<col name='" + fld + "' nameupper='" + fld.ToUpper() + "' type='" + schema_field.type_to_original(db_type(), type) + "' />").node);
 }
Exemplo n.º 35
0
        protected override void GenerateClassNestedField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);
            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
@"    /**
    * {4}
    **/
    public {2} add{1}()
    {{
        assert !isBuilt() : ""Can't modify an already built object!"";

        {2} item = new {2}();
        item.setFieldId({3});
        item.setIndex(_{0}List.size());
        item.setParent(this);
        _{0}List.add(item);
        return item;
    }}

    /**
    * {4}
    **/
    public List<{2}> get{1}List()
    {{
        List<{2}> l = new ArrayList<{2}>();
        int n = get{1}Count();
        for(int i = 0; i < n; i++)
            l.add(get{1}(i));
        return l;
    }}

    /**
    * {4}
    **/
    public {2} get{1}(int index)
    {{
        if (index >= get{1}Count()) return null;

        {2} l{1} = _{0}List.get(index);
        if (l{1} == null)
        {{
            l{1} = {2}.parseFrom(getContentStream(), _header.get{1}(index));
            if (l{1}==null) 
                return null;
            l{1}.setFieldId({3});
            l{1}.setIndex(index);
            l{1}.setParent(this);
            _{0}List.set(index, l{1});
        }}
        return l{1};
    }}

    /**
    * {4}
    **/
    public int get{1}Count()
    {{
        return !isBuilt()? _{0}List.size() : _header.get{1}Count();
    }}
"
                                , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
@"        /**
        * {4}
        **/
        public {2} add{1}()
        {{
            if (_{0} == null)
            {{
                if (isBuilt() && has{1}())
                {{
                    get{1}(); // decode from body
                }}
                else
                {{
                    assert !isBuilt() : ""Can't modify an already built object!"";
                    _{0} = new {2}();
                    _{0}.setFieldId({3});
                    _{0}.setParent(this);
                }}
            }}
            return _{0};
        }}

        /**
        * {4}
        **/
        public {2} get{1}()
        {{
            if (isBuilt() && has{1}() && _{0} == null)
            {{
                _{0} = {2}.parseFrom(getContentStream(), _header.get{1}());
                if (_{0}==null)
                    return null;
                _{0}.setFieldId({3});
                _{0}.setParent(this);
            }}
            return _{0};
        }}

        /**
        * {4}
        **/
        public boolean has{1}()
        {{
            return (isBuilt() && _header.has{1}()) || (!isBuilt() && _{0} != null);
        }}

        /**
        * {4}
        **/
        public void clear{1}()
        {{
            assert !isBuilt() : ""Can't modify an already built object!"";
            _{0} = null;
        }}
"
                    , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
                return;
            }

            Writer.WriteLine(
@"        /**
        * {4}
        **/
        public {2} get{1}()
        {{
            if (_{0} == null)
            {{
                if (isBuilt())
                {{
                    _{0} = {2}.parseFrom(getContentStream(), _header.get{1}());
                    if (_{0}==null)
                        return null;
                }}
                else
                {{
                    _{0} = new {2}();
                }}
                _{0}.setFieldId({3});
                _{0}.setParent(this);
            }}
            return _{0};
        }}
"
                , field.name, field.name.Capitalize(), fieldType, field.id, field.description.Safe());
        }
    // Fills out hash table for items
    private void fillItemList()
    {
        this.itemList = new Hashtable();
        jankFile        itemTxt = new jankFile(Resources.Load <TextAsset>(@"ItemList"));
        List <string>   sheetP  = new List <string>();
        List <Sprite[]> sheets  = new List <Sprite[]>();

        // Determine number of spritesheets
        string s = itemTxt.ReadLine();

        string[] split = s.Split(' ');
        int      paths = 0;

        int.TryParse(split[split.Length - 1], out paths);
        // Read paths for spritesheets
        for (int i = 0; i < paths; i++)
        {
            string   sheetPath = itemTxt.ReadLine();
            Sprite[] sheet     = Resources.LoadAll <Sprite>(@sheetPath);
            sheets.Add(sheet);
            sheetP.Add(sheetPath);
        }
        itemTxt.ReadLine();

        // Count the number of items to read
        s     = itemTxt.ReadLine();
        split = s.Split(' ');
        int itemAmt = 0;

        int.TryParse(split[split.Length - 1], out itemAmt);

        // Read in each item and place in hash
        itemTxt.ReadLine();
        for (int i = 0; i < itemAmt; i++)
        {
            string   name = "", path = "", des = "";
            Sprite   icon;
            itemType main, sub;

            // Name
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            for (int j = 1; j < split.Length; j++)
            {
                name += split[j];
                if (j != split.Length - 1)
                {
                    name += " ";
                }
            }
            // Description
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            for (int j = 1; j < split.Length; j++)
            {
                des += split[j];
                if (j != split.Length - 1)
                {
                    des += " ";
                }
            }

            // Path
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            int pathNum = 0;
            int.TryParse(split[split.Length - 1], out pathNum);
            path = sheetP[pathNum];
            icon = getSprite(sheets[pathNum], name);

            // Price
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            int price = 0;
            int.TryParse(split[split.Length - 1], out price);

            // Types
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            main  = (itemType)System.Enum.Parse(typeof(itemType), split[split.Length - 1]);
            s     = itemTxt.ReadLine();
            split = s.Split(' ');
            sub   = (itemType)System.Enum.Parse(typeof(itemType), split[split.Length - 1]);

            // Make item so far
            Item entry = new Item(main, sub, icon, path, name, des, i, price, 1);

            // Read in main type first
            switch (main)
            {
            case itemType.ARMOR:
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                armorType a = (armorType)System.Enum.Parse(typeof(armorType), split[split.Length - 1]);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                int[] stats = new int[7];
                for (int k = 0; k < stats.Length; k++)
                {
                    int.TryParse(split[k + 1], out stats[k]);
                }
                entry.setArmorType(a);
                entry.setStats(stats);
                break;

            case itemType.WEAPON:
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                weaponType w = (weaponType)System.Enum.Parse(typeof(weaponType), split[split.Length - 1]);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                stats = new int[7];
                for (int k = 0; k < stats.Length; k++)
                {
                    int.TryParse(split[k + 1], out stats[k]);
                }
                entry.setWeaponType(w);
                entry.setStats(stats);
                entry.setSubType(itemType.ARMOR);
                entry.setArmorType(armorType.WEAPON);
                break;

            case itemType.FIELD:
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                fieldType f = (fieldType)System.Enum.Parse(typeof(fieldType), split[split.Length - 1]);
                entry.setFieldType(f);
                break;

            case itemType.BATTLE:
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                battleType b = (battleType)System.Enum.Parse(typeof(battleType), split[split.Length - 1]);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                status statusMod = (status)System.Enum.Parse(typeof(status), split[split.Length - 1]);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                int range = 0;
                int.TryParse(split[split.Length - 1], out range);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                stat st = (stat)System.Enum.Parse(typeof(stat), split[split.Length - 1]);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                int scalar = 0;
                int.TryParse(split[split.Length - 1], out scalar);
                s     = itemTxt.ReadLine();
                split = s.Split(' ');
                bool tAlly = true;
                bool.TryParse(split[split.Length - 1], out tAlly);
                entry.setBattleType(b);
                entry.setStatus(statusMod);
                entry.setModifiers(range, st, scalar, tAlly);
                break;

            default:     // Nothing happens if it's a key item
                break;
            }
            this.itemList.Add(i, entry);
            itemTxt.ReadLine();
        }
    }
Exemplo n.º 37
0
        protected override void GenerateClassSimpleField(messageType message, fieldType field)
        {
            var fieldTypeForList = FieldType(field);
            var fieldType = fieldTypeForList;
            if (field.type == typeType.@string)
                fieldType = "const " + fieldType + "&";
            // In C++, a repeated enum is stored as a RepeatedField<int>
            var underlyingType = field.type == typeType.@enum ?
                "int" :
                fieldTypeForList;
            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
@"        void add{1}({2} item);
        void remove{1}({2} item);
        std::vector<{3}> {0}List();
        {2} get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType, fieldTypeForList);

                CppWriter.WriteLine(
@"        void Abstract{4}::add{1}({3} item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            m_header.add_{2}(item);
        }}

        void Abstract{4}::remove{1}({3} item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto vals = m_header.mutable_{2}();
            auto newEnd = std::remove_if(vals->begin(), vals->end(), [&item]({6} check) {{ return check != item; }});
            vals->Truncate(newEnd - vals->begin());
        }}

        std::vector<{5}> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(get{1}(i));
            }}
            return list;
        }}

        {3} Abstract{4}::get{1}(int index)
        {{
            return m_header.{2}(index);
        }}

        int Abstract{4}::{0}Count() const
        {{
            return m_header.{2}_size();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, fieldTypeForList, underlyingType);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
@"        bool has{0}() const {{ return m_header.has_{1}(); }}        
        void clear{0}() {{ m_header.clear_{1}(); }}
"
                    , field.name.Capitalize(), field.name.ToLowerInvariant());
            }

            IncludeWriter.WriteLine(
@"        {3} {0}() const {{ return m_header.{2}(); }}
        void set{1}({3} value) {{ m_header.set_{2}(value); }}
"
                , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType);
        }
Exemplo n.º 38
0
 private static string BoxedType(fieldType node, string suffix)
 {
     switch (node.type)
     {
         case typeType.nestedMessage:
             return node.messageType + suffix;
         case typeType.referenceMessage:
             return node.messageType + suffix;
         case typeType.@enum:
             return node.enumType;
         case typeType.uint32:
             return "Integer";
         case typeType.int32:
             return "Integer";
         case typeType.@string:
             return "String";
         case typeType.@bool:
             return "Boolean";
         default:
             return node.type.ToString();
     }
 }
Exemplo n.º 39
0
        protected override void GenerateClassReferenceField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);

            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
@"        void add{1}({2}& item);
        void remove{1}({2}& item);
        std::vector<{2}*> {0}List();
        {2}& get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
@"        void Abstract{4}::add{1}({3}& item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            m_header.add_{2}()->CopyFrom(item.getLocalMessageDescriptor());
        }}

        void Abstract{4}::remove{1}({3}& item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto vals = m_header.mutable_{2}();
            auto newEnd = std::remove_if(vals->begin(), vals->end(), [this, &item](const LocalMessageDescriptor& check) 
            {{ 
                return getRoot()->decode(check) == &item; 
            }});
            vals->DeleteSubrange(newEnd - vals->begin(), vals->end() - newEnd);
        }}

        std::vector<{3}*> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}*>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(&get{1}(i));
            }}
            return list;
        }}

        {3}& Abstract{4}::get{1}(int index)
        {{
            return *dynamic_cast<{3}*>(getRoot()->decode(m_header.{2}(index)));
        }}

        int Abstract{4}::{0}Count() const
        {{
            return m_header.{2}_size();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
@"        bool has{0}() const {{ return m_header.has_{1}(); }}
        void clear{0}() {{ m_header.clear_{1}(); }}
"
                    , field.name.Capitalize(), field.name.ToLowerInvariant());
            }

            IncludeWriter.WriteLine(
@"        void set{1}({2}& value);
        {2}* {0}();
"
                , field.name, field.name.Capitalize(), fieldType);

            CppWriter.WriteLine(
@"        void Abstract{4}::set{1}({3}& value)
        {{
            m_header.clear_{2}();
            m_header.mutable_{2}()->CopyFrom(value.getLocalMessageDescriptor());
            // TODO see if that works // m_header.set_allocated_{2}(value.getLocalMessageDescriptor());
        }}

        {3}* Abstract{4}::{0}()
        {{
            return dynamic_cast<{3}*>(getRoot()->decode(m_header.{2}()));
        }}
"
                , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name);
        }
Exemplo n.º 40
0
 public virtual string val_toqry(string value, fieldType coltype, dbType type, string nullstr = null, bool add_operator = false, bool tostring = false)
 {
     throw new Exception("il provider " + _dbType.ToString() + " non supporta la funzionalità valueToQuery");
 }
Exemplo n.º 41
0
        protected override void GenerateClassNestedField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);
            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
@"        {2}& add{1}();
        std::vector<{2}*> {0}List();
        {2}& get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
@"        {3}& Abstract{4}::add{1}()
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto index = m_{0}List.size();
            auto {0} = std::make_unique<{3}>();
            {0}->setFieldId({5});
            {0}->setIndex(index);
            {0}->setParent(this);
            m_{0}List.set(index, std::move({0}));
            return *m_{0}List.get(index);
        }}

        std::vector<{3}*> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}*>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(&get{1}(i));
            }}
            return list;
        }}

        {3}& Abstract{4}::get{1}(int index)
        {{
            if (!m_{0}List.get(index))
            {{
                auto {0} = {3}::ParseFrom(contentStream(), m_header.{2}(index));
                {0}->setFieldId({5});
                {0}->setIndex(index);
                {0}->setParent(this);
                m_{0}List.set(index, std::move({0}));
            }}
            return *m_{0}List.get(index);
        }}

        int Abstract{4}::{0}Count() const
        {{
            return !isBuilt() ? m_{0}List.size() : m_header.{2}_size();
        }}"
                , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, field.id);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
@"        {2}& add{1}(); // adds the optional {1}
        {2}* {0}();
        bool has{1}() const;
        void clear{1}();
        
"
                    , field.name, field.name.Capitalize(), fieldType);

                CppWriter.WriteLine(
@"        {3}& Abstract{4}::add{1}()
        {{
            if (m_{0} == nullptr)
            {{
                if (isBuilt() && has{1}())
                {{
                    {0}(); // decode from body
                }}
                else
                {{
                    assert((""Can't modify an already built object!"", !isBuilt()));
                    m_{0} = std::make_unique<{6}::{3}>();
                    m_{0}->setFieldId({5});
                    m_{0}->setParent(this);
                }}
            }}
            return *m_{0};
        }}

        {3}* Abstract{4}::{0}()
        {{
            if (isBuilt() && has{1}() && m_{0} == nullptr)
            {{
                m_{0} = {3}::ParseFrom(contentStream(), m_header.{2}());
                m_{0}->setFieldId({5});
                m_{0}->setParent(this);
            }}
            return m_{0}.get();
        }}

        bool Abstract{4}::has{1}() const
        {{
            return (isBuilt() && m_header.has_{2}()) || (!isBuilt() && m_{0} != nullptr);
        }}

        void Abstract{4}::clear{1}()
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            m_{0}.reset();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, field.id, Namespace);
                return;
            }

            IncludeWriter.WriteLine(@"        {1}& {0}();", field.name, fieldType);
            CppWriter.WriteLine(
@"        {2}& Abstract{3}::{0}()
        {{
            if (m_{0} == nullptr)
            {{
                if (isBuilt())
                {{
                    m_{0} = {2}::ParseFrom(contentStream(), m_header.{1}());
                }}
                else
                {{
                    m_{0} = std::make_unique<{2}>();
                }}
                m_{0}->setFieldId({4});
                m_{0}->setParent(this);
            }}
            return *m_{0};
        }}
"
                , field.name, field.name.ToLowerInvariant(), fieldType, message.name, field.id);
        }
Exemplo n.º 42
0
 static public catField cat_field(fieldType tp)
 {
     return(tp == fieldType.VARCHAR || tp == fieldType.CHAR || tp == fieldType.XML || tp == fieldType.TEXT ? catField.TEXT :
            tp == fieldType.DATETIME ? catField.DATE : catField.NUMERIC);
 }
Exemplo n.º 43
0
        protected override void GenerateClassReferenceField(messageType message, fieldType field)
        {
            var fieldType = FieldType(field);
            var boxedType = BoxedType(field, "");

            if (field.modifier == modifierType.repeated)
            {
                Writer.WriteLine(
@"    /**
    * {3}
    **/
    public void add{0}({1} item)
    {{
        assert !isBuilt() : ""Can't modify an already built object!"";
        getBuilder().add{0}(item.getLocalMessageDescriptor());
    }}

    /**
    * {3}
    **/
    public void remove{0}({1} item)
    {{
        assert !isBuilt() : ""Can't modify an already built object!"";
        getBuilder().get{0}BuilderList().remove(item.getLocalMessageDescriptor());
    }}

    /**
    * {3}
    **/
    public {1} get{0}(int index)
    {{
        return ({1})getRoot().decode(_header.get{0}(index));
    }}

    /**
    * {3}
    **/
    public List<{2}> get{0}List()
    {{
        List<{2}> l = new ArrayList<{2}>();
        int n = get{0}Count();
        for(int i = 0; i < n; i++)
            l.add(get{0}(i));
        return l;
    }}

    /**
    * {3}
    **/
    public int get{0}Count()
    {{
        return _header.get{0}Count();
    }}
"
                            , field.name.Capitalize(), fieldType, boxedType, field.description.Safe());
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                Writer.WriteLine(
@"    /**
    * {1}
    **/
    public boolean has{0}()
    {{
        return _header.has{0}();
    }}      

    /**
    * {1}
    **/
    public void clear{0}()
    {{
        assert !isBuilt() : ""Can't modify an already built object!"";
        getBuilder().clear{0}();
    }}
"
                        , field.name.Capitalize(),field.description.Safe());
            }

            Writer.WriteLine(
@"    /**
    * {2}
    **/
    public {1} get{0}()
    {{
        return ({1})getRoot().decode(_header.get{0}());
    }}

    /**
    * {2}
    **/
    public void set{0}({1} value)
    {{
        assert !isBuilt() : ""Can't modify an already built object!"";
        getBuilder().set{0}(value.getLocalMessageDescriptor());
    }}
"
                    , field.name.Capitalize(), fieldType, field.description.Safe());
        }
Exemplo n.º 44
0
        public static string typeToOriginal(dbType typeDb, fieldType type)
        {
            if (typeDb == dbType.access)
            {
                if (type == fieldType.BINARY)
                {
                    return("binary");
                }
                else if (type == fieldType.BOOL)
                {
                    return("boolean");
                }
                else if (type == fieldType.MONEY)
                {
                    return("currency");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("date");
                }
                else if (type == fieldType.GUID)
                {
                    return("guid");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("double");
                }
                else if (type == fieldType.SINGLE)
                {
                    return("single");
                }
                else if (type == fieldType.SMALLINT)
                {
                    return("smallint");
                }
                else if (type == fieldType.INTEGER)
                {
                    return("integer");
                }
                else if (type == fieldType.DECIMAL)
                {
                    return("decimal");
                }
                else if (type == fieldType.VARCHAR)
                {
                    return("varchar");
                }
                else if (type == fieldType.CHAR)
                {
                    return("char");
                }
            }
            else if (typeDb == dbType.sqlserver)
            {
                if (type == fieldType.BINARY)
                {
                    return("varbinary");
                }
                else if (type == fieldType.BOOL)
                {
                    return("bit");
                }
                else if (type == fieldType.MONEY)
                {
                    return("money");
                }
                else if (type == fieldType.DATETIME)
                {
                    return("datetime");
                }
                else if (type == fieldType.DATETIME2)
                {
                    return("datetime2");
                }
                else if (type == fieldType.DOUBLE)
                {
                    return("float");
                }
                else if (type == fieldType.SMALLINT)
                {
                    return("smallint");
                }
                else if (type == fieldType.INTEGER)
                {
                    return("int");
                }
                else if (type == fieldType.LONG)
                {
                    return("bigint");
                }
                else if (type == fieldType.DECIMAL)
                {
                    return("decimal");
                }
                else if (type == fieldType.VARCHAR)
                {
                    return("varchar");
                }
                else if (type == fieldType.CHAR)
                {
                    return("char");
                }
                else if (type == fieldType.TEXT)
                {
                    return("text");
                }
                else if (type == fieldType.XML)
                {
                    return("xml");
                }
            }

            throw new Exception("type field '" + type.ToString() + "' not supported for '" + typeDb.ToString() + "'");
        }
Exemplo n.º 45
0
        protected override void GenerateClassSimpleField(messageType message, fieldType field)
        {
            var fieldTypeForList = FieldType(field);
            var fieldType        = fieldTypeForList;

            if (field.type == typeType.@string)
            {
                fieldType = "const " + fieldType + "&";
            }
            // In C++, a repeated enum is stored as a RepeatedField<int>
            var underlyingType = field.type == typeType.@enum ?
                                 "int" :
                                 fieldTypeForList;

            if (field.modifier == modifierType.repeated)
            {
                IncludeWriter.WriteLine(
                    @"        void add{1}({2} item);
        void remove{1}({2} item);
        std::vector<{3}> {0}List();
        {2} get{1}(int index);
        int {0}Count() const;
"
                    , field.name, field.name.Capitalize(), fieldType, fieldTypeForList);

                CppWriter.WriteLine(
                    @"        void Abstract{4}::add{1}({3} item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            m_header.add_{2}(item);
        }}

        void Abstract{4}::remove{1}({3} item)
        {{
            assert((""Can't modify an already built object!"", !isBuilt()));
            auto vals = m_header.mutable_{2}();
            auto newEnd = std::remove_if(vals->begin(), vals->end(), [&item]({6} check) {{ return check != item; }});
            vals->Truncate(newEnd - vals->begin());
        }}

        std::vector<{5}> Abstract{4}::{0}List()
        {{
            auto count = {0}Count();
            auto list = std::vector<{3}>();
            list.reserve(count);
            for (auto i = 0; i < count; ++i)
            {{
                list.push_back(get{1}(i));
            }}
            return list;
        }}

        {3} Abstract{4}::get{1}(int index)
        {{
            return m_header.{2}(index);
        }}

        int Abstract{4}::{0}Count() const
        {{
            return m_header.{2}_size();
        }}
"
                    , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType, message.name, fieldTypeForList, underlyingType);
                return;
            }

            if (field.modifier == modifierType.optional)
            {
                IncludeWriter.WriteLine(
                    @"        bool has{0}() const {{ return m_header.has_{1}(); }}        
        void clear{0}() {{ m_header.clear_{1}(); }}
"
                    , field.name.Capitalize(), field.name.ToLowerInvariant());
            }

            IncludeWriter.WriteLine(
                @"        {3} {0}() const {{ return m_header.{2}(); }}
        void set{1}({3} value) {{ m_header.set_{2}(value); }}
"
                , field.name, field.name.Capitalize(), field.name.ToLowerInvariant(), fieldType);
        }
Exemplo n.º 46
0
 private static string FieldType(fieldType node)
 {
     switch (node.type)
     {
         case typeType.nestedMessage:
             return node.messageType;
         case typeType.referenceMessage:
             return node.messageType;
         case typeType.@enum:
             return node.enumType;
         case typeType.uint64:
             return "unsigned long";
         case typeType.uint32:
             return "unsigned int";
         case typeType.int64:
             return "long";
         case typeType.int32:
             return "int";
         case typeType.@string:
             return "std::string";
         default:
             return node.type.ToString();
     }
 }
Exemplo n.º 47
0
 protected abstract void GenerateClassSimpleField(messageType message, fieldType field);