magellan/Lucidiot.Raima/FieldEntry.cs

164 lines
5.1 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace Lucidiot.Raima {
/// <summary>
/// Type of the key applied to a field.
/// A key is more commonly known as a B-Tree index.
/// </summary>
public enum FieldKeyType : byte {
/// <summary>
/// There is no key for this field.
/// Using this value on a field of type <see cref="FieldType.CompoundKey" /> makes the field inoperant.
/// </summary>
None = (byte)'n',
/// <summary>
/// A B-Tree index is built for this field, but no uniqueness checks are performed during insertions or updates.
/// </summary>
Duplicates = (byte)'d',
/// <summary>
/// A B-Tree index is built for this field, and uniqueness checks are performed using it during insertions or updates.
/// </summary>
Unique = (byte)'u'
}
/// <summary>
/// Data type of the value stored in a field.
/// </summary>
public enum FieldType : byte {
/// <summary>
/// A character-type field.
/// This is often changed into a string by using the field's array sizes to turn it into a <c>char[]</c>.
/// </summary>
Char = (byte)'c',
/// <summary>
/// A single byte.
/// </summary>
/// <remarks>
/// The character for this field type is <c>'s'</c>, meaning "short", but this does not match the .NET definition of <c>short</c>.
/// </remarks>
Byte = (byte)'s',
/// <summary>
/// A 16-bit integer.
/// </summary>
/// <remarks>
/// The character for this field type is <c>'i'</c>, meaning "int", but this does not match the .NET definition of <c>int</c>.
/// </remarks>
Int16 = (byte)'i',
/// <summary>
/// A 32-bit integer.
/// </summary>
/// <remarks>
/// The character for this field type is <c>'l'</c>, meaning "long", but this does not match the .NET definition of <c>long</c>.
/// </remarks>
Int32 = (byte)'l',
/// <summary>
/// A single-precision IEEE 754 floating point number.
/// </summary>
Float = (byte)'f',
/// <summary>
/// A double-precision IEEE 754 floating point number.
/// </summary>
/// <remarks>
/// A header file of the Common Desktop Environment defines a double as 'F', while its comments use 'D'.
/// </remarks>
Double = (byte)'F',
DatabaseAddress = (byte)'d',
/// <summary>
/// This field regroups multiple fields into one. This is also known as a "struct field".
/// All subsequent fields in the field table that use the <see cref="FieldEntryOptions.StructField" /> flag
/// are sub-fields of this field.
/// </summary>
GroupedField = (byte)'g',
/// <summary>
/// The field is a compound key, used to build a B-Tree index over multiple fields.
/// The <see cref="FieldEntry.KeyType" /> attribute should not be set to <see cref="FieldKeyType.None" />.
/// </summary>
CompoundKey = (byte)'k'
}
[Flags]
public enum FieldEntryOptions : ushort {
/// <summary>
/// No specific options are applied.
/// </summary>
None = 0x0000,
/// <summary>
/// This field is referenced by a <see cref="SortEntry" />.
/// </summary>
SortField = 0x0001,
/// <summary>
/// This field is part of a <see cref="FieldType.GroupedField" /> field that was mentioned earlier in the field table.
/// </summary>
StructField = 0x0002,
/// <summary>
/// The field's type is unsigned.
/// </summary>
Unsigned = 0x0004,
/// <summary>
/// The field is optional.
/// </summary>
Optional = 0x0008,
/// <summary>
/// This field is referenced by a <see cref="KeyEntry" /> for another <see cref="FieldType.CompoundKey" /> field.
/// </summary>
CompoundKeyMember = 0x0010
}
[StructLayout(LayoutKind.Explicit, Size = 20)]
public struct FieldEntry {
[FieldOffset(0)]
public FieldKeyType KeyType;
[FieldOffset(1)]
public FieldType Type;
[FieldOffset(2)]
public short Length;
// Those would probably make more sense as an array of three `short`, but I cannot seem to make that work with marshaling...
[FieldOffset(4)]
public short Dimension1;
[FieldOffset(6)]
public short Dimension2;
[FieldOffset(8)]
public short Dimension3;
[FieldOffset(10)]
public short KeyFileIndex;
[FieldOffset(12)]
public short KeyNumber;
/// <summary>
/// Offset to the field's data inside a record, in bytes.
/// With a type set to <see cref="FieldType.CompoundKey" />, this is the index of the first <see cref="KeyEntry" /> of the compound key.
/// </summary>
[FieldOffset(14)]
public short Offset;
[FieldOffset(16)]
public short RecordEntryIndex;
[FieldOffset(18)]
public FieldEntryOptions Options;
}
}