//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
//
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
///
/// The native version of the JET_SPACEHINTS structure.
///
[StructLayout(LayoutKind.Sequential)]
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
"SA1305:FieldNamesMustNotUseHungarianNotation",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
internal struct NATIVE_SPACEHINTS
{
///
/// Size of the structure.
///
public uint cbStruct;
///
/// Density at (append) layout.
///
public uint ulInitialDensity;
///
/// Initial size (in bytes).
///
public uint cbInitial;
///
/// Space hints options.
///
public uint grbit;
///
/// Density to maintain at.
///
public uint ulMaintDensity;
///
/// Percent growth from last growth or initial size (possibly rounded to nearest native JET allocation size).
///
public uint ulGrowth;
///
/// Overrides ulGrowth if too small.
///
public uint cbMinExtent;
///
/// Cap of ulGrowth.
///
public uint cbMaxExtent;
}
///
/// Describes a column in a table of an ESENT database.
///
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[Serializable]
public sealed class JET_SPACEHINTS : IContentEquatable, IDeepCloneable
{
///
/// Density at (append) layout.
///
private int initialDensity;
///
/// Initial size (in bytes).
///
private int initialSize;
///
/// Space hints options.
///
private SpaceHintsGrbit options;
///
/// Density to maintain at.
///
private int maintenanceDensity;
///
/// Percent growth from last growth or initial size (possibly rounded to nearest native JET allocation size).
///
private int growthPercent;
///
/// Overrides ulGrowth if too small.
///
private int minimumExtent;
///
/// Cap of ulGrowth.
///
private int maximumExtent;
///
/// Gets or sets the density at (append) layout.
///
public int ulInitialDensity
{
[DebuggerStepThrough]
get { return this.initialDensity; }
set { this.initialDensity = value; }
}
///
/// Gets or sets the initial size (in bytes).
///
public int cbInitial
{
[DebuggerStepThrough]
get { return this.initialSize; }
set { this.initialSize = value; }
}
///
/// Gets or sets the space hints options.
///
public SpaceHintsGrbit grbit
{
[DebuggerStepThrough]
get { return this.options; }
set { this.options = value; }
}
///
/// Gets or sets the density at which to maintain.
///
public int ulMaintDensity
{
[DebuggerStepThrough]
get { return this.maintenanceDensity; }
set { this.maintenanceDensity = value; }
}
///
/// Gets or sets the percent growth from last growth or initial size (possibly rounded
/// to nearest native JET allocation size).
/// Valid values are 0, and [100, 50000).
///
public int ulGrowth
{
[DebuggerStepThrough]
get { return this.growthPercent; }
set { this.growthPercent = value; }
}
///
/// Gets or sets the value that overrides ulGrowth if too small. This value is in bytes.
///
public int cbMinExtent
{
[DebuggerStepThrough]
get { return this.minimumExtent; }
set { this.minimumExtent = value; }
}
///
/// Gets or sets the value that sets the ceiling of ulGrowth. This value is in bytes.
///
public int cbMaxExtent
{
[DebuggerStepThrough]
get { return this.maximumExtent; }
set { this.maximumExtent = value; }
}
#region IContentEquatable
///
/// Returns a value indicating whether this instance is equal
/// to another instance.
///
/// An instance to compare with this instance.
/// True if the two instances are equal.
public bool ContentEquals(JET_SPACEHINTS other)
{
if (null == other)
{
return false;
}
return this.ulInitialDensity == other.ulInitialDensity
&& this.cbInitial == other.cbInitial
&& this.grbit == other.grbit
&& this.ulMaintDensity == other.ulMaintDensity
&& this.ulGrowth == other.ulGrowth
&& this.cbMinExtent == other.cbMinExtent
&& this.cbMaxExtent == other.cbMaxExtent;
}
#endregion
#region IDeepCloneable
///
/// Returns a deep copy of the object.
///
/// A deep copy of the object.
public JET_SPACEHINTS DeepClone()
{
JET_SPACEHINTS result = (JET_SPACEHINTS)this.MemberwiseClone();
return result;
}
#endregion
///
/// Generate a string representation of the instance.
///
/// The structure as a string.
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "JET_SPACEHINTS({0})", this.grbit);
}
///
/// Returns the unmanaged columncreate that represents this managed class.
///
/// A native (interop) version of the JET_SPACEHINTS.
internal NATIVE_SPACEHINTS GetNativeSpaceHints()
{
var native = new NATIVE_SPACEHINTS();
native.cbStruct = checked((uint)Marshal.SizeOf(typeof(NATIVE_SPACEHINTS)));
native.ulInitialDensity = checked((uint)this.ulInitialDensity);
native.cbInitial = checked((uint)this.cbInitial);
native.grbit = (uint)this.grbit;
native.ulMaintDensity = checked((uint)this.ulMaintDensity);
native.ulGrowth = checked((uint)this.ulGrowth);
native.cbMinExtent = checked((uint)this.cbMinExtent);
native.cbMaxExtent = checked((uint)this.cbMaxExtent);
return native;
}
///
/// Sets the fields of the object from a native JET_SPACEHINTS struct.
///
///
/// The native columncreate to set the values from.
///
internal void SetFromNativeSpaceHints(NATIVE_SPACEHINTS value)
{
this.ulInitialDensity = checked((int)value.ulInitialDensity);
this.cbInitial = checked((int)value.cbInitial);
this.grbit = (SpaceHintsGrbit)value.grbit;
this.ulMaintDensity = checked((int)value.ulMaintDensity);
this.ulGrowth = checked((int)value.ulGrowth);
this.cbMinExtent = checked((int)value.cbMinExtent);
this.cbMaxExtent = checked((int)value.cbMaxExtent);
}
}
}