/// <summary>
        /// Returns true when the given key is found and sets the value.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool TryGetValue(string key, out string value)
        {
            uint keyInt = _stringTable.Add(key);  // TODO: this could be problematic, testing contains adds objects to string table.

            foreach (var tagEncoded in _tagsList.Where(tagEncoded => tagEncoded.Key == keyInt))
            {
                value = _stringTable.Get(tagEncoded.Value);
                return(true);
            }
            value = null;
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Does the actual serialization of the given data structures.
        /// </summary>
        private static void Serialize(int begin, Stream stream, List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > > tagIndex,
                                      ObjectTable <string> stringTable)
        {
            RuntimeTypeModel typeModel = TagIndexSerializer.CreateTypeModel();

            // move until after the index (index contains two int's, startoftagindex, endoffile).
            stream.Seek(begin + 8, SeekOrigin.Begin);

            // serialize string table.
            List <string> strings = new List <string>();

            for (uint id = 0; id < stringTable.Count; id++)
            {
                strings.Add(stringTable.Get(id));
            }
            stringTable.Clear();
            stringTable = null;
            typeModel.Serialize(stream, strings);
            long startOfTagsIndex = stream.Position - begin;

            // serialize tagindex.
            typeModel.Serialize(stream, tagIndex);
            long endOfFile = stream.Position - begin;

            // write index.
            stream.Seek(begin, SeekOrigin.Begin);
            stream.Write(BitConverter.GetBytes((int)startOfTagsIndex), 0, 4); // write start position of tagindex.
            stream.Write(BitConverter.GetBytes((int)endOfFile), 0, 4);        // write size of complete file.

            stream.Seek(begin + endOfFile, SeekOrigin.Begin);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the tags with the given id.
        /// </summary>
        /// <param name="tagsId"></param>
        /// <returns></returns>
        public TagsCollection Get(uint tagsId)
        {
            OsmTags osmTags = _tagsTable.Get(tagsId);

            if (osmTags != null)
            {
                return(new SimpleTagsCollection(osmTags.Tags));
            }
            return(null);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds a new tag (key-value pair) to this tags collection.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public override void AddOrReplace(string key, string value)
 {
     for (int idx = 0; idx < _tags.Count; idx++)
     {
         Tag tag = _tagsTable.Get(_tags[idx]);
         if (tag.Key == key)
         {
             tag.Value  = value;
             _tags[idx] = _tagsTable.Add(tag);
             return;
         }
     }
     this.Add(key, value);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the tags with the given id.
        /// </summary>
        /// <param name="tagsId"></param>
        /// <returns></returns>
        public TagsCollectionBase Get(uint tagsId)
        {
            OsmTags osmTags = _tagsCollectionTable.Get(tagsId);

            if (osmTags != null)
            {
                TagsCollection collection = new TagsCollection();
                for (int idx = 0; idx < osmTags.Tags.Length; idx++)
                {
                    collection.Add(
                        _tagsTable.Get(osmTags.Tags[idx]));
                }
                return(collection);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public void TestStringTable_AddStrings()
        {
            ObjectTable <string> table = new ObjectTable <string>(false);

            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));


            table = new ObjectTable <string>(true);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
Ejemplo n.º 7
0
        public void TestStringTable_AddStrings()
        {
            ObjectTable<string> table = new ObjectTable<string>(false);
            uint zero = table.Add("zero");
            uint one = table.Add("one");
            uint two = table.Add("two");
            uint three = table.Add("three");
            uint four = table.Add("four");
            uint five = table.Add("five");
            uint six = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable<string>(true);
            zero = table.Add("zero");
            one = table.Add("one");
            two = table.Add("two");
            three = table.Add("three");
            four = table.Add("four");
            five = table.Add("five");
            six = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Does the actual serialization of the given data structures.
        /// </summary>
        private static void Serialize(int begin, Stream stream, List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>> tagIndex,
            ObjectTable<string> stringTable)
        {
            RuntimeTypeModel typeModel = TagIndexSerializer.CreateTypeModel();

            // move until after the index (index contains two int's, startoftagindex, endoffile).
            stream.Seek(begin + 8, SeekOrigin.Begin);

            // serialize string table.
            List<string> strings = new List<string>();
            for (uint id = 0; id < stringTable.Count; id++)
            {
                strings.Add(stringTable.Get(id));
            }
            stringTable.Clear();
            stringTable = null;
            typeModel.Serialize(stream, strings);
            long startOfTagsIndex = stream.Position - begin;

            // serialize tagindex.
            typeModel.Serialize(stream, tagIndex);
            long endOfFile = stream.Position - begin;

            // write index.
            stream.Seek(begin, SeekOrigin.Begin);
            stream.Write(BitConverter.GetBytes((int)startOfTagsIndex), 0, 4); // write start position of tagindex.
            stream.Write(BitConverter.GetBytes((int)endOfFile), 0, 4); // write size of complete file.

            stream.Seek(begin + endOfFile, SeekOrigin.Begin);
        }
Ejemplo n.º 9
0
        public void TestStringTable_AddStringsTwice()
        {
            ObjectTable<string> table = new ObjectTable<string>(false);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable<string>(true);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
Ejemplo n.º 10
0
        public void TestStringTable_AddStringsTwice()
        {
            ObjectTable <string> table = new ObjectTable <string>(false);
            uint zero  = table.Add("zero");
            uint one   = table.Add("one");
            uint two   = table.Add("two");
            uint three = table.Add("three");
            uint four  = table.Add("four");
            uint five  = table.Add("five");
            uint six   = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable <string>(true);
            zero  = table.Add("zero");
            one   = table.Add("one");
            two   = table.Add("two");
            three = table.Add("three");
            four  = table.Add("four");
            five  = table.Add("five");
            six   = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }