an heterogeneous map. it is basically a regular Dictionary, but it associates with each entry a packer for the key and a packer for the value. for "simple types", for which a packer can be inferred, you may use the 2-argument version of Add() or the [] operator, but for all other types, you should use the 4-argument version of Add(), where you specify the packers for the key and value. note: this class implements IDictionary, so it can be used by third-party code, but only for "simple types", for which a packer can be inferred
Inheritance: IDictionary
コード例 #1
0
ファイル: HeteroMap.cs プロジェクト: zlorb/agnos
 public void Update(HeteroMap other)
 {
     foreach (KeyValuePair <Object, FieldInfo> e in other.fields)
     {
         Add(e.Key, e.Value.keypacker, other.data[e.Key], e.Value.valpacker);
     }
 }
コード例 #2
0
ファイル: HeteroMap.cs プロジェクト: zlorb/agnos
        /// <summary>
        /// Adds a new HeteroMap instance to this HeteroMap under the given key
        /// This is a convenience function, used by the Agnos binding code,
        /// but it's not expected to be useful to the general public.
        /// </summary>
        /// <param name="name">
        /// The key
        /// </param>
        /// <returns>
        /// a new HeteroMap instance
        /// </returns>
        public HeteroMap AddNewMap(String name)
        {
            HeteroMap hm = new HeteroMap();

            Add(name, Packers.Str, hm, Packers.builtinHeteroMapPacker);
            return(hm);
        }
コード例 #3
0
            protected void processGetInfo(int seq)
            {
                int       code = (int)(Packers.Int32.unpack(transport));
                HeteroMap info = new HeteroMap();

                switch (code)
                {
                case INFO_SERVICE:
                    processGetServiceInfo(info);
                    break;

                case INFO_FUNCTIONS:
                    processGetFunctionsInfo(info);
                    break;

                case INFO_REFLECTION:
                    processGetReflectionInfo(info);
                    break;

                case INFO_META:
                default:
                    processGetMetaInfo(info);
                    break;
                }

                Packers.Int8.pack(REPLY_SUCCESS, transport);
                Packers.builtinHeteroMapPacker.pack(info, transport);
            }
コード例 #4
0
ファイル: Packers.cs プロジェクト: zlorb/agnos
            public override Object unpack(ITransport transport)
            {
                int       length = (int)Int32.unpack(transport);
                HeteroMap map    = new HeteroMap(length);

                for (int i = 0; i < length; i++)
                {
                    int            keypid    = (int)Int32.unpack(transport);
                    AbstractPacker keypacker = getPacker(keypid);
                    Object         key       = keypacker.unpack(transport);

                    int            valpid    = (int)Int32.unpack(transport);
                    AbstractPacker valpacker = getPacker(valpid);
                    Object         val       = valpacker.unpack(transport);

                    map.Add(key, keypacker, val, valpacker);
                }
                return(map);
            }
コード例 #5
0
ファイル: Packers.cs プロジェクト: zlorb/agnos
            public override void pack(Object obj, ITransport transport)
            {
                HeteroMap map = (HeteroMap)obj;

                if (map == null)
                {
                    Int32.pack(0, transport);
                }
                else
                {
                    Int32.pack(map.Count, transport);
                    foreach (DictionaryEntry e in map)
                    {
                        AbstractPacker keypacker = map.getKeyPacker(e.Key);
                        AbstractPacker valpacker = map.getValuePacker(e.Key);

                        Int32.pack(keypacker.getId(), transport);
                        keypacker.pack(e.Key, transport);

                        Int32.pack(valpacker.getId(), transport);
                        valpacker.pack(e.Value, transport);
                    }
                }
            }
コード例 #6
0
ファイル: HeteroMap.cs プロジェクト: zlorb/agnos
 public HeteroMap(HeteroMap other)
 {
     fields = new Dictionary <object, FieldInfo> (other.fields);
     data   = new Hashtable(other.data);
 }
コード例 #7
0
ファイル: HeteroMap.cs プロジェクト: tomerfiliba/agnos
 public HeteroMap(HeteroMap other)
 {
     fields = new Dictionary<object, FieldInfo> (other.fields);
     data = new Hashtable (other.data);
 }
コード例 #8
0
ファイル: Protocol.cs プロジェクト: tomerfiliba/agnos
 protected abstract void processGetFunctionsInfo(HeteroMap info);
コード例 #9
0
ファイル: Main.cs プロジェクト: tomerfiliba/agnos
    protected static void test(FeatureTest.Client conn)
    {
        conn.AssertServiceCompatibility();

        var eve = conn.Person.init("eve", null,	null);
        var adam = conn.Person.init("adam", null, null);
        eve.marry(adam);
        var cain = conn.Person.init("cain", adam, eve);
        if (cain.name != "cain") {
            throw new Exception("cain is not the name");
        }

        bool succ = true;
        try {
            adam.marry(eve);
        } catch (FeatureTest.MartialStatusError) {
            // okay
            succ = false;
        }

        if (succ) {
            throw new Exception("an exception should have been thrown!");
        }

        double thought = adam.think(17, 3.0);
        if (thought != (17/3.0)) {
            throw new Exception("adam thinks wrong: " + thought);
        }

        try {
            adam.think(17, 0);
        } catch (Agnos.GenericException) {
            // okay
        }

        var info = conn.GetServiceInfo(Agnos.Protocol.INFO_SERVICE);
        if ((String)info["SERVICE_NAME"] != "FeatureTest") {
            throw new Exception("wrong service name: " + info["SERVICE_NAME"]);
        }

        info = conn.GetServiceInfo(Agnos.Protocol.INFO_FUNCTIONS);
        foreach (DictionaryEntry e in info) {
            System.Console.WriteLine("{0} = {1}", e.Key, e.Value);
        }

        byte[] barr = {(byte)0xff, (byte)0xee, (byte)0xaa, (byte)0xbb};
        IList<double> lst = new List<double>();
        lst.Add(1.3);
        lst.Add(FeatureTest.pi);
        lst.Add(4.4);
        ICollection<int> hs = new HashSet<int>();
        hs.Add(18);
        hs.Add(19);
        hs.Add(20);
        IDictionary<int, string> hm = new Dictionary<int, string>();
        hm[34] = "foo";
        hm[56] = "bar";
        FeatureTest.Address adr = new FeatureTest.Address(FeatureTest.State.NY, "albany", "foobar drive", 1772);

        FeatureTest.Everything everything = conn.func_of_everything(
                (byte)1, (short)2, 3, (long)4, 5.5, true, new DateTime(), barr,
                "hello world", lst, hs, hm, adr, eve, FeatureTest.MyEnum.C);

        if (everything.some_int32 != 3) {
            throw new Exception("expected 'some_int32' to be 3" + everything.some_int32);
        }

        HeteroMap hm1 = new HeteroMap();
        hm1["x"] = "y";
        HeteroMap hm2 = conn.hmap_test(1999, hm1);
        if ((int)hm2["a"] != 1999) {
            throw new Exception("expected 'a' to be 1999; " + hm2["a"]);
        }

        System.Console.WriteLine("test passed!");
    }
コード例 #10
0
 protected abstract void processGetReflectionInfo(HeteroMap info);
コード例 #11
0
 protected abstract void processGetFunctionsInfo(HeteroMap info);
コード例 #12
0
 protected abstract void processGetServiceInfo(HeteroMap info);
コード例 #13
0
ファイル: HeteroMap.cs プロジェクト: tomerfiliba/agnos
 public void Update(HeteroMap other)
 {
     foreach (KeyValuePair<Object, FieldInfo> e in other.fields) {
         Add (e.Key, e.Value.keypacker, other.data[e.Key], e.Value.valpacker);
     }
 }
コード例 #14
0
ファイル: Main.cs プロジェクト: tomerfiliba/agnos
 public HeteroMap hmap_test(int a, HeteroMap b)
 {
     HeteroMap hm = new HeteroMap();
     hm["a"] = a;
     hm["b"] = 18;
     return hm;
 }
コード例 #15
0
ファイル: Protocol.cs プロジェクト: tomerfiliba/agnos
 protected abstract void processGetServiceInfo(HeteroMap info);
コード例 #16
0
ファイル: Protocol.cs プロジェクト: tomerfiliba/agnos
 protected abstract void processGetReflectionInfo(HeteroMap info);
コード例 #17
0
ファイル: Protocol.cs プロジェクト: tomerfiliba/agnos
 protected abstract void processGetMetaInfo(HeteroMap info);
コード例 #18
0
ファイル: Protocol.cs プロジェクト: tomerfiliba/agnos
            protected void processGetInfo(int seq)
            {
                int code = (int)(Packers.Int32.unpack (transport));
                HeteroMap info = new HeteroMap();

                switch (code) {
                case INFO_SERVICE:
                    processGetServiceInfo (info);
                    break;
                case INFO_FUNCTIONS:
                    processGetFunctionsInfo (info);
                    break;
                case INFO_REFLECTION:
                    processGetReflectionInfo (info);
                    break;
                case INFO_META:
                default:
                    processGetMetaInfo(info);
                    break;
                }

                Packers.Int8.pack (REPLY_SUCCESS, transport);
                Packers.builtinHeteroMapPacker.pack(info, transport);
            }
コード例 #19
0
 protected abstract void processGetMetaInfo(HeteroMap info);
コード例 #20
0
ファイル: HeteroMap.cs プロジェクト: tomerfiliba/agnos
 /// <summary>
 /// Adds a new HeteroMap instance to this HeteroMap under the given key
 /// This is a convenience function, used by the Agnos binding code,
 /// but it's not expected to be useful to the general public.
 /// </summary>
 /// <param name="name">
 /// The key
 /// </param>
 /// <returns>
 /// a new HeteroMap instance
 /// </returns>
 public HeteroMap AddNewMap(String name)
 {
     HeteroMap hm = new HeteroMap ();
     Add (name, Packers.Str, hm, Packers.builtinHeteroMapPacker);
     return hm;
 }