1use crate::{ColorSpace, Config, ConstConfig, OcioError, Result};
3use std::{
4 ffi::{c_char, c_void, CStr, CString},
5 ptr::NonNull,
6};
7
8unsafe fn text<'a>(value: *const c_char) -> &'a CStr {
9 if value.is_null() {
10 c""
11 } else {
12 unsafe { CStr::from_ptr(value) }
13 }
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18#[repr(i32)]
19pub enum MergeStrategy {
20 PreferInput = 0,
21 PreferBase = 1,
22 InputOnly = 2,
23 BaseOnly = 3,
24 Remove = 4,
25 Unspecified = 5,
26}
27impl MergeStrategy {
28 fn from_native(value: i32) -> Result<Self> {
29 match value {
30 0 => Ok(Self::PreferInput),
31 1 => Ok(Self::PreferBase),
32 2 => Ok(Self::InputOnly),
33 3 => Ok(Self::BaseOnly),
34 4 => Ok(Self::Remove),
35 5 => Ok(Self::Unspecified),
36 _ => Err(OcioError::Ocio(format!("Unknown merge strategy: {value}"))),
37 }
38 }
39}
40
41pub struct ConfigMergingParameters {
43 handle: NonNull<c_void>,
44}
45impl ConfigMergingParameters {
46 pub fn serialize(&self) -> Result<String> {
48 crate::app_helpers::serialize_app_helper(self.handle, 5)
49 }
50 pub fn create() -> Result<Self> {
52 crate::clear_last_error();
53 let value = unsafe { ocio_sys::ocio_config_merging_parameters_create() };
54 Ok(Self {
55 handle: crate::handle_result(value)?,
56 })
57 }
58
59 pub fn create_editable_copy(&self) -> Result<Self> {
65 crate::clear_last_error();
66 let value = unsafe {
67 ocio_sys::ocio_config_merging_parameters_create_editable_copy(self.handle.as_ptr())
68 };
69 Ok(Self {
70 handle: crate::handle_result(value)?,
71 })
72 }
73
74 pub fn base_config_name(&self) -> Result<&CStr> {
76 crate::clear_last_error();
77 let value = unsafe {
78 ocio_sys::ocio_config_merging_parameters_get_base_config_name(self.handle.as_ptr())
79 };
80 crate::ocio_call_status()?;
81 Ok(unsafe { text(value) })
82 }
83
84 pub fn set_base_config_name(&mut self, value: &CStr) -> Result<()> {
86 crate::clear_last_error();
87 unsafe {
88 ocio_sys::ocio_config_merging_parameters_set_base_config_name(
89 self.handle.as_ptr(),
90 value.as_ptr(),
91 )
92 };
93 crate::ocio_call_status()
94 }
95
96 pub fn input_config_name(&self) -> Result<&CStr> {
98 crate::clear_last_error();
99 let value = unsafe {
100 ocio_sys::ocio_config_merging_parameters_get_input_config_name(self.handle.as_ptr())
101 };
102 crate::ocio_call_status()?;
103 Ok(unsafe { text(value) })
104 }
105
106 pub fn set_input_config_name(&mut self, value: &CStr) -> Result<()> {
108 crate::clear_last_error();
109 unsafe {
110 ocio_sys::ocio_config_merging_parameters_set_input_config_name(
111 self.handle.as_ptr(),
112 value.as_ptr(),
113 )
114 };
115 crate::ocio_call_status()
116 }
117
118 pub fn output_name(&self) -> Result<&CStr> {
120 crate::clear_last_error();
121 let value = unsafe {
122 ocio_sys::ocio_config_merging_parameters_get_output_name(self.handle.as_ptr())
123 };
124 crate::ocio_call_status()?;
125 Ok(unsafe { text(value) })
126 }
127
128 pub fn set_output_name(&mut self, value: &CStr) -> Result<()> {
130 crate::clear_last_error();
131 unsafe {
132 ocio_sys::ocio_config_merging_parameters_set_output_name(
133 self.handle.as_ptr(),
134 value.as_ptr(),
135 )
136 };
137 crate::ocio_call_status()
138 }
139
140 pub fn input_family_prefix(&self) -> Result<&CStr> {
142 crate::clear_last_error();
143 let value = unsafe {
144 ocio_sys::ocio_config_merging_parameters_get_input_family_prefix(self.handle.as_ptr())
145 };
146 crate::ocio_call_status()?;
147 Ok(unsafe { text(value) })
148 }
149
150 pub fn set_input_family_prefix(&mut self, value: &CStr) -> Result<()> {
152 crate::clear_last_error();
153 unsafe {
154 ocio_sys::ocio_config_merging_parameters_set_input_family_prefix(
155 self.handle.as_ptr(),
156 value.as_ptr(),
157 )
158 };
159 crate::ocio_call_status()
160 }
161
162 pub fn base_family_prefix(&self) -> Result<&CStr> {
164 crate::clear_last_error();
165 let value = unsafe {
166 ocio_sys::ocio_config_merging_parameters_get_base_family_prefix(self.handle.as_ptr())
167 };
168 crate::ocio_call_status()?;
169 Ok(unsafe { text(value) })
170 }
171
172 pub fn set_base_family_prefix(&mut self, value: &CStr) -> Result<()> {
174 crate::clear_last_error();
175 unsafe {
176 ocio_sys::ocio_config_merging_parameters_set_base_family_prefix(
177 self.handle.as_ptr(),
178 value.as_ptr(),
179 )
180 };
181 crate::ocio_call_status()
182 }
183
184 pub fn name(&self) -> Result<&CStr> {
186 crate::clear_last_error();
187 let value =
188 unsafe { ocio_sys::ocio_config_merging_parameters_get_name(self.handle.as_ptr()) };
189 crate::ocio_call_status()?;
190 Ok(unsafe { text(value) })
191 }
192
193 pub fn set_name(&mut self, value: &CStr) -> Result<()> {
195 crate::clear_last_error();
196 unsafe {
197 ocio_sys::ocio_config_merging_parameters_set_name(self.handle.as_ptr(), value.as_ptr())
198 };
199 crate::ocio_call_status()
200 }
201
202 pub fn description(&self) -> Result<&CStr> {
204 crate::clear_last_error();
205 let value = unsafe {
206 ocio_sys::ocio_config_merging_parameters_get_description(self.handle.as_ptr())
207 };
208 crate::ocio_call_status()?;
209 Ok(unsafe { text(value) })
210 }
211
212 pub fn set_description(&mut self, value: &CStr) -> Result<()> {
214 crate::clear_last_error();
215 unsafe {
216 ocio_sys::ocio_config_merging_parameters_set_description(
217 self.handle.as_ptr(),
218 value.as_ptr(),
219 )
220 };
221 crate::ocio_call_status()
222 }
223
224 pub fn search_path(&self) -> Result<CString> {
226 crate::clear_last_error();
227 let value = unsafe {
228 ocio_sys::ocio_config_merging_parameters_get_search_path(self.handle.as_ptr())
229 };
230 crate::ocio_call_status()?;
231 Ok(unsafe { text(value) }.to_owned())
232 }
233
234 pub fn set_search_path(&mut self, value: &CStr) -> Result<()> {
236 crate::clear_last_error();
237 unsafe {
238 ocio_sys::ocio_config_merging_parameters_set_search_path(
239 self.handle.as_ptr(),
240 value.as_ptr(),
241 )
242 };
243 crate::ocio_call_status()
244 }
245
246 pub fn active_displays(&self) -> Result<CString> {
248 crate::clear_last_error();
249 let value = unsafe {
250 ocio_sys::ocio_config_merging_parameters_get_active_displays(self.handle.as_ptr())
251 };
252 crate::ocio_call_status()?;
253 Ok(unsafe { text(value) }.to_owned())
254 }
255
256 pub fn set_active_displays(&mut self, value: &CStr) -> Result<()> {
258 crate::clear_last_error();
259 unsafe {
260 ocio_sys::ocio_config_merging_parameters_set_active_displays(
261 self.handle.as_ptr(),
262 value.as_ptr(),
263 )
264 };
265 crate::ocio_call_status()
266 }
267
268 pub fn active_views(&self) -> Result<CString> {
270 crate::clear_last_error();
271 let value = unsafe {
272 ocio_sys::ocio_config_merging_parameters_get_active_views(self.handle.as_ptr())
273 };
274 crate::ocio_call_status()?;
275 Ok(unsafe { text(value) }.to_owned())
276 }
277
278 pub fn set_active_views(&mut self, value: &CStr) -> Result<()> {
280 crate::clear_last_error();
281 unsafe {
282 ocio_sys::ocio_config_merging_parameters_set_active_views(
283 self.handle.as_ptr(),
284 value.as_ptr(),
285 )
286 };
287 crate::ocio_call_status()
288 }
289
290 pub fn inactive_color_spaces(&self) -> Result<CString> {
292 crate::clear_last_error();
293 let value = unsafe {
294 ocio_sys::ocio_config_merging_parameters_get_inactive_color_spaces(self.handle.as_ptr())
295 };
296 crate::ocio_call_status()?;
297 Ok(unsafe { text(value) }.to_owned())
298 }
299
300 pub fn set_inactive_color_spaces(&mut self, value: &CStr) -> Result<()> {
302 crate::clear_last_error();
303 unsafe {
304 ocio_sys::ocio_config_merging_parameters_set_inactive_color_spaces(
305 self.handle.as_ptr(),
306 value.as_ptr(),
307 )
308 };
309 crate::ocio_call_status()
310 }
311
312 pub fn is_input_first(&self) -> Result<bool> {
314 crate::clear_last_error();
315 let value = unsafe {
316 ocio_sys::ocio_config_merging_parameters_is_input_first(self.handle.as_ptr())
317 };
318 crate::ocio_call_status()?;
319 Ok(value)
320 }
321
322 pub fn set_input_first(&mut self, value: bool) -> Result<()> {
324 crate::clear_last_error();
325 unsafe {
326 ocio_sys::ocio_config_merging_parameters_set_input_first(self.handle.as_ptr(), value)
327 };
328 crate::ocio_call_status()
329 }
330
331 pub fn is_error_on_conflict(&self) -> Result<bool> {
333 crate::clear_last_error();
334 let value = unsafe {
335 ocio_sys::ocio_config_merging_parameters_is_error_on_conflict(self.handle.as_ptr())
336 };
337 crate::ocio_call_status()?;
338 Ok(value)
339 }
340
341 pub fn set_error_on_conflict(&mut self, value: bool) -> Result<()> {
343 crate::clear_last_error();
344 unsafe {
345 ocio_sys::ocio_config_merging_parameters_set_error_on_conflict(
346 self.handle.as_ptr(),
347 value,
348 )
349 };
350 crate::ocio_call_status()
351 }
352
353 pub fn is_avoid_duplicates(&self) -> Result<bool> {
355 crate::clear_last_error();
356 let value = unsafe {
357 ocio_sys::ocio_config_merging_parameters_is_avoid_duplicates(self.handle.as_ptr())
358 };
359 crate::ocio_call_status()?;
360 Ok(value)
361 }
362
363 pub fn set_avoid_duplicates(&mut self, value: bool) -> Result<()> {
365 crate::clear_last_error();
366 unsafe {
367 ocio_sys::ocio_config_merging_parameters_set_avoid_duplicates(
368 self.handle.as_ptr(),
369 value,
370 )
371 };
372 crate::ocio_call_status()
373 }
374
375 pub fn is_adjust_input_reference_space(&self) -> Result<bool> {
377 crate::clear_last_error();
378 let value = unsafe {
379 ocio_sys::ocio_config_merging_parameters_is_adjust_input_reference_space(
380 self.handle.as_ptr(),
381 )
382 };
383 crate::ocio_call_status()?;
384 Ok(value)
385 }
386
387 pub fn set_adjust_input_reference_space(&mut self, value: bool) -> Result<()> {
389 crate::clear_last_error();
390 unsafe {
391 ocio_sys::ocio_config_merging_parameters_set_adjust_input_reference_space(
392 self.handle.as_ptr(),
393 value,
394 )
395 };
396 crate::ocio_call_status()
397 }
398
399 pub fn default_strategy(&self) -> Result<MergeStrategy> {
401 crate::clear_last_error();
402 let value = unsafe {
403 ocio_sys::ocio_config_merging_parameters_get_default_strategy(self.handle.as_ptr())
404 };
405 crate::ocio_call_status()?;
406 MergeStrategy::from_native(value)
407 }
408
409 pub fn set_default_strategy(&mut self, value: MergeStrategy) -> Result<()> {
411 crate::clear_last_error();
412 unsafe {
413 ocio_sys::ocio_config_merging_parameters_set_default_strategy(
414 self.handle.as_ptr(),
415 value as i32,
416 )
417 };
418 crate::ocio_call_status()
419 }
420
421 pub fn roles(&self) -> Result<MergeStrategy> {
423 crate::clear_last_error();
424 let value =
425 unsafe { ocio_sys::ocio_config_merging_parameters_get_roles(self.handle.as_ptr()) };
426 crate::ocio_call_status()?;
427 MergeStrategy::from_native(value)
428 }
429
430 pub fn set_roles(&mut self, value: MergeStrategy) -> Result<()> {
432 crate::clear_last_error();
433 unsafe {
434 ocio_sys::ocio_config_merging_parameters_set_roles(self.handle.as_ptr(), value as i32)
435 };
436 crate::ocio_call_status()
437 }
438
439 pub fn file_rules(&self) -> Result<MergeStrategy> {
441 crate::clear_last_error();
442 let value = unsafe {
443 ocio_sys::ocio_config_merging_parameters_get_file_rules(self.handle.as_ptr())
444 };
445 crate::ocio_call_status()?;
446 MergeStrategy::from_native(value)
447 }
448
449 pub fn set_file_rules(&mut self, value: MergeStrategy) -> Result<()> {
451 crate::clear_last_error();
452 unsafe {
453 ocio_sys::ocio_config_merging_parameters_set_file_rules(
454 self.handle.as_ptr(),
455 value as i32,
456 )
457 };
458 crate::ocio_call_status()
459 }
460
461 pub fn display_views(&self) -> Result<MergeStrategy> {
463 crate::clear_last_error();
464 let value = unsafe {
465 ocio_sys::ocio_config_merging_parameters_get_display_views(self.handle.as_ptr())
466 };
467 crate::ocio_call_status()?;
468 MergeStrategy::from_native(value)
469 }
470
471 pub fn set_display_views(&mut self, value: MergeStrategy) -> Result<()> {
473 crate::clear_last_error();
474 unsafe {
475 ocio_sys::ocio_config_merging_parameters_set_display_views(
476 self.handle.as_ptr(),
477 value as i32,
478 )
479 };
480 crate::ocio_call_status()
481 }
482
483 pub fn view_transforms(&self) -> Result<MergeStrategy> {
485 crate::clear_last_error();
486 let value = unsafe {
487 ocio_sys::ocio_config_merging_parameters_get_view_transforms(self.handle.as_ptr())
488 };
489 crate::ocio_call_status()?;
490 MergeStrategy::from_native(value)
491 }
492
493 pub fn set_view_transforms(&mut self, value: MergeStrategy) -> Result<()> {
495 crate::clear_last_error();
496 unsafe {
497 ocio_sys::ocio_config_merging_parameters_set_view_transforms(
498 self.handle.as_ptr(),
499 value as i32,
500 )
501 };
502 crate::ocio_call_status()
503 }
504
505 pub fn looks(&self) -> Result<MergeStrategy> {
507 crate::clear_last_error();
508 let value =
509 unsafe { ocio_sys::ocio_config_merging_parameters_get_looks(self.handle.as_ptr()) };
510 crate::ocio_call_status()?;
511 MergeStrategy::from_native(value)
512 }
513
514 pub fn set_looks(&mut self, value: MergeStrategy) -> Result<()> {
516 crate::clear_last_error();
517 unsafe {
518 ocio_sys::ocio_config_merging_parameters_set_looks(self.handle.as_ptr(), value as i32)
519 };
520 crate::ocio_call_status()
521 }
522
523 pub fn color_spaces(&self) -> Result<MergeStrategy> {
525 crate::clear_last_error();
526 let value = unsafe {
527 ocio_sys::ocio_config_merging_parameters_get_color_spaces(self.handle.as_ptr())
528 };
529 crate::ocio_call_status()?;
530 MergeStrategy::from_native(value)
531 }
532
533 pub fn set_color_spaces(&mut self, value: MergeStrategy) -> Result<()> {
535 crate::clear_last_error();
536 unsafe {
537 ocio_sys::ocio_config_merging_parameters_set_color_spaces(
538 self.handle.as_ptr(),
539 value as i32,
540 )
541 };
542 crate::ocio_call_status()
543 }
544
545 pub fn named_transforms(&self) -> Result<MergeStrategy> {
547 crate::clear_last_error();
548 let value = unsafe {
549 ocio_sys::ocio_config_merging_parameters_get_named_transforms(self.handle.as_ptr())
550 };
551 crate::ocio_call_status()?;
552 MergeStrategy::from_native(value)
553 }
554
555 pub fn set_named_transforms(&mut self, value: MergeStrategy) -> Result<()> {
557 crate::clear_last_error();
558 unsafe {
559 ocio_sys::ocio_config_merging_parameters_set_named_transforms(
560 self.handle.as_ptr(),
561 value as i32,
562 )
563 };
564 crate::ocio_call_status()
565 }
566
567 pub fn add_search_path(&mut self, value: &CStr) -> Result<()> {
569 crate::clear_last_error();
570 unsafe {
571 ocio_sys::ocio_config_merging_parameters_add_search_path(
572 self.handle.as_ptr(),
573 value.as_ptr(),
574 )
575 };
576 crate::ocio_call_status()
577 }
578
579 pub fn add_environment_var(&mut self, name: &CStr, value: &CStr) -> Result<()> {
581 crate::clear_last_error();
582 unsafe {
583 ocio_sys::ocio_config_merging_parameters_add_environment_var(
584 self.handle.as_ptr(),
585 name.as_ptr(),
586 value.as_ptr(),
587 )
588 };
589 crate::ocio_call_status()
590 }
591
592 pub fn num_environment_vars(&self) -> Result<i32> {
594 crate::clear_last_error();
595 let value = unsafe {
596 ocio_sys::ocio_config_merging_parameters_get_num_environment_vars(self.handle.as_ptr())
597 };
598 crate::ocio_call_status()?;
599 Ok(value)
600 }
601
602 pub fn environment_var(&self, index: i32) -> Result<CString> {
604 crate::clear_last_error();
605 let value = unsafe {
606 ocio_sys::ocio_config_merging_parameters_get_environment_var(
607 self.handle.as_ptr(),
608 index,
609 )
610 };
611 crate::ocio_call_status()?;
612 Ok(unsafe { text(value) }.to_owned())
613 }
614
615 pub fn environment_var_value(&self, index: i32) -> Result<CString> {
617 crate::clear_last_error();
618 let value = unsafe {
619 ocio_sys::ocio_config_merging_parameters_get_environment_var_value(
620 self.handle.as_ptr(),
621 index,
622 )
623 };
624 crate::ocio_call_status()?;
625 Ok(unsafe { text(value) }.to_owned())
626 }
627
628 pub fn merge_configs(&self, base: &Config, input: &Config) -> Result<Config> {
630 crate::clear_last_error();
631 let value = unsafe {
632 ocio_sys::ocio_config_merging_parameters_merge_configs(
633 self.handle.as_ptr(),
634 base.handle.as_ptr(),
635 input.handle.as_ptr(),
636 )
637 };
638 Ok(Config {
639 handle: crate::handle_result(value)?,
640 })
641 }
642
643 pub fn merge_configs_ref<'a, 'b>(
646 &self,
647 base: impl Into<crate::ConfigRef<'a>>,
648 input: impl Into<crate::ConfigRef<'b>>,
649 ) -> Result<Config> {
650 let base = base.into();
651 let input = input.into();
652 let base_copy = base.isolated_copy()?;
653 let input_copy = input.isolated_copy()?;
654 let (base, base_const) = base_copy
655 .as_ref()
656 .map_or(base, crate::ConfigRef::Editable)
657 .raw();
658 let (input, input_const) = input_copy
659 .as_ref()
660 .map_or(input, crate::ConfigRef::Editable)
661 .raw();
662 crate::clear_last_error();
663 let value = unsafe {
664 ocio_sys::ocio_config_merging_parameters_merge_config_refs(
665 self.handle.as_ptr(),
666 base,
667 base_const,
668 input,
669 input_const,
670 )
671 };
672 Ok(Config {
673 handle: crate::handle_result(value)?,
674 })
675 }
676
677 pub fn merge_color_space(&self, base: &Config, input: &ColorSpace) -> Result<Config> {
679 crate::clear_last_error();
680 let value = unsafe {
681 ocio_sys::ocio_config_merging_parameters_merge_color_space(
682 self.handle.as_ptr(),
683 base.handle.as_ptr(),
684 input.handle.as_ptr(),
685 )
686 };
687 Ok(Config {
688 handle: crate::handle_result(value)?,
689 })
690 }
691
692 pub fn merge_color_space_ref<'a, 'b>(
696 &self,
697 base: impl Into<crate::ConfigRef<'a>>,
698 input: impl Into<crate::ColorSpaceRef<'b>>,
699 ) -> Result<Config> {
700 let base = base.into();
701 let base_copy = base.isolated_copy()?;
702 let (base, base_const) = base_copy
703 .as_ref()
704 .map_or(base, crate::ConfigRef::Editable)
705 .raw();
706 let (input, input_const) = input.into().raw();
707 crate::clear_last_error();
708 let value = unsafe {
709 ocio_sys::ocio_config_merging_parameters_merge_color_space_refs(
710 self.handle.as_ptr(),
711 base,
712 base_const,
713 input,
714 input_const,
715 )
716 };
717 Ok(Config {
718 handle: crate::handle_result(value)?,
719 })
720 }
721}
722impl Drop for ConfigMergingParameters {
723 fn drop(&mut self) {
724 unsafe { ocio_sys::ocio_config_merging_parameters_destroy(self.handle.as_ptr()) }
725 }
726}
727
728pub struct ConfigMerger {
730 handle: NonNull<c_void>,
731}
732impl ConfigMerger {
733 pub fn create() -> Result<Self> {
735 crate::clear_last_error();
736 let value = unsafe { ocio_sys::ocio_config_merger_create() };
737 crate::ocio_call_status()?;
738 Ok(Self {
739 handle: crate::handle_result(value)?,
740 })
741 }
742
743 pub fn from_file(path: &CStr) -> Result<Self> {
745 crate::clear_last_error();
746 let value = unsafe { ocio_sys::ocio_config_merger_from_file(path.as_ptr()) };
747 crate::ocio_call_status()?;
748 Ok(Self {
749 handle: crate::handle_result(value)?,
750 })
751 }
752
753 pub fn create_editable_copy(&self) -> Result<Self> {
755 crate::clear_last_error();
756 let value =
757 unsafe { ocio_sys::ocio_config_merger_create_editable_copy(self.handle.as_ptr()) };
758 crate::ocio_call_status()?;
759 Ok(Self {
760 handle: crate::handle_result(value)?,
761 })
762 }
763
764 pub fn set_search_path(&mut self, v: &CStr) -> Result<()> {
766 crate::clear_last_error();
767 unsafe { ocio_sys::ocio_config_merger_set_search_path(self.handle.as_ptr(), v.as_ptr()) };
768 crate::ocio_call_status()
769 }
770
771 pub fn add_search_path(&mut self, v: &CStr) -> Result<()> {
773 crate::clear_last_error();
774 unsafe { ocio_sys::ocio_config_merger_add_search_path(self.handle.as_ptr(), v.as_ptr()) };
775 crate::ocio_call_status()
776 }
777
778 pub fn num_search_paths(&self) -> Result<i32> {
780 crate::clear_last_error();
781 let value = unsafe { ocio_sys::ocio_config_merger_num_search_paths(self.handle.as_ptr()) };
782 crate::ocio_call_status()?;
783 Ok(value)
784 }
785
786 pub fn search_path(&self, index: i32) -> Result<&CStr> {
788 crate::clear_last_error();
789 let value =
790 unsafe { ocio_sys::ocio_config_merger_search_path(self.handle.as_ptr(), index) };
791 crate::ocio_call_status()?;
792 Ok(unsafe { text(value) })
793 }
794
795 pub fn set_working_dir(&mut self, v: &CStr) -> Result<()> {
797 crate::clear_last_error();
798 unsafe { ocio_sys::ocio_config_merger_set_working_dir(self.handle.as_ptr(), v.as_ptr()) };
799 crate::ocio_call_status()
800 }
801
802 pub fn working_dir(&self) -> Result<&CStr> {
804 crate::clear_last_error();
805 let value = unsafe { ocio_sys::ocio_config_merger_working_dir(self.handle.as_ptr()) };
806 crate::ocio_call_status()?;
807 Ok(unsafe { text(value) })
808 }
809
810 pub fn num_params(&self) -> Result<i32> {
812 crate::clear_last_error();
813 let value = unsafe { ocio_sys::ocio_config_merger_num_params(self.handle.as_ptr()) };
814 crate::ocio_call_status()?;
815 Ok(value)
816 }
817
818 pub fn params(&self, index: i32) -> Result<Option<ConfigMergingParameters>> {
822 crate::clear_last_error();
823 let value = unsafe { ocio_sys::ocio_config_merger_params(self.handle.as_ptr(), index) };
824 crate::ocio_call_status()?;
825 Ok(NonNull::new(value).map(|handle| ConfigMergingParameters { handle }))
826 }
827
828 pub fn add_params(&mut self, params: &ConfigMergingParameters) -> Result<()> {
831 crate::clear_last_error();
832 unsafe {
833 ocio_sys::ocio_config_merger_add_params(self.handle.as_ptr(), params.handle.as_ptr())
834 };
835 crate::ocio_call_status()
836 }
837
838 pub fn merge_configs(&self) -> Result<Self> {
840 crate::clear_last_error();
841 let value = unsafe { ocio_sys::ocio_config_merger_merge_configs(self.handle.as_ptr()) };
842 crate::ocio_call_status()?;
843 Ok(Self {
844 handle: crate::handle_result(value)?,
845 })
846 }
847
848 pub fn merge_configs_shared(&self) -> Result<ConstConfigMerger> {
851 crate::clear_last_error();
852 let value =
853 unsafe { ocio_sys::ocio_config_merger_merge_configs_shared(self.handle.as_ptr()) };
854 Ok(ConstConfigMerger {
855 handle: crate::handle_result(value)?,
856 })
857 }
858
859 pub fn num_merged_configs(&self) -> Result<i32> {
861 crate::clear_last_error();
862 let value =
863 unsafe { ocio_sys::ocio_config_merger_num_merged_configs(self.handle.as_ptr()) };
864 crate::ocio_call_status()?;
865 Ok(value)
866 }
867
868 pub fn merged_config(&self, index: i32) -> Result<Option<Config>> {
871 crate::clear_last_error();
872 let value =
873 unsafe { ocio_sys::ocio_config_merger_merged_config(self.handle.as_ptr(), index) };
874 crate::ocio_call_status()?;
875 Ok(NonNull::new(value).map(|handle| Config { handle }))
876 }
877
878 pub fn merged_const_config(&self, index: i32) -> Result<Option<ConstConfig>> {
881 crate::clear_last_error();
882 let value = unsafe {
883 ocio_sys::ocio_config_merger_merged_const_config(self.handle.as_ptr(), index)
884 };
885 crate::ocio_call_status()?;
886 Ok(NonNull::new(value).map(|handle| ConstConfig { handle }))
887 }
888
889 pub fn serialize(&self) -> Result<String> {
891 crate::clear_last_error();
892 let value = unsafe { ocio_sys::ocio_config_merger_serialize(self.handle.as_ptr()) };
893 crate::ocio_call_status()?;
894 Ok(unsafe { text(value) }.to_string_lossy().into_owned())
895 }
896
897 pub fn set_version(&mut self, major: u32, minor: u32) -> Result<()> {
899 crate::clear_last_error();
900 unsafe { ocio_sys::ocio_config_merger_set_version(self.handle.as_ptr(), major, minor) };
901 crate::ocio_call_status()
902 }
903
904 pub fn major_version(&self) -> Result<u32> {
906 crate::clear_last_error();
907 let value = unsafe { ocio_sys::ocio_config_merger_major_version(self.handle.as_ptr()) };
908 crate::ocio_call_status()?;
909 Ok(value)
910 }
911
912 pub fn minor_version(&self) -> Result<u32> {
914 crate::clear_last_error();
915 let value = unsafe { ocio_sys::ocio_config_merger_minor_version(self.handle.as_ptr()) };
916 crate::ocio_call_status()?;
917 Ok(value)
918 }
919}
920impl Drop for ConfigMerger {
921 fn drop(&mut self) {
922 unsafe { ocio_sys::ocio_config_merger_destroy(self.handle.as_ptr()) }
923 }
924}
925
926pub struct ConstConfigMerger {
931 handle: NonNull<c_void>,
932}
933
934impl ConstConfigMerger {
935 fn number(&self, field: i32) -> Result<i64> {
936 crate::clear_last_error();
937 let value =
938 unsafe { ocio_sys::ocio_const_config_merger_number(self.handle.as_ptr(), field) };
939 crate::ocio_call_status()?;
940 Ok(value)
941 }
942
943 fn native_text(&self, field: i32, index: i32) -> Result<&CStr> {
944 crate::clear_last_error();
945 let value =
946 unsafe { ocio_sys::ocio_const_config_merger_text(self.handle.as_ptr(), field, index) };
947 crate::ocio_call_status()?;
948 Ok(unsafe { text(value) })
949 }
950
951 pub fn from_file(path: &CStr) -> Result<Self> {
953 crate::clear_last_error();
954 let value = unsafe { ocio_sys::ocio_const_config_merger_from_file(path.as_ptr()) };
955 Ok(Self {
956 handle: crate::handle_result(value)?,
957 })
958 }
959
960 pub fn merge_configs(&self) -> Result<Self> {
962 crate::clear_last_error();
963 let value =
964 unsafe { ocio_sys::ocio_const_config_merger_merge_configs(self.handle.as_ptr()) };
965 Ok(Self {
966 handle: crate::handle_result(value)?,
967 })
968 }
969
970 pub fn num_search_paths(&self) -> Result<i32> {
972 Ok(self.number(0)? as i32)
973 }
974
975 pub fn search_path(&self, index: i32) -> Result<&CStr> {
977 self.native_text(0, index)
978 }
979
980 pub fn working_dir(&self) -> Result<&CStr> {
982 self.native_text(1, 0)
983 }
984
985 pub fn num_params(&self) -> Result<i32> {
987 Ok(self.number(1)? as i32)
988 }
989
990 pub fn params(&self, index: i32) -> Result<Option<ConfigMergingParameters>> {
994 crate::clear_last_error();
995 let value = unsafe {
996 ocio_sys::ocio_const_config_merger_params(self.handle.as_ptr(), index, false)
997 };
998 crate::ocio_call_status()?;
999 Ok(NonNull::new(value).map(|handle| ConfigMergingParameters { handle }))
1000 }
1001
1002 pub fn serialize(&self) -> Result<String> {
1004 Ok(self.native_text(2, 0)?.to_string_lossy().into_owned())
1005 }
1006
1007 pub fn major_version(&self) -> Result<u32> {
1009 Ok(self.number(2)? as u32)
1010 }
1011
1012 pub fn minor_version(&self) -> Result<u32> {
1014 Ok(self.number(3)? as u32)
1015 }
1016
1017 pub fn num_merged_configs(&self) -> Result<i32> {
1019 crate::clear_last_error();
1020 let value =
1021 unsafe { ocio_sys::ocio_const_config_merger_num_merged_configs(self.handle.as_ptr()) };
1022 crate::ocio_call_status()?;
1023 Ok(value)
1024 }
1025
1026 pub fn merged_const_config(&self, index: i32) -> Result<Option<ConstConfig>> {
1028 crate::clear_last_error();
1029 let value = unsafe {
1030 ocio_sys::ocio_const_config_merger_merged_config(self.handle.as_ptr(), index)
1031 };
1032 crate::ocio_call_status()?;
1033 Ok(NonNull::new(value).map(|handle| ConstConfig { handle }))
1034 }
1035
1036 pub fn create_editable_copy(&self) -> Result<ConfigMerger> {
1038 crate::clear_last_error();
1039 let value =
1040 unsafe { ocio_sys::ocio_const_config_merger_editable_copy(self.handle.as_ptr()) };
1041 Ok(ConfigMerger {
1042 handle: crate::handle_result(value)?,
1043 })
1044 }
1045}
1046
1047impl Drop for ConstConfigMerger {
1048 fn drop(&mut self) {
1049 unsafe { ocio_sys::ocio_const_config_merger_destroy(self.handle.as_ptr()) }
1050 }
1051}