uqa_sql/semantics/parameters/
definition.rs1use super::units::ParameterUnit;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub enum ParameterContext {
14 Internal,
16 Superuser,
18 User,
20}
21
22impl ParameterContext {
23 pub const fn name(self) -> &'static str {
25 match self {
26 Self::Internal => "internal",
27 Self::Superuser => "superuser",
28 Self::User => "user",
29 }
30 }
31}
32
33#[derive(Clone, Copy, Debug)]
35pub struct EnumOption {
36 pub name: &'static str,
37 pub value: u8,
38 pub hidden: bool,
40}
41
42impl EnumOption {
43 pub const fn listed(name: &'static str, value: u8) -> Self {
44 Self {
45 name,
46 value,
47 hidden: false,
48 }
49 }
50
51 pub const fn hidden(name: &'static str, value: u8) -> Self {
52 Self {
53 name,
54 value,
55 hidden: true,
56 }
57 }
58}
59
60#[derive(Clone, Copy, Debug)]
62pub enum ParameterKind {
63 Bool {
64 boot: bool,
65 },
66 Integer {
67 boot: i32,
68 min: i32,
69 max: i32,
70 unit: Option<ParameterUnit>,
71 },
72 Enum {
73 boot: u8,
74 options: &'static [EnumOption],
75 },
76 String {
77 boot: &'static str,
78 },
79}
80
81impl ParameterKind {
82 pub const fn type_name(&self) -> &'static str {
84 match self {
85 Self::Bool { .. } => "bool",
86 Self::Integer { .. } => "integer",
87 Self::Enum { .. } => "enum",
88 Self::String { .. } => "string",
89 }
90 }
91}
92
93#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
95pub struct ParameterFlags(u16);
96
97impl ParameterFlags {
98 pub const NONE: Self = Self(0);
99 pub const LIST_INPUT: Self = Self(1 << 0);
101 pub const LIST_QUOTE: Self = Self(1 << 1);
103 pub const NO_SHOW_ALL: Self = Self(1 << 2);
105 pub const NO_RESET: Self = Self(1 << 3);
107 pub const NO_RESET_ALL: Self = Self(1 << 4);
109 pub const REPORT: Self = Self(1 << 5);
111 pub const IS_NAME: Self = Self(1 << 6);
113
114 pub const fn union(self, other: Self) -> Self {
115 Self(self.0 | other.0)
116 }
117
118 pub const fn contains(self, other: Self) -> bool {
119 self.0 & other.0 == other.0
120 }
121}
122
123#[derive(Clone, Copy, Debug)]
125pub struct ParameterDefinition {
126 pub name: &'static str,
128 pub kind: ParameterKind,
129 pub context: ParameterContext,
130 pub category: &'static str,
131 pub short_desc: &'static str,
132 pub extra_desc: Option<&'static str>,
133 pub flags: ParameterFlags,
134 pub library: Option<&'static str>,
136}
137
138impl ParameterDefinition {
139 pub fn has_flag(&self, flag: ParameterFlags) -> bool {
140 self.flags.contains(flag)
141 }
142
143 pub fn boot_setting(&self) -> String {
145 match self.kind {
146 ParameterKind::Bool { boot } => if boot { "on" } else { "off" }.into(),
147 ParameterKind::Integer { boot, .. } => boot.to_string(),
148 ParameterKind::Enum { boot, options } => {
149 super::value::enum_display(options, boot).into()
150 }
151 ParameterKind::String { boot } => boot.into(),
152 }
153 }
154
155 pub fn unit(&self) -> Option<ParameterUnit> {
157 match self.kind {
158 ParameterKind::Integer { unit, .. } => unit,
159 _ => None,
160 }
161 }
162}