1use crate::features::IdlFeatures;
13use crate::grammar::IdlVersion;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub struct ParserConfig {
25 pub version: IdlVersion,
27 pub compat: CompatMode,
29 pub vendor: VendorExt,
32 pub profile: Profile,
37 pub features: IdlFeatures,
42}
43
44impl Default for ParserConfig {
45 fn default() -> Self {
46 Self {
47 version: IdlVersion::V4_2,
48 compat: CompatMode::Strict,
49 vendor: VendorExt::None,
50 profile: Profile::DdsExtensible,
51 features: IdlFeatures::dds_extensible(),
52 }
53 }
54}
55
56impl ParserConfig {
57 #[must_use]
59 pub const fn strict_4_2() -> Self {
60 Self {
61 version: IdlVersion::V4_2,
62 compat: CompatMode::Strict,
63 vendor: VendorExt::None,
64 profile: Profile::DdsExtensible,
65 features: IdlFeatures::dds_extensible(),
66 }
67 }
68
69 #[must_use]
72 pub const fn pragmatic_4_2() -> Self {
73 Self {
74 version: IdlVersion::V4_2,
75 compat: CompatMode::Pragmatic,
76 vendor: VendorExt::None,
77 profile: Profile::DdsExtensible,
78 features: IdlFeatures::dds_extensible(),
79 }
80 }
81
82 #[must_use]
85 pub const fn plain_dds_4_2() -> Self {
86 Self {
87 version: IdlVersion::V4_2,
88 compat: CompatMode::Strict,
89 vendor: VendorExt::None,
90 profile: Profile::DdsBasic,
91 features: IdlFeatures::dds_basic(),
92 }
93 }
94
95 #[must_use]
98 pub const fn full_4_2() -> Self {
99 Self {
100 version: IdlVersion::V4_2,
101 compat: CompatMode::Strict,
102 vendor: VendorExt::None,
103 profile: Profile::Full,
104 features: IdlFeatures::corba_full(),
105 }
106 }
107
108 #[must_use]
111 pub const fn opensplice_legacy() -> Self {
112 Self {
113 version: IdlVersion::V4_2,
114 compat: CompatMode::Pragmatic,
115 vendor: VendorExt::OpenSplice,
116 profile: Profile::Full,
117 features: IdlFeatures::opensplice_legacy(),
118 }
119 }
120
121 #[must_use]
123 pub const fn opensplice_modern() -> Self {
124 Self {
125 version: IdlVersion::V4_2,
126 compat: CompatMode::Strict,
127 vendor: VendorExt::OpenSplice,
128 profile: Profile::DdsExtensible,
129 features: IdlFeatures::opensplice_modern(),
130 }
131 }
132
133 #[must_use]
135 pub const fn rti_connext() -> Self {
136 Self {
137 version: IdlVersion::V4_2,
138 compat: CompatMode::Strict,
139 vendor: VendorExt::Rti,
140 profile: Profile::DdsExtensible,
141 features: IdlFeatures::rti_connext(),
142 }
143 }
144
145 #[must_use]
147 pub const fn cyclonedds() -> Self {
148 Self {
149 version: IdlVersion::V4_2,
150 compat: CompatMode::Strict,
151 vendor: VendorExt::None,
152 profile: Profile::DdsExtensible,
153 features: IdlFeatures::cyclonedds(),
154 }
155 }
156
157 #[must_use]
159 pub const fn fastdds() -> Self {
160 Self {
161 version: IdlVersion::V4_2,
162 compat: CompatMode::Strict,
163 vendor: VendorExt::None,
164 profile: Profile::DdsExtensible,
165 features: IdlFeatures::fastdds(),
166 }
167 }
168}
169
170#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
176pub enum CompatMode {
177 #[default]
179 Strict,
180 Pragmatic,
183}
184
185#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
208pub enum Profile {
209 DdsBasic,
211 #[default]
213 DdsExtensible,
214 Full,
216}
217
218#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
224pub enum VendorExt {
225 #[default]
227 None,
228 Rti,
230 OpenSplice,
232 CycloneDds,
234 FastDds,
236}
237
238#[cfg(test)]
239mod tests {
240 #![allow(clippy::expect_used)]
241
242 use super::*;
243
244 #[test]
245 fn default_is_strict_4_2_no_vendor() {
246 let cfg = ParserConfig::default();
247 assert_eq!(cfg.version, IdlVersion::V4_2);
248 assert_eq!(cfg.compat, CompatMode::Strict);
249 assert_eq!(cfg.vendor, VendorExt::None);
250 }
251
252 #[test]
253 fn strict_4_2_constructor_matches_default() {
254 assert_eq!(ParserConfig::strict_4_2(), ParserConfig::default());
255 }
256
257 #[test]
258 fn pragmatic_4_2_keeps_version_and_no_vendor() {
259 let cfg = ParserConfig::pragmatic_4_2();
260 assert_eq!(cfg.version, IdlVersion::V4_2);
261 assert_eq!(cfg.compat, CompatMode::Pragmatic);
262 assert_eq!(cfg.vendor, VendorExt::None);
263 }
264
265 #[test]
266 fn config_is_copyable() {
267 let cfg = ParserConfig::default();
268 let copy = cfg;
269 assert_eq!(cfg, copy);
270 }
271
272 #[test]
273 fn compat_mode_default_is_strict() {
274 assert_eq!(CompatMode::default(), CompatMode::Strict);
275 }
276
277 #[test]
278 fn vendor_ext_default_is_none() {
279 assert_eq!(VendorExt::default(), VendorExt::None);
280 }
281
282 #[test]
283 fn config_can_be_customized_field_by_field() {
284 let cfg = ParserConfig {
285 version: IdlVersion::V4_0,
286 compat: CompatMode::Pragmatic,
287 vendor: VendorExt::Rti,
288 profile: Profile::Full,
289 features: IdlFeatures::corba_full(),
290 };
291 assert_eq!(cfg.version, IdlVersion::V4_0);
292 assert_eq!(cfg.compat, CompatMode::Pragmatic);
293 assert_eq!(cfg.vendor, VendorExt::Rti);
294 assert_eq!(cfg.profile, Profile::Full);
295 assert!(cfg.features.corba_components);
296 }
297
298 #[test]
299 fn opensplice_legacy_constructor_enables_corba_and_pragmas() {
300 let cfg = ParserConfig::opensplice_legacy();
301 assert!(cfg.features.vendor_opensplice_legacy);
302 assert!(cfg.features.corba_value_types_full);
303 assert!(cfg.features.corba_components);
304 assert_eq!(cfg.vendor, VendorExt::OpenSplice);
305 }
306
307 #[test]
308 fn rti_connext_constructor() {
309 let cfg = ParserConfig::rti_connext();
310 assert!(cfg.features.vendor_rti);
311 assert_eq!(cfg.vendor, VendorExt::Rti);
312 assert!(!cfg.features.corba_components);
313 }
314
315 #[test]
316 fn cyclonedds_constructor() {
317 let cfg = ParserConfig::cyclonedds();
318 assert!(cfg.features.vendor_cyclonedds);
319 assert!(!cfg.features.vendor_rti);
320 }
321
322 #[test]
323 fn fastdds_constructor() {
324 let cfg = ParserConfig::fastdds();
325 assert!(cfg.features.vendor_fastdds);
326 assert!(!cfg.features.vendor_opensplice);
327 }
328
329 #[test]
334 fn default_profile_is_dds_extensible() {
335 assert_eq!(ParserConfig::default().profile, Profile::DdsExtensible);
336 assert_eq!(Profile::default(), Profile::DdsExtensible);
337 }
338
339 #[test]
340 fn plain_dds_profile_constructor() {
341 let cfg = ParserConfig::plain_dds_4_2();
342 assert_eq!(cfg.profile, Profile::DdsBasic);
343 assert_eq!(cfg.compat, CompatMode::Strict);
344 assert_eq!(cfg.vendor, VendorExt::None);
345 }
346
347 #[test]
348 fn full_profile_constructor() {
349 let cfg = ParserConfig::full_4_2();
350 assert_eq!(cfg.profile, Profile::Full);
351 }
352
353 #[test]
354 fn strict_pragmatic_use_extensible_profile() {
355 assert_eq!(ParserConfig::strict_4_2().profile, Profile::DdsExtensible);
358 assert_eq!(
359 ParserConfig::pragmatic_4_2().profile,
360 Profile::DdsExtensible
361 );
362 }
363}