Esempio n. 1
0
        /// <summary>Flush the cache to <see cref="BaseStream"/> with <see cref="kWordByteCount"/> or fewer bytes bytes</summary>
        void FlushCache()
        {
                        #if !CONTRACTS_FULL_SHIM // can't do this with our shim! ValueAtReturn sets out param to default ON ENTRY
            Contract.Ensures(Contract.ValueAtReturn(out mCache) == 0);
            Contract.Ensures(Contract.ValueAtReturn(out mCacheBitIndex) == 0);
                        #endif

            if (mCacheBitIndex == 0)             // no bits to flush!
            {
                Contract.Assert(mCache == 0, "Why is there data in the cache?");
                return;
            }

            mCacheBitsStreamedCount = 0;

            int byte_count = (mCacheBitIndex - 1) >> Bits.kByteBitShift; // number of bytes to try and write
            int shift      = kWordBitCount - Bits.kByteBitCount;         // start shifting from the MSB
            while (                                                      /*!IsEndOfStream &&*/
                byte_count >= 0)
            {
                mIoBuffer[0] = (byte)(mCache >> shift);
                BaseStream.Write(mIoBuffer, 0, sizeof(byte));
                --byte_count;
                shift -= Bits.kByteBitCount;
                mCacheBitsStreamedCount += Bits.kByteBitCount;
            }

            if (byte_count != -1 && ThrowOnOverflow.CanWrite())
            {
                throw new System.IO.EndOfStreamException("Tried to write more bits than the stream has/can see");
            }

            mCache         = 0;
            mCacheBitIndex = 0;
        }
Esempio n. 2
0
        /// <summary>Restore the cursor to what it was before the corresponding call to a <see cref="WriteElementBegin(string, XmlElement&amp;)"/></summary>
        public void WriteElementEnd(ref TCursor oldCursor)
        {
                        #if !CONTRACTS_FULL_SHIM // can't do this with our shim! ValueAtReturn sets out param to default ON ENTRY
            Contract.Ensures(Contract.ValueAtReturn(out oldCursor) == null);
                        #endif

            RestoreCursor(ref oldCursor);
        }
Esempio n. 3
0
        /// <summary>Get the procedure for building a mask of a section of bits in a vector, relative to the vector's element size (<see cref="System.Int64"/>)</summary>
        /// <param name="proc"></param>
        /// <param name="byteOrder">Order in which bits are enumerated (first to last)</param>
        public static void GetVectorElementSectionBitMaskInT(out VectorElementBitMask <ulong> proc,
                                                             Shell.EndianFormat byteOrder = kVectorWordFormat)
        {
            Contract.Ensures(Contract.ValueAtReturn(out proc) != null);

            proc = byteOrder == Shell.EndianFormat.Big
                                ? (VectorElementBitMask <ulong>)VectorElementSectionBitMaskInInt64BE
                                : (VectorElementBitMask <ulong>)VectorElementSectionBitMaskInInt64LE;
        }
Esempio n. 4
0
        /// <summary>Returns the cursor to a previously saved cursor value</summary>
        /// <param name="oldCursor">Previously saved cursor. Set to null before the method returns</param>
        public void RestoreCursor(ref TCursor oldCursor)
        {
                        #if !CONTRACTS_FULL_SHIM // can't do this with our shim! ValueAtReturn sets out param to default ON ENTRY
            Contract.Ensures(Contract.ValueAtReturn(out oldCursor) == null);
                        #endif
            Contract.Assert(oldCursor != null, "Can't restore a cursor that wasn't saved!");

            Cursor    = oldCursor;
            oldCursor = null;
        }
Esempio n. 5
0
        /// <summary>Generate an 32-bit bit count to bitmask table</summary>
        /// <param name="wordBitSize">Number of bits to generate a table for</param>
        /// <param name="lut">Bitmask look up table</param>
        /// <remarks>Treat <paramref name="lut"/> as <b>read-only</b></remarks>
        public static void BitmaskLookUpTableGenerate(int wordBitSize, out uint[] lut)
        {
            Contract.Requires/*<ArgumentOutOfRangeException>*/ (wordBitSize > 0 && wordBitSize <= kUInt32BitCount);
            Contract.Ensures(Contract.ValueAtReturn(out lut) != null);

            if (wordBitSize == kUInt32BitCount && kBitmaskLookup32 != null)
            {
                lut = kBitmaskLookup32;
            }
            else
            {
                lut = new uint[BitmaskLookUpTableGetLength(wordBitSize)];
                for (int x = 1, shift = lut.Length - 2; x < lut.Length; x++, shift--)
                {
                    lut[x] = (uint)(uint.MaxValue >> shift);
                }
            }
        }
Esempio n. 6
0

        
        public override void ReadElementEnd(ref TCursor oldCursor)
        {
            Contract.Ensures(Contract.ValueAtReturn(out oldCursor) == null);

            throw new NotImplementedException();
        }
Esempio n. 8
0
        public static void GetVectorElementFromBufferInT(out VectorElementFromBuffer <ulong> proc)
        {
            Contract.Ensures(Contract.ValueAtReturn(out proc) != null);

            proc = VectorElementFromBufferInT;
        }