| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use crate::{ |
| 4 | enums::{EnumValues, FlagsValues}, |
| 5 | prelude::*, |
| 6 | subclass::prelude::*, |
| 7 | InterfaceInfo, TypeFlags, TypeInfo, TypeModule, TypePlugin, |
| 8 | }; |
| 9 | |
| 10 | mod sealed { |
| 11 | pub trait Sealed {} |
| 12 | impl<T: super::IsA<super::TypePlugin>> Sealed for T {} |
| 13 | } |
| 14 | |
| 15 | pub trait DynamicObjectRegisterExt: AsRef<TypePlugin> + sealed::Sealed + 'static { |
| 16 | fn add_dynamic_interface( |
| 17 | &self, |
| 18 | instance_type: crate::types::Type, |
| 19 | interface_type: crate::types::Type, |
| 20 | interface_info: &InterfaceInfo, |
| 21 | ); |
| 22 | |
| 23 | fn register_dynamic_enum( |
| 24 | &self, |
| 25 | name: &str, |
| 26 | const_static_values: &'static EnumValues, |
| 27 | ) -> crate::types::Type; |
| 28 | |
| 29 | fn register_dynamic_flags( |
| 30 | &self, |
| 31 | name: &str, |
| 32 | const_static_values: &'static FlagsValues, |
| 33 | ) -> crate::types::Type; |
| 34 | |
| 35 | fn register_dynamic_type( |
| 36 | &self, |
| 37 | parent_type: crate::types::Type, |
| 38 | type_name: &str, |
| 39 | type_info: &TypeInfo, |
| 40 | flags: TypeFlags, |
| 41 | ) -> crate::types::Type; |
| 42 | } |
| 43 | |
| 44 | impl<O: IsA<TypePlugin> + ObjectSubclassIsExt> DynamicObjectRegisterExt for O |
| 45 | where |
| 46 | O::Subclass: TypePluginRegisterImpl, |
| 47 | { |
| 48 | fn add_dynamic_interface( |
| 49 | &self, |
| 50 | instance_type: crate::types::Type, |
| 51 | interface_type: crate::types::Type, |
| 52 | interface_info: &InterfaceInfo, |
| 53 | ) { |
| 54 | self.imp() |
| 55 | .add_dynamic_interface(instance_type, interface_type, interface_info); |
| 56 | } |
| 57 | |
| 58 | fn register_dynamic_enum( |
| 59 | &self, |
| 60 | name: &str, |
| 61 | const_static_values: &'static EnumValues, |
| 62 | ) -> crate::types::Type { |
| 63 | self.imp().register_dynamic_enum(name, const_static_values) |
| 64 | } |
| 65 | |
| 66 | fn register_dynamic_flags( |
| 67 | &self, |
| 68 | name: &str, |
| 69 | const_static_values: &'static FlagsValues, |
| 70 | ) -> crate::types::Type { |
| 71 | self.imp().register_dynamic_flags(name, const_static_values) |
| 72 | } |
| 73 | |
| 74 | fn register_dynamic_type( |
| 75 | &self, |
| 76 | parent_type: crate::types::Type, |
| 77 | type_name: &str, |
| 78 | type_info: &TypeInfo, |
| 79 | flags: TypeFlags, |
| 80 | ) -> crate::types::Type { |
| 81 | self.imp() |
| 82 | .register_dynamic_type(parent_type, type_name, type_info, flags) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl DynamicObjectRegisterExt for TypeModule { |
| 87 | fn add_dynamic_interface( |
| 88 | &self, |
| 89 | instance_type: crate::types::Type, |
| 90 | interface_type: crate::types::Type, |
| 91 | interface_info: &InterfaceInfo, |
| 92 | ) { |
| 93 | <Self as TypeModuleExt>::add_interface(self, instance_type, interface_type, interface_info); |
| 94 | } |
| 95 | |
| 96 | fn register_dynamic_enum( |
| 97 | &self, |
| 98 | name: &str, |
| 99 | const_static_values: &'static EnumValues, |
| 100 | ) -> crate::types::Type { |
| 101 | <Self as TypeModuleExt>::register_enum(self, name, const_static_values) |
| 102 | } |
| 103 | |
| 104 | fn register_dynamic_flags( |
| 105 | &self, |
| 106 | name: &str, |
| 107 | const_static_values: &'static FlagsValues, |
| 108 | ) -> crate::types::Type { |
| 109 | <Self as TypeModuleExt>::register_flags(self, name, const_static_values) |
| 110 | } |
| 111 | |
| 112 | fn register_dynamic_type( |
| 113 | &self, |
| 114 | parent_type: crate::types::Type, |
| 115 | type_name: &str, |
| 116 | type_info: &TypeInfo, |
| 117 | flags: TypeFlags, |
| 118 | ) -> crate::types::Type { |
| 119 | <Self as TypeModuleExt>::register_type(self, parent_type, type_name, type_info, flags) |
| 120 | } |
| 121 | } |
| 122 | |