DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Properties | Private Attributes | List of all members
Deveel.Data.Store.StoreBase.StoreArea Class Reference

An IArea that is backed by a StoreBase. More...

Inheritance diagram for Deveel.Data.Store.StoreBase.StoreArea:
Deveel.Data.Store.IArea

Public Member Functions

 StoreArea (StoreBase store, long id, long offset, bool readOnly)
 
 StoreArea (StoreBase store, long id, long offset, bool readOnly, long fixedSize)
 
void CopyTo (IArea destArea, int size)
 Copies the given amount of bytes from the current position of the this area to another one. More...
 
int Read (byte[] buffer, int offset, int length)
 Reads an array of bytes from the underlying IArea and advances the position by length . More...
 
void Write (byte[] buffer, int offset, int length)
 
void Flush ()
 

Protected Member Functions

long CheckAreaOffset (int diff)
 

Properties

long Id [get, private set]
 
long StartOffset [get, set]
 
long EndOffset [get, set]
 
StoreBase Store [get, set]
 
virtual bool IsReadOnly [get, private set]
 
long Position [get, set]
 
int Length [get]
 
- Properties inherited from Deveel.Data.Store.IArea
long Id [get]
 Returns the unique identifier that represents this area. More...
 
bool IsReadOnly [get]
 Gets a value indicating whether this area can be written or not. More...
 
long Position [get, set]
 Returns or sets the current position of the pointer within the area. More...
 
int Length [get]
 

Private Attributes

byte[] buffer = new byte[BufferSize]
 
long position
 
const int BufferSize = 8
 

Detailed Description

An IArea that is backed by a StoreBase.

Definition at line 887 of file StoreBase.cs.

Constructor & Destructor Documentation

Deveel.Data.Store.StoreBase.StoreArea.StoreArea ( StoreBase  store,
long  id,
long  offset,
bool  readOnly 
)
inline

Definition at line 893 of file StoreBase.cs.

893  {
894  Store = store;
895  Id = id;
896  IsReadOnly = readOnly;
897 
898  store.CheckOffset(offset);
899 
900  store.Read(offset, buffer, 0, 8);
901  long v = ByteBuffer.ReadInt8(buffer, 0);
902  if ((v & DeletedFlag) != 0)
903  throw new IOException("Store being constructed on deleted area.");
904 
905  long maxSize = v - 16;
906  StartOffset = offset + 8;
908  EndOffset = StartOffset + maxSize;
909  }
A wrapper for an array of byte.
Definition: ByteBuffer.cs:27
static long ReadInt8(byte[] arr, int offset)
Definition: ByteBuffer.cs:234
Deveel.Data.Store.StoreBase.StoreArea.StoreArea ( StoreBase  store,
long  id,
long  offset,
bool  readOnly,
long  fixedSize 
)
inline

Definition at line 911 of file StoreBase.cs.

911  {
912  Store = store;
913  Id = id;
914  IsReadOnly = readOnly;
915 
916  // Check the offset is valid
917  if (offset != FixedAreaOffset) {
918  store.CheckOffset(offset);
919  }
920 
921  StartOffset = offset;
923  EndOffset = StartOffset + fixedSize;
924  }

Member Function Documentation

long Deveel.Data.Store.StoreBase.StoreArea.CheckAreaOffset ( int  diff)
inlineprotected

Definition at line 951 of file StoreBase.cs.

951  {
952  long newPos = position + diff;
953  if (newPos > EndOffset)
954  throw new IOException("Trying to access a position out of area bounds.");
955 
956  long oldPos = position;
957  position = newPos;
958  return oldPos;
959  }
void Deveel.Data.Store.StoreBase.StoreArea.CopyTo ( IArea  destArea,
int  size 
)
inline

Copies the given amount of bytes from the current position of the this area to another one.

Parameters
destAreaThe IArea where to write.
sizeThe number of bytes to Write.

Implements Deveel.Data.Store.IArea.

Definition at line 961 of file StoreBase.cs.

961  {
962  // NOTE: Assuming 'destination' is a StoreArea, the temporary buffer
963  // could be optimized away to a direct Array.Ccopy. However, this
964  // function would need to be written as a lower level IO function.
965  const int bufferSize = 2048;
966  byte[] buf = new byte[bufferSize];
967  int toCopy = System.Math.Min(size, bufferSize);
968 
969  while (toCopy > 0) {
970  var read = Read(buf, 0, toCopy);
971  if (read == 0)
972  break;
973 
974  destArea.Write(buf, 0, read);
975  size -= toCopy;
976  toCopy = System.Math.Min(size, bufferSize);
977  }
978  }
int Read(byte[] buffer, int offset, int length)
Reads an array of bytes from the underlying IArea and advances the position by length ...
Definition: StoreBase.cs:980
void Deveel.Data.Store.StoreBase.StoreArea.Flush ( )
inline

Implements Deveel.Data.Store.IArea.

Definition at line 991 of file StoreBase.cs.

991  {
992  }
int Deveel.Data.Store.StoreBase.StoreArea.Read ( byte[]  buffer,
int  offset,
int  length 
)
inline

Reads an array of bytes from the underlying IArea and advances the position by length .

Parameters
bufferThe destination buffer into which to Read the number of bytes given from the area.
offsetThe offset within the buffer from where to start writing the byte Read into.
lengthThe number of bytes to Read from the area. This is also the incremental size of the position of the area.
Returns
Returns the number of bytes actually Read from the IArea.

Implements Deveel.Data.Store.IArea.

Definition at line 980 of file StoreBase.cs.

980  {
981  return Store.Read(CheckAreaOffset(length), buffer, offset, length);
982  }
abstract int Read(long offset, byte[] buffer, int index, int length)
void Deveel.Data.Store.StoreBase.StoreArea.Write ( byte[]  buffer,
int  offset,
int  length 
)
inline

Parameters
buffer
offset
length

Implements Deveel.Data.Store.IArea.

Definition at line 984 of file StoreBase.cs.

984  {
985  if (IsReadOnly)
986  throw new IOException("The area is read-only access.");
987 
988  Store.Write(CheckAreaOffset(length), buffer, offset, length);
989  }
void Write(long offset, byte value)
Definition: StoreBase.cs:876

Member Data Documentation

byte [] Deveel.Data.Store.StoreBase.StoreArea.buffer = new byte[BufferSize]
private

Definition at line 888 of file StoreBase.cs.

const int Deveel.Data.Store.StoreBase.StoreArea.BufferSize = 8
private

Definition at line 891 of file StoreBase.cs.

long Deveel.Data.Store.StoreBase.StoreArea.position
private

Definition at line 889 of file StoreBase.cs.

Property Documentation

long Deveel.Data.Store.StoreBase.StoreArea.EndOffset
getsetprivate

Definition at line 930 of file StoreBase.cs.

long Deveel.Data.Store.StoreBase.StoreArea.Id
getprivate set

Definition at line 926 of file StoreBase.cs.

virtual bool Deveel.Data.Store.StoreBase.StoreArea.IsReadOnly
getprivate set

Definition at line 934 of file StoreBase.cs.

int Deveel.Data.Store.StoreBase.StoreArea.Length
get

Definition at line 947 of file StoreBase.cs.

long Deveel.Data.Store.StoreBase.StoreArea.Position
getset

Definition at line 936 of file StoreBase.cs.

long Deveel.Data.Store.StoreBase.StoreArea.StartOffset
getsetprivate

Definition at line 928 of file StoreBase.cs.

StoreBase Deveel.Data.Store.StoreBase.StoreArea.Store
getsetprivate

Definition at line 932 of file StoreBase.cs.


The documentation for this class was generated from the following file: