コード例 #1
0
        public Status Initialize(CalculatorGraphConfig config, SidePacket sidePacket)
        {
            UnsafeNativeMethods.mp_CalculatorGraph__Initialize__Rconfig_Rsp(mpPtr, config.mpPtr, sidePacket.mpPtr, out var statusPtr).Assert();

            GC.KeepAlive(this);
            return(new Status(statusPtr));
        }
コード例 #2
0
        public CalculatorGraph(CalculatorGraphConfig config) : base()
        {
            var bytes = config.ToByteArray();

            UnsafeNativeMethods.mp_CalculatorGraph__Rcgc(bytes, bytes.Length, out var ptr).Assert();
            this.ptr = ptr;
        }
コード例 #3
0
        public CalculatorGraph(string configText) : base(UnsafeNativeMethods.MpCalculatorGraphCreate())
        {
            graphConfig = new CalculatorGraphConfig(configText);

            var status = Initialize(graphConfig);

            status.AssertOk();
        }
コード例 #4
0
        public CalculatorGraph(string configText) : base()
        {
            var config = CalculatorGraphConfig.ParseFromString(configText);

            UnsafeNativeMethods.mp_CalculatorGraph__Rconfig(config.mpPtr, out var ptr).Assert();
            GC.KeepAlive(config);
            this.ptr = ptr;
        }
コード例 #5
0
        public Status Initialize(CalculatorGraphConfig config, SidePacket sidePacket)
        {
            var bytes = config.ToByteArray();

            UnsafeNativeMethods.mp_CalculatorGraph__Initialize__PKc_i_Rsp(mpPtr, bytes, bytes.Length, sidePacket.mpPtr, out var statusPtr).Assert();

            GC.KeepAlive(this);
            return(new Status(statusPtr));
        }
コード例 #6
0
        public Status Initialize(CalculatorGraphConfig config)
        {
            var bytes = config.ToByteArray();

            UnsafeNativeMethods.mp_ValidatedGraphConfig__Initialize__Rcgc(mpPtr, bytes, bytes.Length, out var statusPtr).Assert();

            GC.KeepAlive(this);
            return(new Status(statusPtr));
        }
コード例 #7
0
        public static string GetUnusedNodeName(CalculatorGraphConfig config, string nodeNameBase)
        {
            var nodeNames = new HashSet <string>(config.Node.Select(node => node.Name).Where(name => name.Length > 0));

            var candidate = nodeNameBase;
            var iter      = 1;

            while (nodeNames.Contains(candidate))
            {
                candidate = $"{nodeNameBase}_{++iter:D2}";
            }

            return(candidate);
        }
コード例 #8
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (OwnsResource())
            {
                UnsafeNativeMethods.MpCalculatorGraphDestroy(ptr);
            }

            ptr         = IntPtr.Zero;
            graphConfig = null;

            _disposed = true;
        }
コード例 #9
0
        /// <exception cref="ArgumentOutOfRangeException">
        ///   Thrown when <paramref name="nodeId" /> is invalid
        /// </exception>
        public static string CanonicalNodeName(CalculatorGraphConfig graphConfig, int nodeId)
        {
            var nodeConfig = graphConfig.Node[nodeId];
            var nodeName   = nodeConfig.Name.Length == 0 ? nodeConfig.Calculator : nodeConfig.Name;

            var nodesWithSameName = graphConfig.Node
                                    .Select((node, i) => (node.Name.Length == 0 ? node.Calculator : node.Name, i))
                                    .Where(pair => pair.Item1 == nodeName);

            if (nodesWithSameName.Count() <= 1)
            {
                return(nodeName);
            }

            var seq = nodesWithSameName.Count(pair => pair.i <= nodeId);

            return($"{nodeName}_{seq}");
        }
コード例 #10
0
        public static string GetUnusedSidePacketName(CalculatorGraphConfig config, string inputSidePacketNameBase)
        {
            var inputSidePackets = new HashSet <string>(
                config.Node.SelectMany(node => node.InputSidePacket)
                .Select(sidePacket => {
                ParseTagIndexName(sidePacket, out var tag, out var index, out var name);
                return(name);
            }));

            string candidate = inputSidePacketNameBase;
            int    iter      = 1;

            while (inputSidePackets.Contains(candidate))
            {
                candidate = $"{inputSidePacketNameBase}_{++iter:D2}";
            }

            return(candidate);
        }
コード例 #11
0
        public static string GetUnusedStreamName(CalculatorGraphConfig config, string streamNameBase)
        {
            var outputStreamNames = config.Node.SelectMany(node => node.OutputStream)
                                    .Select(outputStream =>
            {
                ParseTagIndexName(outputStream, out var tag, out var index, out var name);
                return(name);
            });

            var candidate = streamNameBase;
            var iter      = 1;

            while (config.InputStream.Contains(candidate))
            {
                candidate = $"{streamNameBase}_{++iter:D2}";
            }

            while (outputStreamNames.Contains(candidate))
            {
                candidate = $"{streamNameBase}_{++iter:D2}";
            }

            return(candidate);
        }
コード例 #12
0
 public CalculatorGraph(CalculatorGraphConfig config) : this(config.ToByteArray())
 {
 }
コード例 #13
0
 private Status Initialize(CalculatorGraphConfig config)
 {
     return(new Status(UnsafeNativeMethods.MpCalculatorGraphInitialize(ptr, config.GetPtr())));
 }