/// <summary> /// Adds an entry in the list /// </summary> /// <param name="next"></param> public void Add(MetricEntry next) { if (null == _next) { _next = next; return; } MetricEntry prev = _next; while (null != prev.Next) { prev = prev.Next; } prev.Next = next; }
/// <summary> /// Adds a new metric entry in the existing list of metric entries /// </summary> /// <param name="newEntry"></param> /// <returns></returns> public void AddMetricEntry(MetricEntry newEntry) { if (null == newEntry) { throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("MetricEntry cannot be null")); } if (null == _Entry) { _Entry = newEntry; } else { _Entry.Add(newEntry); // tack on at the end } _Count++; _size += newEntry.Size + SerializationHelper.VarSize(newEntry.Size) + SerializationHelper.VarSize((uint)newEntry.Tag); }
/// <summary> /// Compares a metricEntry object with this one and returns true or false /// </summary> /// <param name="metricEntry"></param> /// <returns></returns> public bool Compare(MetricEntry metricEntry) { if (Tag != metricEntry.Tag) { return(false); } if (Size != metricEntry.Size) { return(false); } for (int i = 0; i < Size; i++) { if (Data[i] != metricEntry.Data[i]) { return(false); } } return(true); }
/// <summary> /// This function Packs the data in the buffer provided. The /// function is being called during the save loop and caller /// must call GetSize for the block before calling this function. /// The buffer must be preallocated and buffer size must be at /// least the size of the block. /// On return cbBuffer contains the size of the data written. /// Called only by BuildMetricTable funtion /// </summary> /// <param name="strm"></param> /// <returns></returns> public uint Pack(Stream strm) { // Write the size of the Block at the begining of the buffer. // But first check the validity of the buffer & its size uint cbWrite = 0; // First write the size of the block cbWrite = SerializationHelper.Encode(strm, _size); // Now write each entry for the block MetricEntry entry = _Entry; while (null != entry) { cbWrite += SerializationHelper.Encode(strm, (uint)entry.Tag); cbWrite += SerializationHelper.Encode(strm, entry.Size); strm.Write(entry.Data, 0, (int)entry.Size); cbWrite += entry.Size; entry = entry.Next; } return(cbWrite); }
/// <summary> /// Adds a new metric entry in the existing list of metric entries /// </summary> /// <param name="property"></param> /// <param name="tag"></param> /// <returns></returns> public MetricEntryType AddMetricEntry(StylusPointPropertyInfo property, KnownTagCache.KnownTagIndex tag) { // Create a new metric entry based on the packet information passed. MetricEntry entry = new MetricEntry(); MetricEntryType type = entry.CreateMetricEntry(property, tag); // Don't add this entry to the global list if size is 0, means default metric values! if( 0 == entry.Size ) { return type; } MetricEntry start = _Entry; if( null == start ) { _Entry = entry; } else // tack on data at the end, want to keep x,y at the beginning { while(start.Next != null) { start = start.Next; } start.Next = entry; } _Count++; _size += entry.Size + SerializationHelper.VarSize(entry.Size) + SerializationHelper.VarSize((uint)_Entry.Tag); return type; }
/// <summary> /// Adds a new metric entry in the existing list of metric entries /// </summary> /// <param name="newEntry"></param> /// <returns></returns> public void AddMetricEntry(MetricEntry newEntry) { if (null == newEntry) { throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("MetricEntry cannot be null")); } if( null == _Entry ) _Entry = newEntry; else _Entry.Add(newEntry); // tack on at the end _Count ++; _size += newEntry.Size + SerializationHelper.VarSize(newEntry.Size) + SerializationHelper.VarSize((uint)newEntry.Tag); }
/// <summary> /// Adds an entry in the list /// </summary> /// <param name="next"></param> public void Add(MetricEntry next) { if( null == _next ) { _next = next; return; } MetricEntry prev = _next; while( null != prev.Next ) { prev = prev.Next; } prev.Next = next; }
/// <summary> /// Compares a metricEntry object with this one and returns true or false /// </summary> /// <param name="metricEntry"></param> /// <returns></returns> public bool Compare(MetricEntry metricEntry) { if( Tag != metricEntry.Tag ) return false; if( Size != metricEntry.Size ) return false; for( int i = 0; i < Size; i++ ) { if( Data[i] != metricEntry.Data[i] ) return false; } return true; }
/// <summary> /// Decodes a Metric Block from the stream. For information on how they are stored in the stream, please refer to the spec. /// </summary> /// <param name="strm"></param> /// <param name="cbSize"></param> /// <param name="block"></param> /// <returns></returns> private uint DecodeMetricBlock(Stream strm, uint cbSize, out MetricBlock block) { // allocate the block block = new MetricBlock(); if (cbSize == 0) return 0; uint cb; uint cbTotal = cbSize; uint size; while (cbTotal > 0) { // First decode the tag for this entry uint dw; cb = SerializationHelper.Decode(strm, out dw); if (cb > cbTotal) throw new ArgumentException(ISFDebugMessage("Invalid ISF data"),"strm"); cbTotal -= cb; // Next read the size of the metric data cb = SerializationHelper.Decode(strm, out size); if (cb + size > cbTotal) throw new ArgumentException(ISFDebugMessage("Invalid ISF data"),"strm"); cbTotal -= cb; // now create new metric entry MetricEntry entry = new MetricEntry(); entry.Tag = (KnownTagCache.KnownTagIndex)dw; byte[] data = new byte[size]; uint bytesRead = StrokeCollectionSerializer.ReliableRead(strm, data, size); cbTotal -= bytesRead; if ( bytesRead != size ) { // Make sure the bytes read are expected. If not, we should bail out. // An exception will be thrown. break; } entry.Data = data; block.AddMetricEntry(entry); } if (0 != cbTotal) throw new ArgumentException(ISFDebugMessage("Invalid ISF data"),"strm"); return cbSize; }
// // /// <summary> /// This function compares pMetricColl with the current one. If pMetricColl has more entries apart from the one /// in the current list with which some of its entries are identical, setType is set as SUPERSET. /// </summary> /// <param name="metricColl"></param> /// <param name="setType"></param> /// <returns></returns> public bool CompareMetricBlock(MetricBlock metricColl, ref SetType setType) { if (null == metricColl) { return(false); } // if both have null entry, implies default metric Block for both of them // and it already exists in the list. Return TRUE // If only one of the blocks is empty, return FALSE - they cannot be merged // because the other block may have customized GUID_X or GUID_Y. if (null == GetMetricEntryList()) { return(metricColl.GetMetricEntryList() == null); } if (null == metricColl.GetMetricEntryList()) { return(false); } // Else compare the entries bool fTagFound = false; uint cbLhs = this.MetricEntryCount; // No of entries in this block uint cbRhs = metricColl.MetricEntryCount; // No of entries in the block to be compared MetricEntry outside, inside; if (metricColl.MetricEntryCount <= MetricEntryCount) { outside = metricColl.GetMetricEntryList(); inside = GetMetricEntryList(); } else { inside = metricColl.GetMetricEntryList(); outside = GetMetricEntryList(); setType = SetType.SuperSet; } // For each entry in metricColl, search for the same in this Block. // If it is found, continue with the next entry of smaller Block. while (null != outside) { fTagFound = false; // Always start at the begining of the larger block MetricEntry temp = inside; while (null != temp) { if (outside.Compare(temp)) { fTagFound = true; break; } else { temp = temp.Next; } } if (!fTagFound) { return(false); } // Found the entry; Continue with the next entry in the outside block outside = outside.Next; } return(true); }