@@ -324,6 +324,54 @@ namespace BlazesRusCode
324324 }
325325 }
326326
327+ // / <summary>
328+ // / Swaps the updated form data.
329+ // / </summary>
330+ // / <param name="FormCopy">The form copy.</param>
331+ // / <param name="ElementValues">The element values.</param>
332+ // / <param name="FormIndex">Index of the form.</param>
333+ void ReplaceVariablesWithRefValues (ReferenceMap ElementValues, size_t FormIndex = 0 )
334+ {
335+ std::string CurString;
336+ MediumDec targetResult;
337+ FormData& FormDRef = Data.at (FormIndex);
338+ for (FormData::iterator CurrentVal = FormDRef.begin (), LastVal = FormDRef.end (); CurrentVal != LastVal; ++CurrentVal)
339+ {
340+ if (CurrentVal->second .ElementCat == FormulaElementType::Formula)// FormulaDetected
341+ {
342+ ReplaceVariablesWithRefValues (ElementValues, CurrentVal->second .Index );
343+ }
344+ else if (CurrentVal->second .ElementCat == FormulaElementType::Variable)// Swap Variable with values
345+ {
346+ CurString = FormDRef.VariableMap .at (CurrentVal->first ).Name ;
347+ tsl::ordered_map<std::string, MediumDec&>::iterator KeyedElemVal = ElementValues.find (CurString);
348+ if (KeyedElemVal != ElementValues.end ())// Only attempt to replace variable if matching variable is found
349+ {
350+ FormDRef.at (CurrentVal->first ).ElementCat = FormulaElementType::Num;
351+ targetResult = KeyedElemVal.value ();
352+ FormDRef.NumMap .insert_or_assign (CurrentVal->first , targetResult);// ElementValues.at(CurString));
353+ }
354+ else
355+ {
356+ std::cout << " Failed to replace variable named " << CurString << " with value data" << std::endl;
357+ }
358+ }
359+ }
360+ }
361+
362+ // / <summary>
363+ // / Simplifies and evaluates the formula and then returns the copy.
364+ // / </summary>
365+ // / <param name="ElementValues">The element values.</param>
366+ // / <returns>BlazesRusCode.MediumDecFormula</returns>
367+ MediumDecFormula EvaluateRefToSimplifiedForm (ReferenceMap ElementValues)
368+ {
369+ MediumDecFormula FormCopy = *this ;// Duplicate values so can erase parts when calculating
370+ FormCopy.ReplaceVariablesWithRefValues (ElementValues);
371+ FormCopy.EvaluateOperations ();
372+ return FormCopy;
373+ }
374+
327375 // / <summary>
328376 // / Swaps the updated form data.
329377 // / </summary>
@@ -380,7 +428,7 @@ namespace BlazesRusCode
380428 {
381429 MediumDecFormula FormCopy = *this ;// Duplicate values so can erase parts when calculating
382430 FormCopy.ReplaceVariablesWithValues (ElementValues);
383- // FormCopy.EvaluateOperations();
431+ FormCopy.EvaluateOperations ();
384432 return FormCopy;
385433 }
386434
0 commit comments