Example #1
0
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints2 = new OperatorHints();

            hints2.CreateOperatorCode += HandleCreateOperatorCode;
            hints2.ImplementingClass   = nameof(Def_Energy_Time_Power);
            c.WithDiv <Energy, Time, Power>(hints2);
        }
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.ImplementingClass   = nameof(Def_Power_EnergyMassDensity_MassStream);
            hints.CreateOperatorCode += HandleCreateOperatorCode;
            c.WithDiv <Power, EnergyMassDensity, MassStream>(hints);
        }
Example #3
0
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.CreateOperatorCode += HandleCreateOperatorCode;
            hints.ImplementingClass   = nameof(Def_Power_Length_LinearPowerLoss);
            c.WithDiv <ValueA, ValueB, ValueC>(hints);
        }
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.ImplementingClass   = nameof(Def_LinearForce_Length_Pressure);
            hints.CreateOperatorCode += HandleCreateOperatorCode;
            c.WithDiv <LinearForce, Length, Pressure>(hints);
        }
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.CreateOperatorCode += HandleCreateOperatorCode;
            hints.ImplementingClass   = nameof(Def_LinearPowerLoss_Length_Irradiance);
            c.WithDiv <UnitA, UnitB, UnitC>(hints);
        }
Example #6
0
 public OperatorCodeBuilderInput GetBuilder()
 {
     if (OperatorHints is null)
     {
         return(null);
     }
     return(OperatorHints.GetBuilder(this));
 }
        public static void Setup(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints
            {
                ImplementingClass = nameof(Def_Force_Area_Pressure)
            };

            hints.CreateOperatorCode += HandleCreateOperatorCode;
            c.WithDiv <TMul, T1, T2>(hints);
        }
        public static OperatorHints GetBasicOperatorHints()
        {
            var hints = new OperatorHints();

            hints.CreateOperatorCode += (sender, args) =>
            {
                args.Result.Comment = args.Input.DebugIs;
                Debug.WriteLine("Processing " + args.Input.DebugIs);
                CreateHeuristicCode(args);
                args.SetHandled();
            };
            return(hints);
        }
Example #9
0
        private static void Add_EnergyMassDensity_DeltaKelvinTemperature_SpecificHeatCapacity(MultiplicationAlgebra c)
        {
            var hints = new OperatorHints();

            hints.CreateOperatorCode += (sender, args) =>
            {
                args.Result.Comment = args.Input.DebugIs;
                AlgebraDefUtils.CreateHeuristicCode(args);
                args.SetHandled();
            };
            hints.ImplementingClass = nameof(MultiplicationAlgebraDefs);

            c.WithDiv <EnergyMassDensity, DeltaKelvinTemperature, SpecificHeatCapacity>(hints);
        }
Example #10
0
        public MultiplicationAlgebra WithDiv <T1, T2, TDiv>(OperatorHints operatorHints = null,
                                                            bool areRelatedUnits        = false)
        {
            var x = new MultiplicationAlgebraItem(
                new TypesGroup(typeof(T1).Name),
                new TypesGroup(typeof(T2).Name),
                new TypesGroup(typeof(TDiv).Name),
                areRelatedUnits,
                operatorHints
                );

            Items.Add(x);
            return(this);
        }
        private void CreateOperator(TypesGroup left, TypesGroup right, TypesGroup result, string op,
                                    bool areRelatedUnits, NullableArguments nullableArguments, OperatorHints operatorHints)
        {
            var leftValue  = left.Value.ValueTypeName;
            var rightValue = right.Value.ValueTypeName;

            if ((nullableArguments & NullableArguments.Left) != 0)
            {
                leftValue += "?";
            }
            if ((nullableArguments & NullableArguments.Right) != 0)
            {
                rightValue += "?";
            }

            var operatorGenerationKey = new OperatorGenerationKey(leftValue, rightValue, op);

            var tResult = result.Value;

            if (_done.TryGetValue(operatorGenerationKey, out var resultType))
            {
                if (resultType != tResult.ValueTypeName)
                {
                    throw new NotSupportedException();
                }
                return;
            }

            _done[operatorGenerationKey] = tResult.ValueTypeName;

            var info = op == "/" ? OperatorInfo.Div : OperatorInfo.Mul;

            var leftName  = info.Left.Name;
            var rightName = info.Right.Name;

            if (left.Value != right.Value)
            {
                leftName  = left.Value.FirstLower();
                rightName = right.Value.FirstLower();
            }

            var cl = GetClass(operatorGenerationKey.GetOperatorTargetType());

            cl.Kind = CsNamespaceMemberKind.Struct;

            // cw.WriteLine("// " + key + " " + areRelatedUnits);

            var rightFraction = FractionUnitDefs.IsFraction(right);
            var leftFraction  = FractionUnitDefs.IsFraction(left);

            var rightUnit  = "rightUnit";
            var resultUnit = "resultUnit";

            CsCodeWriter PrepareCode()
            {
                if (nullableArguments == NullableArguments.None)
                {
                    var ppp = new OperatorParams(left, right, result, leftName, rightName, op, operatorHints);
                    if (areRelatedUnits)
                    {
                        return(CreateCodeForRelatedUnits(ppp, ref rightUnit, ref resultUnit));
                    }
                    if (leftFraction != null)
                    {
                        if (rightFraction == null)
                        {
                            return(CreateCodeForLeftFractionValue(ppp, leftFraction));
                        }

                        {
                            var cw = Ext.Create <Self>();

                            if (TryHint(ppp, cw))
                            {
                                cw.WriteLine("// scenario F1");
                                return(cw);
                            }

                            cw.WriteLine("// scenario F2");
                            cw.WithThrowNotImplementedException();
                            return(cw);
                        }
                    }

                    if (rightFraction != null)
                    {
                        return(CreateCodeForRightFractionValue(rightFraction, ppp));
                    }

                    {
                        var cw = Ext.Create <Self>();

                        if (TryHint(ppp, cw))
                        {
                            cw.WriteLine("// scenario F3");
                            return(cw);
                        }
                    }
                    return(CreateCodeForFractionalResult(ppp));
                }

                return(NullableArgument.CreateCode(leftName, rightName, op, nullableArguments));
            }

            var cw1 = PrepareCode();

            var method = cl.AddMethod(op, tResult + (nullableArguments == NullableArguments.None ? "" : "?"),
                                      info.Description)
                         .WithBody(cw1);

            var p = method.AddParam(leftName, leftValue);

            p.Description = info.Left.Desctiption;
            p             = method.AddParam(rightName, rightValue);
            p.Description = info.Right.Desctiption;
        }
Example #12
0
 public OperatorParams(TypesGroup left, TypesGroup right, TypesGroup result, string leftMethodArgumentName,
                       string rightMethodArgumentName, string oper, OperatorHints operatorHints) : base(left, right, result,
                                                                                                        leftMethodArgumentName, rightMethodArgumentName, oper)
 {
     OperatorHints = operatorHints;
 }