private Collection <int> PossibleResultTupleIndices(Plan chosenplan, Type typeDesired) { // Now, figure out the result element that we'll pick from this plan. Collection <int> possibleResultIndices = new Collection <int>(); for (int j = 0; j < chosenplan.transformer.TupleTypes.Length; j++) { Type resultType = chosenplan.transformer.TupleTypes[j]; if (typeDesired.IsInterface) { if (resultType.IsInterface && typeDesired.Equals(resultType)) { possibleResultIndices.Add(j); } else { foreach (Type interfaceType in resultType.GetInterfaces()) { if (interfaceType.Equals(typeDesired)) { possibleResultIndices.Add(j); break; } } } } else { if (resultType.Equals(typeDesired) || ReflectionUtils.IsSubclassOrEqual(resultType, typeDesired)) { possibleResultIndices.Add(j); } } } Util.Assert(possibleResultIndices.Count > 0); Collection <int> activePossible = new Collection <int>(); foreach (int i in possibleResultIndices) { if (chosenplan.IsActiveTupleElement(i)) { activePossible.Add(i); } } //Util.Assert(activePossible.Count > 0); return(activePossible); }
private Collection<int> PossibleResultTupleIndices(Plan chosenplan, Type typeDesired) { // Now, figure out the result element that we'll pick from this plan. Collection<int> possibleResultIndices = new Collection<int>(); for (int j = 0; j < chosenplan.transformer.TupleTypes.Length; j++) { Type resultType = chosenplan.transformer.TupleTypes[j]; if (typeDesired.IsInterface) { if (resultType.IsInterface && typeDesired.Equals(resultType)) possibleResultIndices.Add(j); else { foreach (Type interfaceType in resultType.GetInterfaces()) if (interfaceType.Equals(typeDesired)) { possibleResultIndices.Add(j); break; } } } else { if (resultType.Equals(typeDesired) || ReflectionUtils.IsSubclassOrEqual(resultType, typeDesired)) possibleResultIndices.Add(j); } } Util.Assert(possibleResultIndices.Count > 0); Collection<int> activePossible = new Collection<int>(); foreach (int i in possibleResultIndices) if (chosenplan.IsActiveTupleElement(i)) activePossible.Add(i); //Util.Assert(activePossible.Count > 0); return activePossible; }
// resultTuple can be null. private bool AddplanInternal(Plan p, ResultTuple resultTuple) { totalAttemptedAdditions++; bool addSuccessful = false; if (planSet.ContainsKey(p)) { totalFailedAdditions++; return(false); } else { planSet[p] = true; NumPlans++; Dictionary <Type, bool> processedTypes = new Dictionary <Type, bool>(); for (int i = 0; i < p.transformer.TupleTypes.Length; i++) { if (!p.IsActiveTupleElement(i)) { continue; } Type t = p.transformer.TupleTypes[i]; Collection <Plan> l = null; if (plansByType.ContainsKey(t)) { l = plansByType[t]; } else { l = new Collection <Plan>(); // Always add 0 to the list of plans for a type. bool success; Plan pl = DefaultPlan(t, out success); if (success) { l.Add(pl); typeMap.AddTypeWithPlans(t); } plansByType[t] = l; } //we don't allow chars because the it can create unreadable chars if (/*t.IsValueType && */ t.IsPrimitive && !t.ToString().StartsWith("System.Char")) { if (p.transformer is PrimitiveValueTransformer) { l.Add(p); typeMap.AddTypeWithPlans(t); } else { if (resultTuple != null) { object pValue = resultTuple.tuple[i]; Util.Assert(pValue != null && pValue.GetType().Equals(t)); bool alreadyInDB = false; foreach (Plan existingPlan in l) { Util.Assert(existingPlan.transformer is PrimitiveValueTransformer); object existingPlanValue = (existingPlan.transformer as PrimitiveValueTransformer).fvalue; Util.Assert(existingPlanValue != null && existingPlanValue.GetType().Equals(pValue.GetType())); if (pValue.Equals(existingPlanValue)) { alreadyInDB = true; } } if (!alreadyInDB) { Plan constantPlan = Plan.Constant(t, pValue); l.Add(constantPlan); typeMap.AddTypeWithPlans(t); } } } } else { if (processedTypes.ContainsKey(t)) { continue; } processedTypes[t] = true; bool success; Plan pl = DefaultPlan(t, out success); // Util.Assert(l.Contains(p) && success ? p.Equals(pl) : true); typeMap.AddTypeWithPlans(t); l.Add(p); } } addSuccessful = true; } return(addSuccessful); }
// resultTuple can be null. private bool AddplanInternal(Plan p, ResultTuple resultTuple) { totalAttemptedAdditions++; bool addSuccessful = false; if (planSet.ContainsKey(p)) { totalFailedAdditions++; return false; } else { planSet[p] = true; NumPlans++; Dictionary<Type, bool> processedTypes = new Dictionary<Type, bool>(); for (int i = 0; i < p.transformer.TupleTypes.Length; i++) { if (!p.IsActiveTupleElement(i)) { continue; } Type t = p.transformer.TupleTypes[i]; Collection<Plan> l = null; if (plansByType.ContainsKey(t)) { l = plansByType[t]; } else { l = new Collection<Plan>(); // Always add 0 to the list of plans for a type. bool success; Plan pl = DefaultPlan(t, out success); if (success) { l.Add(pl); typeMap.AddTypeWithPlans(t); } plansByType[t] = l; } //we don't allow chars because the it can create unreadable chars if (/*t.IsValueType && */t.IsPrimitive && !t.ToString().StartsWith("System.Char")) { if (p.transformer is PrimitiveValueTransformer) { l.Add(p); typeMap.AddTypeWithPlans(t); } else { if (resultTuple != null) { object pValue = resultTuple.tuple[i]; Util.Assert(pValue != null && pValue.GetType().Equals(t)); bool alreadyInDB = false; foreach (Plan existingPlan in l) { Util.Assert(existingPlan.transformer is PrimitiveValueTransformer); object existingPlanValue = (existingPlan.transformer as PrimitiveValueTransformer).fvalue; Util.Assert(existingPlanValue != null && existingPlanValue.GetType().Equals(pValue.GetType())); if (pValue.Equals(existingPlanValue)) alreadyInDB = true; } if (!alreadyInDB) { Plan constantPlan = Plan.Constant(t, pValue); l.Add(constantPlan); typeMap.AddTypeWithPlans(t); } } } } else { if (processedTypes.ContainsKey(t)) continue; processedTypes[t] = true; bool success; Plan pl = DefaultPlan(t, out success); // Util.Assert(l.Contains(p) && success ? p.Equals(pl) : true); typeMap.AddTypeWithPlans(t); l.Add(p); } } addSuccessful = true; } return addSuccessful; }