コード例 #1
0
 /// <summary>
 ///   Gets a sequence of elements from a position in the buffer into a target buffer.
 /// </summary>
 /// <param name="positionInBytes">Relative position in bytes from the beginning of the buffer to get the data from.</param>
 /// <param name = "buffer">An array of values to be read from the buffer.</param>
 /// <param name = "offset">The zero-based byte offset in buffer at which to begin storing
 ///   the data read from the current buffer.</param>
 /// <param name = "count">The number of values to be read from the current buffer.</param>
 public void GetRange <T>(int positionInBytes, T[] buffer, int offset, int count) where T : struct
 {
     unsafe
     {
         Utilities.Read((IntPtr)(_buffer + positionInBytes), buffer, offset, count);
     }
 }
コード例 #2
0
        public unsafe T Get <T>(int positionInBytes) where T : struct
        {
            T data = default(T);

            Utilities.Read <T>((IntPtr)((void *)(this._buffer + positionInBytes)), ref data);
            return(data);
        }
コード例 #3
0
 /// <summary>
 ///   Gets an array of values from a position in the buffer.
 /// </summary>
 /// <param name="positionInBytes">Relative position in bytes from the beginning of the buffer to get the data from.</param>
 /// <param name="count">number of T instance to get from the positionInBytes</param>
 /// <typeparam name = "T">The type of the values to be read from the buffer.</typeparam>
 /// <returns>An array of values that was read from the current buffer.</returns>
 public T[] GetRange <T>(int positionInBytes, int count) where T : struct
 {
     unsafe
     {
         var result = new T[count];
         Utilities.Read((IntPtr)(_buffer + positionInBytes), result, 0, count);
         return(result);
     }
 }
コード例 #4
0
 /// <summary>
 ///   Gets a single value from the current buffer at the specified position.
 /// </summary>
 /// <param name="positionInBytes">Relative position in bytes from the beginning of the buffer to get the data from.</param>
 /// <typeparam name = "T">The type of the value to be read from the buffer.</typeparam>
 /// <returns>The value that was read.</returns>
 public T Get <T>(int positionInBytes) where T : struct
 {
     unsafe
     {
         T result = default(T);
         Utilities.Read((IntPtr)(_buffer + positionInBytes), ref result);
         return(result);
     }
 }
コード例 #5
0
ファイル: DataStream.cs プロジェクト: conankzhang/fez
        public unsafe int ReadRange <T>(T[] buffer, int offset, int count) where T : struct
        {
            if (!this._canRead)
            {
                throw new NotSupportedException();
            }
            long num = this._position;

            this._position = (sbyte *)(void *)Utilities.Read <T>((IntPtr)((void *)(this._buffer + this._position)), buffer, offset, count) - this._buffer;
            return((int)(this._position - num));
        }
コード例 #6
0
ファイル: DataStream.cs プロジェクト: conankzhang/fez
        public unsafe T[] ReadRange <T>(int count) where T : struct
        {
            if (!this._canRead)
            {
                throw new NotSupportedException();
            }
            sbyte *numPtr = this._buffer + this._position;

            T[] data = new T[count];
            this._position = (sbyte *)(void *)Utilities.Read <T>((IntPtr)((void *)numPtr), data, 0, count) - this._buffer;
            return(data);
        }
コード例 #7
0
        /// <summary>
        ///   Reads a sequence of elements from the current stream into a target buffer and
        ///   advances the position within the stream by the number of bytes read.
        /// </summary>
        /// <remarks>
        /// In order to provide faster read/write, this operation doesn't check stream bound.
        /// A client must carefully not read/write above the size of this datastream.
        /// </remarks>
        /// <param name = "buffer">An array of values to be read from the stream.</param>
        /// <param name = "offset">The zero-based byte offset in buffer at which to begin storing
        ///   the data read from the current stream.</param>
        /// <param name = "count">The number of values to be read from the current stream.</param>
        /// <returns>The number of bytes read from the stream.</returns>
        /// <exception cref = "T:System.NotSupportedException">This stream does not support reading.</exception>
        public int ReadRange <T>(T[] buffer, int offset, int count) where T : struct
        {
            unsafe
            {
                if (!_canRead)
                {
                    throw new NotSupportedException();
                }

                var oldPosition = _position;
                _position = (sbyte *)Utilities.Read((IntPtr)(_buffer + _position), buffer, offset, count) - _buffer;
                return((int)(_position - oldPosition));
            }
        }
コード例 #8
0
        /// <summary>
        ///   Reads an array of values from the current stream, and advances the current position
        ///   within this stream by the number of bytes written.
        /// </summary>
        /// <remarks>
        /// In order to provide faster read/write, this operation doesn't check stream bound.
        /// A client must carefully not read/write above the size of this datastream.
        /// </remarks>
        /// <typeparam name = "T">The type of the values to be read from the stream.</typeparam>
        /// <returns>An array of values that was read from the current stream.</returns>
        public T[] ReadRange <T>(int count) where T : struct
        {
            unsafe
            {
                if (!_canRead)
                {
                    throw new NotSupportedException();
                }

                sbyte *from   = _buffer + _position;
                var    result = new T[count];
                _position = (sbyte *)Utilities.Read((IntPtr)from, result, 0, count) - _buffer;
                return(result);
            }
        }
コード例 #9
0
ファイル: DataPointer.cs プロジェクト: zmtzawqlp/SharpDX
        /// <summary>
        /// Converts this instance to a read only byte buffer.
        /// </summary>
        /// <returns>A readonly byte buffer.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// DataPointer is Zero
        /// or
        /// Size cannot be &lt; 0
        /// </exception>
        public byte[] ToArray()
        {
            if (Pointer == IntPtr.Zero)
            {
                throw new InvalidOperationException("DataPointer is Zero");
            }
            if (Size < 0)
            {
                throw new InvalidOperationException("Size cannot be < 0");
            }
            var buffer = new byte[Size];

            Utilities.Read(Pointer, buffer, 0, Size);
            return(buffer);
        }
コード例 #10
0
ファイル: DataPointer.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// Reads the content of the unmanaged memory location of this instance to the specified buffer.
 /// </summary>
 /// <typeparam name="T">Type of a buffer element</typeparam>
 /// <param name="buffer">The buffer.</param>
 /// <param name="offset">The offset in the array to write to.</param>
 /// <param name="count">The number of T element to read from the memory location.</param>
 /// <exception cref="System.ArgumentNullException">buffer</exception>
 /// <exception cref="System.InvalidOperationException">DataPointer is Zero</exception>
 /// <exception cref="System.ArgumentOutOfRangeException">buffer;Total buffer size cannot be larger than size of this data pointer</exception>
 public void CopyTo <T>(T[] buffer, int offset, int count) where T : struct
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (Pointer == IntPtr.Zero)
     {
         throw new InvalidOperationException("DataPointer is Zero");
     }
     if (offset < 0)
     {
         throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
     }
     if (count <= 0)
     {
         throw new ArgumentOutOfRangeException("count", "Must be > 0");
     }
     if (count * Utilities.SizeOf <T>() > Size)
     {
         throw new ArgumentOutOfRangeException("buffer", "Total buffer size cannot be larger than size of this data pointer");
     }
     Utilities.Read(Pointer, buffer, offset, count);
 }
コード例 #11
0
 public unsafe void GetRange <T>(int positionInBytes, T[] buffer, int offset, int count) where T : struct
 {
     Utilities.Read <T>((IntPtr)((void *)(this._buffer + positionInBytes)), buffer, offset, count);
 }
コード例 #12
0
 public unsafe T[] GetRange <T>(int positionInBytes, int count) where T : struct
 {
     T[] data = new T[count];
     Utilities.Read <T>((IntPtr)((void *)(this._buffer + positionInBytes)), data, 0, count);
     return(data);
 }