Example #1
0
        // Create a new relation type for a particular heading
        // Called once for the generic, then once for each specific
        static DataTypeTuple Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null)
        {
            //var basetype = DataTypes.Row as DataTypeTuple;
            var dt = new DataTypeTuple {
                Name    = name,
                Heading = heading,
                Flags   = flags,
            };

            return(dt);
        }
Example #2
0
        // --- create ------------------------------------------------------

        // from existing columns, with normalisation by default
        public static DataHeading Create(IEnumerable <DataColumn> columns, bool istuple = true)
        {
            Logger.Assert(columns != null && columns.All(c => c.DataType.IsVariable), "bad columns");
            var dh = new DataHeading()
            {
                _columns = columns.ToArray(),
                IsTuple  = istuple,
            };

            dh._coldict = Enumerable.Range(0, dh._columns.Length)
                          .ToDictionary(x => dh._columns[x].Name, x => x);
            return((istuple) ? DataTypeTuple.Get(dh).Heading : dh);
        }
Example #3
0
        // Get type from dictionary, or create and add
        public static DataTypeTuple Get(DataHeading heading)
        {
            if (_headings.ContainsKey(heading))
            {
                return(_headings[heading]);
            }
            var dt = DataTypeTuple.Create("tuple", heading, TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasHeading);

            dt.Ordinal         = _headings.Count + 1;
            dt.NativeType      = TypeMaker.CreateType(dt);
            _headings[heading] = dt;
            return(dt);
        }
Example #4
0
 // construct a type from a base name, optional heading and optional user type name
 public static DataType Derive(DataType basetype, DataHeading heading, string username)
 {
     if (basetype == DataTypes.Table)
     {
         return(DataTypeRelation.Get(heading));
     }
     if (basetype == DataTypes.Row)
     {
         return(DataTypeTuple.Get(heading));
     }
     if (basetype == DataTypes.User)
     {
         return(DataTypeUser.Get(username, heading.Columns));
     }
     return(basetype);
 }
Example #5
0
        // Get type from dictionary, or create and add
        // Every relation needs a row type, so make sure they use the same heading
        public static DataTypeRelation Get(DataHeading heading)
        {
            if (_headings.ContainsKey(heading))
            {
                return(_headings[heading]);
            }
            var tupletype = DataTypeTuple.Get(heading);
            var dt        = DataTypeRelation.Create("relation", tupletype.Heading, TypeFlags.Variable | TypeFlags.Generated | TypeFlags.HasHeading);

            dt.Ordinal         = _headings.Count + 1;
            dt.ChildTupleType  = tupletype;
            dt.NativeType      = TypeMaker.CreateType(dt);
            _headings[heading] = dt;
            var x = Activator.CreateInstance(dt.NativeType);

            return(dt);
        }
Example #6
0
        // Create a row that belongs to a table.
        // Can be called with a tuple or non-tuple heading. If the latter, reorder values to match tuple heading.
        public static DataRow Create(DataHeading heading, TypedValue[] values)
        {
            if (values.Length != heading.Degree)
            {
                throw new ArgumentOutOfRangeException("values", "wrong degree");
            }
            Logger.Assert(values.All(v => v != null), "null value");
            var newheading = (heading.IsTuple) ? heading : DataTypeTuple.Get(heading).Heading;
            var dr         = new DataRow()
            {
                DataType = DataTypeTuple.Get(heading),
                Heading  = newheading,
                _values  = (heading.IsTuple) ? values : newheading.Columns.Select(c => values[heading.FindIndex(c)]).ToArray(),
            };

            dr._hashcode = dr.CalcHashCode();
            dr.Heading.CheckValues(dr.Values);
            return(dr);
        }