use std::fmt::Debug;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct XmpValue<T: Clone + Debug + Default + PartialEq> {
pub value: T,
pub(crate) options: u32,
}
pub(crate) mod xmp_prop {
pub(crate) const VALUE_IS_URI: u32 = 0x00000002;
pub(crate) const HAS_QUALIFIERS: u32 = 0x00000010;
pub(crate) const IS_QUALIFIER: u32 = 0x00000020;
pub(crate) const HAS_LANG: u32 = 0x00000040;
pub(crate) const HAS_TYPE: u32 = 0x00000080;
pub(crate) const VALUE_IS_STRUCT: u32 = 0x00000100;
pub(crate) const VALUE_IS_ARRAY: u32 = 0x00000200;
pub(crate) const ARRAY_IS_ORDERED: u32 = 0x00000400;
pub(crate) const ARRAY_IS_ALTERNATE: u32 = 0x00000800;
pub(crate) const ARRAY_IS_ALT_TEXT: u32 = 0x00001000;
pub(crate) const IS_ALIAS: u32 = 0x00010000;
pub(crate) const HAS_ALIASES: u32 = 0x00020000;
pub(crate) const IS_INTERNAL: u32 = 0x00040000;
pub(crate) const IS_STABLE: u32 = 0x00100000;
pub(crate) const IS_DERIVED: u32 = 0x00200000;
pub(crate) const IS_SCHEMA_NODE: u32 = 0x80000000;
}
impl<T: Clone + Debug + Default + PartialEq> XmpValue<T> {
pub fn new(value: T) -> Self {
Self { value, options: 0 }
}
pub fn has_no_flags(&self) -> bool {
self.options == 0
}
pub fn is_uri(&self) -> bool {
self.options & xmp_prop::VALUE_IS_URI != 0
}
pub fn set_is_uri(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::VALUE_IS_URI)
}
pub fn has_qualifiers(&self) -> bool {
self.options & xmp_prop::HAS_QUALIFIERS != 0
}
pub fn set_has_qualifiers(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::HAS_QUALIFIERS)
}
pub fn is_qualifier(&self) -> bool {
self.options & xmp_prop::IS_QUALIFIER != 0
}
pub fn set_is_qualifier(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::IS_QUALIFIER)
}
pub fn has_lang(&self) -> bool {
self.options & xmp_prop::HAS_LANG != 0
}
pub fn set_has_lang(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::HAS_LANG)
}
pub fn has_type(&self) -> bool {
self.options & xmp_prop::HAS_TYPE != 0
}
pub fn set_has_type(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::HAS_TYPE)
}
pub fn is_struct(&self) -> bool {
self.options & xmp_prop::VALUE_IS_STRUCT != 0
}
pub fn set_is_struct(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::VALUE_IS_STRUCT)
}
pub fn is_array(&self) -> bool {
self.options & xmp_prop::VALUE_IS_ARRAY != 0
}
pub fn set_is_array(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::VALUE_IS_ARRAY)
}
pub fn is_ordered(&self) -> bool {
self.options & xmp_prop::ARRAY_IS_ORDERED != 0
}
pub fn set_is_ordered(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::ARRAY_IS_ORDERED)
}
pub fn is_alternate(&self) -> bool {
self.options & xmp_prop::ARRAY_IS_ALTERNATE != 0
}
pub fn set_is_alternate(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::ARRAY_IS_ALTERNATE)
}
pub fn is_alt_text(&self) -> bool {
self.options & xmp_prop::ARRAY_IS_ALT_TEXT != 0
}
pub fn set_is_alt_text(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::ARRAY_IS_ALT_TEXT)
}
pub fn is_alias(&self) -> bool {
self.options & xmp_prop::IS_ALIAS != 0
}
pub fn set_is_alias(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::IS_ALIAS)
}
pub fn has_aliases(&self) -> bool {
self.options & xmp_prop::HAS_ALIASES != 0
}
pub fn set_has_aliases(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::HAS_ALIASES)
}
pub fn is_internal(&self) -> bool {
self.options & xmp_prop::IS_INTERNAL != 0
}
pub fn set_is_internal(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::IS_INTERNAL)
}
pub fn is_stable(&self) -> bool {
self.options & xmp_prop::IS_STABLE != 0
}
pub fn set_is_stable(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::IS_STABLE)
}
pub fn is_derived(&self) -> bool {
self.options & xmp_prop::IS_DERIVED != 0
}
pub fn set_is_derived(self, value: bool) -> Self {
self.set_flag(value, xmp_prop::IS_DERIVED)
}
fn set_flag(mut self, value: bool, prop_constant: u32) -> Self {
if value {
self.options |= prop_constant;
} else {
self.options &= !prop_constant;
}
self
}
pub fn is_schema_node(&self) -> bool {
self.options & xmp_prop::IS_SCHEMA_NODE != 0
}
}
impl<T: Clone + Debug + Default + PartialEq> From<T> for XmpValue<T> {
fn from(value: T) -> Self {
Self { value, options: 0 }
}
}
impl From<&str> for XmpValue<String> {
fn from(value: &str) -> Self {
Self {
value: value.to_owned(),
options: 0,
}
}
}