public static void Serialize <TDoc, TCursor>(TagElementStream <TDoc, TCursor, string> s, ref Values.GroupTagData32 value) where TDoc : class where TCursor : class { bool reading = s.IsReading; var group_tag = reading ? null : value.TagString; var name = reading ? null : value.Name; var guid = reading ? Values.KGuid.Empty : value.Uuid; s.StreamAttribute("tag", ref group_tag); s.StreamAttributeOpt("guid", ref guid, Predicates.IsNotEmpty); s.StreamAttribute("name", ref name); if (reading) { value = new Values.GroupTagData32(group_tag, name, guid); } }
public static void Serialize <TDoc, TCursor>(TagElementStream <TDoc, TCursor, string> s, ref Values.GroupTag32Collection collection, string groupsElementName = "Groups") where TDoc : class where TCursor : class { Contract.Requires(!string.IsNullOrEmpty(groupsElementName)); bool reading = s.IsReading; var guid = reading ? Values.KGuid.Empty : collection.Uuid; var tags = reading ? null // HACK: GroupTags is exposed as a IReadOnlyList, but at the time of this writing is implemented // with a GroupTagData32[] as its backing field : (Values.GroupTagData32[])collection.GroupTags; s.StreamAttributeOpt("guid", ref guid, Predicates.IsNotEmpty); using (var bm = s.EnterCursorBookmarkOpt(groupsElementName, tags, Predicates.HasItems)) if (bm.IsNotNull) { StreamElements(s, ref tags); } if (reading) { bool sort = false; s.ReadAttributeOpt("sort", ref sort); collection = new Values.GroupTag32Collection(guid, sort, tags); } }
/// <summary>Saves the stream's cursor and sets <paramref name="newCursor"/> to be the new cursor for the stream</summary> /// <param name="stream">The underlying stream for this bookmark</param> /// <param name="newCursor">The new cursor for the stream</param> public TagElementStreamReadBookmark(TagElementStream <TDoc, TCursor, TName> stream, TCursor newCursor) { Contract.Requires <ArgumentNullException>(stream != null); Contract.Requires <ArgumentNullException>(newCursor != null); (mStream = stream).SaveCursor(newCursor, out mOldCursor); }
TagElementStreamBookmark( [SuppressMessage("Microsoft.Design", "CA1801:ReviewUnusedParameters")] bool dummy) { mStream = null; mOldCursor = null; }
/// <summary>Returns the cursor of the underlying stream to the last saved cursor value</summary> public void Dispose() { if (mStream != null) { mStream.WriteElementEnd(ref mOldCursor); mStream = null; } }
/// <summary>Returns the cursor of the underlying stream to the last saved cursor value</summary> public void Dispose() { if (mStream != null) { mStream.RestoreCursor(ref mOldCursor); mStream = null; } }
/// <summary>Saves the stream's cursor so a new one can be specified, but then later restored to the saved cursor, via <see cref="Dispose()"/></summary> /// <param name="stream">The underlying stream for this bookmark</param> /// <param name="elementName"></param> public TagElementStreamWriteBookmark(TagElementStream <TDoc, TCursor, TName> stream, TName elementName) { Contract.Requires <ArgumentNullException>(stream != null); Contract.Requires <ArgumentNullException>(elementName != null); mStream = null; mOldCursor = null; (mStream = stream).WriteElementBegin(elementName, out mOldCursor); }
public static void Serialize <TDoc, TCursor, TContext>(BitSet @this, TagElementStream <TDoc, TCursor, string> s, string elementName, TContext ctxt, SerializeBitToTagElementStreamDelegate <TDoc, TCursor, TContext> streamElement, int highestBitIndex = TypeExtensions.kNoneInt32) where TDoc : class where TCursor : class { Contract.Requires(s != null); Contract.Requires(streamElement != null); Contract.Requires(highestBitIndex.IsNoneOrPositive()); Contract.Requires(highestBitIndex < @this.Length); if (highestBitIndex.IsNone()) { highestBitIndex = @this.Length - 1; } if (s.IsReading) { int bit_index = 0; foreach (var node in s.ElementsByName(elementName)) { using (s.EnterCursorBookmark(node)) { bit_index = streamElement(s, @this, TypeExtensions.kNoneInt32, ctxt); if (bit_index.IsNone()) { s.ThrowReadException(new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo, "Element is not a valid {0} value", elementName))); } @this[bit_index] = true; } } } else if (s.IsWriting) { foreach (int bit_index in @this.SetBitIndices) { if (bit_index > highestBitIndex) { break; } using (s.EnterCursorBookmark(elementName)) streamElement(s, @this, bit_index, ctxt); } } }
public static void Serialize <TDoc, TCursor, TContext>(this Collections.BitSet @this, IO.TagElementStream <TDoc, TCursor, string> s, string elementName, TContext ctxt, IO.TagElementStreamDefaultSerializer.SerializeBitToTagElementStreamDelegate <TDoc, TCursor, TContext> streamElement, int highestBitIndex = TypeExtensions.kNoneInt32) where TDoc : class where TCursor : class { Contract.Requires(s != null); Contract.Requires(streamElement != null); Contract.Requires(highestBitIndex.IsNoneOrPositive()); Contract.Requires(highestBitIndex < @this.Length); IO.TagElementStreamDefaultSerializer.Serialize(@this, s, elementName, ctxt, streamElement, highestBitIndex); }
static void StreamElements <TDoc, TCursor>(TagElementStream <TDoc, TCursor, string> s, ref Values.GroupTagData32[] tags) where TDoc : class where TCursor : class { const string k_element_name = "Group"; if (s.IsReading) { var list = new List <Values.GroupTagData32>(); foreach (var node in s.ElementsByName(k_element_name)) { using (s.EnterCursorBookmark(node)) { Values.GroupTagData32 data = null; Serialize(s, ref data); list.Add(data); } } tags = list.ToArray(); } else if (s.IsWriting) { foreach (Values.GroupTagData32 data in tags) { using (s.EnterCursorBookmark(k_element_name)) { var temp = data; // can't pass a foreach value by ref Serialize(s, ref temp); } } } }
public void Serialize <TDoc, TCursor>(TagElementStream <TDoc, TCursor, TName> s) where TDoc : class where TCursor : class { Contract.Requires(s != null); }