public int CompactCollection(CollectionVariable collection, string name, bool sequential) { int addcount=0; if (collection!=null && collection.Count>0) { List<_IndexVariablePair> pairs=new List<_IndexVariablePair>(); bool matched; //, namematched, varmatched; int mc=0; int mmax=(_iden!=null) ? _iden.Length : 0; mmax=(((_layout!=null) ? _layout.Length : 0)>mmax) ? _layout.Length : mmax; //Console.WriteLine("(Template.CompactCollection) mmax:{0}", mmax); ValueVariable val=null; bool repeatmatch=false; int i=0; Variable[] array=collection.Children.ToArray(); while (i<array.Length) { //Console.WriteLine("(Template.CompactCollection) [{0}] repeatmatch:{0}", mc, repeatmatch); if (repeatmatch) { repeatmatch=false; } else { val=(array[i] is ValueVariable) ? (ValueVariable)array[i] : null; i++; } if (val!=null) { //namematched=__matchname(mc, _iden, value.Name, _casesens, _infinitism); //varmatched=__matchvariable(mc, _layout, _infinitism, value); //matched=namematched && varmatched; matched=__matchname(mc, _iden, val.Name, _casesens, _infinitism) && __matchvariable(mc, _layout, _infinitism, val); //Console.WriteLine("(Template.CompactCollection) [{0}] type:{1}, name:{2}, namematched:{3}, varmatched:{4}, (mc<mmax):{5}, (_layout && mc<_layout.Length):{6}", // mc, value.TypeName, "" /*value.Name*/, namematched, varmatched, (mc<mmax), (_layout && mc<_layout.Length)); if (matched) { //Console.WriteLine("(Template.CompactCollection) match at mc:{0}", mc); pairs.Add(new _IndexVariablePair(i, val)); mc++; } else if (mc>0 && mc!=mmax) { //Console.WriteLine("(Template.CompactCollection) unmatched before total; mc:{0}", mc); if (mmax==0 || mc>mmax) { //Console.WriteLine("(Template.CompactCollection) creating from left over"); __add(collection, pairs, name, ref addcount); } __reset(out mc, out repeatmatch, true, pairs); } if (mmax>0 && ((mc==mmax && (_infinitism==VariableType.NONE)) || (mc>0 && !(i!=array.Length)))) { //Console.WriteLine("(Template.CompactCollection) unmatched total mc:{0}, creating identifier", mc); __add(collection, pairs, name, ref addcount); __reset(out mc, out repeatmatch, matched, pairs); } } else if (mc>0 && sequential) { //Console.WriteLine("(Template.CompactCollection) non-value inbetween match series mc:{0}", mc); if (mmax==0 || mc>mmax) { //Console.WriteLine("(Template.CompactCollection) creating from left over"); __add(collection, pairs, name, ref addcount); } __reset(out mc, out repeatmatch, false, pairs); } } } return addcount; }
public IntVariable(int val, CollectionVariable parent) : this(val, String.Empty, parent) { }
public IntVariable(int val, string name, CollectionVariable parent) { _value=val; _name=name; _parent=parent; }
public Identifier(CollectionVariable parent) : this("", parent) { }
public Identifier(string name, CollectionVariable parent) { _name=name; _parent=parent; }
public FloatVariable(float val, CollectionVariable parent) : this(val, String.Empty, parent) { }
public Identifier GetMatchingIdentifier(CollectionVariable collection) { if (collection!=null) { foreach (Variable v in collection.Children) { Identifier identifier=v as Identifier; if (ValidateIdentifier(identifier)) return identifier; } } return null; }
public StringVariable(string val, string name, CollectionVariable parent) { _value=val; _name=name; _parent=parent; }
public BoolVariable(bool val, string name, CollectionVariable parent) { _value=val; _name=name; _parent=parent; }
void __add(CollectionVariable collection, List<_IndexVariablePair> pairs, string name, ref int addcount) { if (pairs.Count>0) { bool first=true; Identifier iden=new Identifier(name, collection); foreach (_IndexVariablePair pair in pairs) { collection.Children.RemoveAt(pair.i); if (first) { collection.Children.Insert(pair.i, iden); first=false; } iden.Add(pair.variable); // re-own to the new identifier } addcount++; } }
public int CompactCollection(CollectionVariable collection, string name) { return CompactCollection(collection, name, false); }
public int RenameValues(CollectionVariable collection, string name) { int count=0; if (collection!=null) { foreach (Variable v in collection.Children) { ValueVariable val = v as ValueVariable; if (ValidateValue(val)) { val.Name=name; count++; } } } return count; }
public int RenameIdentifiers(CollectionVariable collection, string name) { int count=0; if (collection!=null) { foreach (Variable v in collection.Children) { Identifier identifier=v as Identifier; if (ValidateIdentifier(identifier)) { identifier.Name=name; count++; } } } return count; }
public ValueVariable GetMatchingValue(CollectionVariable collection) { if (collection!=null) { foreach (Variable v in collection.Children) { ValueVariable val = v as ValueVariable; if (ValidateValue(val)) return val; } } return null; }
public Node(string name, CollectionVariable parent) { _name=name; _parent=parent; }
public BoolVariable(bool val, CollectionVariable parent) : this(val, String.Empty, parent) { }
public Node(CollectionVariable parent) : this(String.Empty, parent) { }
public FloatVariable(float val, string name, CollectionVariable parent) { _value=val; _name=name; _parent=parent; }
public StringVariable(string val, CollectionVariable parent) : this(val, String.Empty, parent) { }
void AddVariableAndReset(CollectionVariable collection, Variable variable, bool iden, bool val) { collection.Add(variable); Reset(iden, val); }