2024-01-23 12:53:15 +00:00
|
|
|
//! Macro-based [`crate::GeglOperation`] struct generator.
|
|
|
|
|
|
|
|
/// A macro to generate a struct that implements [`crate::GeglOperation`].
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gegl_operation {
|
|
|
|
(
|
|
|
|
struct_name: $struct_name:ident,
|
|
|
|
gegl_name: $gegl_name:expr,
|
|
|
|
append_crop: $append_crop:expr,
|
2024-01-27 17:04:01 +00:00
|
|
|
values: (
|
|
|
|
$(
|
|
|
|
$(#[$key_meta:meta])*
|
|
|
|
$key:ident: $key_type:ty, $key_default:expr
|
|
|
|
),*,
|
|
|
|
),
|
2024-01-23 12:53:15 +00:00
|
|
|
) => {
|
|
|
|
#[doc = concat!(" The `gegl:", $gegl_name, "` operation.")]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct $struct_name {
|
|
|
|
$(
|
2024-01-27 17:04:01 +00:00
|
|
|
$(#[$key_meta])*
|
2024-01-23 12:53:15 +00:00
|
|
|
pub $key: $key_type,
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
2024-01-28 13:04:55 +00:00
|
|
|
paste::paste! {
|
|
|
|
impl $struct_name {
|
|
|
|
$(
|
|
|
|
#[doc = concat!(" Builder function to assign `", stringify!($key), "`.")]
|
|
|
|
pub fn [<with_ $key>](mut self, value: $key_type) -> $struct_name {
|
|
|
|
self.$key = value;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
|
|
|
|
/// Get this operation inside a [`Box`].
|
|
|
|
pub fn boxed(self) -> Box<$struct_name> {
|
|
|
|
Box::new(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-23 12:53:15 +00:00
|
|
|
impl Default for $struct_name {
|
|
|
|
fn default() -> $struct_name {
|
|
|
|
$struct_name {
|
|
|
|
$($key: $key_default,)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl $crate::GeglOperation for $struct_name {
|
|
|
|
fn append_crop_operation(&self) -> bool {
|
|
|
|
$append_crop
|
|
|
|
}
|
|
|
|
|
2024-01-25 18:57:44 +00:00
|
|
|
fn default_values(&self) -> $crate::GeglData {
|
|
|
|
Self::default().values()
|
|
|
|
}
|
|
|
|
|
2024-01-23 12:53:15 +00:00
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
concat!("gegl:", $gegl_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn values(&self) -> $crate::GeglData {
|
|
|
|
$crate::indexmap! {
|
|
|
|
$(stringify!($key) => self.$key.to_string(),)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-01-23 17:06:24 +00:00
|
|
|
|
|
|
|
/// A macro to generate an enum that implements [`std::fmt::Display`].
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! gegl_enum {
|
|
|
|
(
|
2024-01-27 17:32:58 +00:00
|
|
|
$(#[$enum_meta:meta])*
|
2024-01-23 17:06:24 +00:00
|
|
|
$enum_name:ident,
|
2024-01-24 11:50:38 +00:00
|
|
|
$($key:ident => $value:expr),*,
|
2024-01-23 17:06:24 +00:00
|
|
|
) => {
|
2024-01-27 17:32:58 +00:00
|
|
|
$(#[$enum_meta])*
|
2024-01-23 17:06:24 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum $enum_name {
|
|
|
|
$(
|
2024-01-27 17:32:58 +00:00
|
|
|
#[doc = concat!("The [`", stringify!($enum_name), "`] `", $value, "`." )]
|
2024-01-23 17:06:24 +00:00
|
|
|
$key,
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for $enum_name {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let display = match self {
|
|
|
|
$($enum_name::$key => $value,)*
|
|
|
|
};
|
|
|
|
|
|
|
|
write!(f, "{display}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|