// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; using System.Diagnostics; using System.Runtime.InteropServices; [DebuggerDisplay("{Value}", Name = "{Key}")] internal sealed class OptionInternal : IOption { [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly IntPtr m_options; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly Option option; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly float min; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly float max; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly float step; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private readonly float @default; [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string description; internal OptionInternal(IntPtr options, Option option) { m_options = options; this.option = option; object error; NativeMethods.rs2_get_option_range(m_options, option, out min, out max, out step, out @default, out error); } /// Gets the option description /// human-readable option description public string Description { get { if (description == null) { object error; var str = NativeMethods.rs2_get_option_description(m_options, option, out error); description = Marshal.PtrToStringAnsi(str); } return description; } } /// Gets or sets option value /// value of the option public float Value { get { object error; return NativeMethods.rs2_get_option(m_options, option, out error); } set { object error; NativeMethods.rs2_set_option(m_options, option, value, out error); } } /// get option value description (in case specific option value hold special meaning) /// value of the option /// human-readable description of a specific value of an option or null if no special meaning public string GetValueDescription(float value) { object error; var str = NativeMethods.rs2_get_option_value_description(m_options, option, value, out error); return Marshal.PtrToStringAnsi(str); } public Option Key => option; public float Min => min; public float Max => max; public float Step => step; public float Default => @default; /// Gets the option value description (in case specific option value hold special meaning) /// human-readable description of a specific value of an option or null if no special meaning public string ValueDescription => GetValueDescription(Value); /// Gets a value indicating whether an option is read-only /// if option is read-only public bool ReadOnly { get { object error; return NativeMethods.rs2_is_option_read_only(m_options, option, out error) != 0; } } } }