Beispiel #1
0
                /// <summary>
                ///     This method will re-initialize the current instance with the specified parameters by mutation.
                /// </summary>
                public Digit _mutate(int measure, int size, TChild a, TChild b = null, TChild c = null, TChild d = null)
                {
#if ASSERTS
                    var all     = new[] { a, b, c, d };
                    var notNull = all.Where(x => x != null).ToArray();
                    if (notNull.Length != 2)
                    {
                        //a hack allows one of the inner elements to be fragments...
                        notNull.All(x => !x.IsFragment).AssertTrue();
                    }
                    else
                    {
                        notNull[1].IsFragment.AssertFalse();                         //this only applies to the 1st element!
                    }

                    notNull.Count().AssertEqual(size);
                    notNull.Sum(x => x.Measure).AssertEqual(measure);
#endif
                    First  = a;
                    Second = b;
                    Third  = c;
                    Fourth = d;

                    Measure    = measure;
                    Size       = size;
                    ChildCount = size;
                    return(this);
                }
Beispiel #2
0
                Digit Update_MUTATES(int index, Leaf <TValue> leaf)
                {
                    var whereIsThisIndex = WhereIsThisIndex(index);

                    switch (whereIsThisIndex)
                    {
                    case IN_START:
                    case IN_MIDDLE_OF_1:
                        First = First.Update(index, leaf, Lineage);
                        return(this);

                    case IN_START_OF_2:
                    case IN_MIDDLE_OF_2:
                        Second = Second.Update(index - First.Measure, leaf, Lineage);
                        return(this);

                    case IN_START_OF_3:
                    case IN_MIDDLE_OF_3:
                        Third = Third.Update(index - First.Measure - Second.Measure, leaf, Lineage);
                        return(this);

                    case IN_START_OF_4:
                    case IN_MIDDLE_OF_4:
                        Fourth = Fourth.Update(index - First.Measure - Second.Measure - Third.Measure, leaf, Lineage);
                        return(this);

                    case IN_END:
                    case OUTSIDE:
                        throw ImplErrors.Arg_out_of_range("index", index);

                    default:
                        throw ImplErrors.Invalid_execution_path("Checked all index locations already.");
                    }
                }
        public void RegisterType <T, TChild>()
            where T : class
            where TChild : T, new()
        {
            var instance = new TChild();
            var type     = typeof(T);

            _iocDict[type] = instance;
        }
Beispiel #4
0
                public Digit(TChild one, Lineage lineage)
                    : base(one.Measure, lineage, 1, ExampleChild.Nesting + 1)
                {
#if ASSERTS
                    one.AssertNotNull();
                    one.IsFragment.AssertFalse();
#endif
                    First = one;
                    Size  = 1;
                }
        public TChild AddChild <TChild>() where TChild : QueryExpression, new()
        {
            TChild child = new TChild()
            {
                Parent = this
            };

            _children.Add(child);
            return(child);
        }
Beispiel #6
0
                public Digit(TChild one, TChild two, Lineage lineage)
                    : base(one.Measure + two.Measure, lineage, 2, ExampleChild.Nesting + 1)
                {
#if ASSERTS
                    one.AssertNotNull();
                    two.AssertNotNull();
                    new[] { two.IsFragment }.Any(x => x).AssertFalse();                  //one can be a fragment as a hack used as part of RemoveAt
#endif
                    First  = one;
                    Second = two;
                    Size   = 2;
                }
Beispiel #7
0
 public ChildInfo(TChild child, StackedContentChildInfo lengthInfo)
 {
     this.Child      = child;
     this.LengthInfo = lengthInfo?.Clone() ?? new StackedContentChildInfo();
     if (this.LengthInfo.Horizontal.GridLength == null)
     {
         this.LengthInfo.Horizontal.GridLength = new GridLength(1, GridUnitType.Star);
     }
     if (this.LengthInfo.Vertical.GridLength == null)
     {
         this.LengthInfo.Vertical.GridLength = new GridLength(1, GridUnitType.Star);
     }
 }
Beispiel #8
0
                public Digit(TChild one, TChild two, TChild three, TChild four, Lineage lineage)
                    : base(one.Measure + two.Measure + three.Measure + four.Measure, lineage, 4, ExampleChild.Nesting + 1)
                {
                    AssertEx.AssertAreNotNull(one, two, three, four);
                    AssertEx.AssertFalse(new[] { one.IsFragment, two.IsFragment, three.IsFragment, four.IsFragment }.Any(x => x));


                    First  = one;
                    Second = two;
                    Third  = three;
                    Fourth = four;
                    Size   = 4;
                }
Beispiel #9
0
                public Digit(TChild one, TChild two, TChild three, Lineage lineage)
                    : base(one.Measure + two.Measure + three.Measure, lineage, 3, ExampleChild.Nesting + 1)
                {
#if ASSERTS
                    AssertEx.AssertAreNotNull(one, two, three);
                    new[] { one.IsFragment, two.IsFragment, three.IsFragment }.Any(x => x).AssertFalse();
#endif

                    First  = one;
                    Second = two;
                    Third  = three;
                    Size   = 3;
                }
Beispiel #10
0
                public Digit AddLast(TChild item, Lineage lineage)
                {
                    switch (Size)
                    {
                    case 1:
                        return(MutateOrCreate(First, item, lineage));

                    case 2:
                        return(MutateOrCreate(First, Second, item, lineage));

                    case 3:
                        return(MutateOrCreate(First, Second, Third, item, lineage));

                    case 4:
                        throw ImplErrors.Bad_digit_size(Size);
                    }
                    throw ImplErrors.Bad_digit_size(Size);
                }
Beispiel #11
0
                public void Split(int index, out Digit left, out TChild center, out Digit right, Lineage lineage)
                {
                    switch (WhereIsThisIndex(index))
                    {
                    case IN_START:
                    case IN_MIDDLE_OF_1:
                        left   = null;
                        center = First;
                        right  = CreateCheckNull(lineage, Second, Third, Fourth);
                        break;

                    case IN_START_OF_2:
                    case IN_MIDDLE_OF_2:
                        left   = new Digit(First, lineage);
                        center = Second;
                        right  = CreateCheckNull(lineage, Third, Fourth);
                        break;

                    case IN_START_OF_3:
                    case IN_MIDDLE_OF_3:
                        left   = new Digit(First, Second, lineage);
                        center = Third;
                        right  = CreateCheckNull(lineage, Fourth);
                        break;

                    case IN_MIDDLE_OF_4:
                    case IN_START_OF_4:
                        left   = new Digit(First, Second, Third, lineage);
                        center = Fourth;
                        right  = null;
                        break;

                    case IN_END:
                    case OUTSIDE:
                        throw ImplErrors.Arg_out_of_range("index", index);

                    default:
                        throw ImplErrors.Invalid_execution_path("Checked all index locations.");
                    }
                }
Beispiel #12
0
 public void Select (TChild child)
 {
   m_Child = child;
 }
Beispiel #13
0
 public TFactorySiblingMessageInternal (TInternalMessageAction messageAction, TChild child, TTypeInfo typeInfo)
   : base (TResource.TModule.Factory, messageAction, TNode.Create (typeInfo), typeInfo)
 {
   Node.SelectRelationSibling (child);
 }
Beispiel #14
0
 public TCollectionMessageInternal (TInternalMessageAction messageAction, TChild child, TTypeInfo typeInfo)
   : base (TResource.TModule.Collection, messageAction, TNode.Create (typeInfo), typeInfo)
 {
   Node.SelectRelationChild (child);
 }
Beispiel #15
0
 private Digit MutateOrCreate(TChild a, Lineage lineage)
 {
     return(Lineage.AllowMutation(lineage) ? _mutate(a.Measure, 1, a) : new Digit(a, lineage));
 }
Beispiel #16
0
 private Digit MutateOrCreate(TChild a, TChild b, Lineage lineage)
 {
     return(Lineage.AllowMutation(lineage) ? _mutate(a.Measure + b.Measure, 2, a, b) : new Digit(a, b, lineage));
 }
Beispiel #17
0
 private Digit MutateOrCreate(TChild a, TChild b, TChild c, TChild d, Lineage lineage)
 {
     return(Lineage.AllowMutation(lineage)
                                 ? _mutate(a.Measure + b.Measure + c.Measure + d.Measure, 4, a, b, c, d) : new Digit(a, b, c, d, lineage));
 }
 public void Add(TChild item)
 {
     barList.Add(item);
 }
Beispiel #19
0
                //This method is used when we don't know the exact size of the digit we want to create.
                public Digit CreateCheckNull(Lineage lineage, TChild item1 = null, TChild item2 = null, TChild item3 = null,
                                             TChild item4 = null)
                {
                    var itemsPresent = item1 != null ? 1 : 0;

                    itemsPresent |= item2 != null ? 2 : 0;
                    itemsPresent |= item3 != null ? 4 : 0;
                    itemsPresent |= item4 != null ? 8 : 0;
                    Digit res;

                    switch (itemsPresent)
                    {
                    case 0 << 0 | 0 << 1 | 0 << 2 | 0 << 3:
                            res = null;
                        break;

                    case 1 << 0 | 0 << 1 | 0 << 2 | 0 << 3:
                            res = MutateOrCreate(item1, lineage);
                        break;

                    case 0 << 0 | 1 << 1 | 0 << 2 | 0 << 3:
                            res = MutateOrCreate(item2, lineage);
                        break;

                    case 0 << 0 | 0 << 1 | 1 << 2 | 0 << 3:
                            res = MutateOrCreate(item3, lineage);
                        break;

                    case 0 << 0 | 0 << 1 | 0 << 2 | 1 << 3:
                            res = MutateOrCreate(item4, lineage);
                        break;

                    case 1 << 0 | 1 << 1 | 0 << 2 | 0 << 3:
                            res = MutateOrCreate(item1, item2, lineage);
                        break;

                    case 1 << 0 | 1 << 1 | 1 << 2 | 0 << 3:
                            res = MutateOrCreate(item1, item2, item3, lineage);
                        break;

                    case 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3:
                            res = MutateOrCreate(item1, item2, item3, item4, lineage);
                        break;

                    case 0 << 0 | 1 << 1 | 1 << 2 | 0 << 3:
                            res = MutateOrCreate(item2, item3, lineage);
                        break;

                    case 0 << 0 | 1 << 1 | 1 << 2 | 1 << 3:
                            res = MutateOrCreate(item2, item3, item4, lineage);
                        break;

                    case 0 << 0 | 0 << 1 | 1 << 2 | 1 << 3:
                            res = MutateOrCreate(item3, item4, lineage);
                        break;

                    case 1 << 0 | 0 << 1 | 1 << 2 | 0 << 3:
                            res = MutateOrCreate(item1, item3, lineage);
                        break;

                    case 1 << 0 | 0 << 1 | 1 << 2 | 1 << 3:
                            res = MutateOrCreate(item1, item3, item4, lineage);
                        break;

                    case 0 << 0 | 1 << 1 | 0 << 2 | 1 << 3:
                            res = MutateOrCreate(item2, item4, lineage);
                        break;

                    case 1 << 0 | 0 << 1 | 0 << 2 | 1 << 3:
                            res = MutateOrCreate(item1, item4, lineage);
                        break;

                    case 1 << 0 | 1 << 1 | 0 << 2 | 1 << 3:
                            res = MutateOrCreate(item1, item2, item4, lineage);
                        break;

                    default:
                        throw ImplErrors.Invalid_execution_path("Checked all digit permutations already.");
                    }

                    return(res);
                }