1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
macro_rules! enum_ {
    (
        #[repr($inner:ident)]
        $(#[$attr:meta])*
        pub enum $ety:ident {
            $($(#[$vattr:meta])* $name:ident = $value:expr,)*
        }
    ) => {
        #[repr($inner)]
        #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
        $(#[$attr])*
        pub enum $ety {
            $($(#[$vattr])* $name = $value,)*
        }
        impl $ety {
            #[inline]
            pub fn try_from(value: $inner) -> Option<Self> {
                match value {
                    $($value => Some($ety :: $name),)*
                    _ => None,
                }
            }
        }
    }
}
macro_rules! flags {
    (
        #[repr($inner:ident)]
        $(#[$attr:meta])*
        pub enum $flagty:ident {
            $($(#[$vattr:meta])* $name:ident = $value:expr,)*
        }
    ) => {
        #[repr(C)]
        #[derive(Copy, Clone, PartialEq, Eq, Hash)]
        $(#[$attr])*
        pub struct $flagty(pub $inner);
        impl $flagty {
            pub const NONE : $flagty = $flagty ( 0 );
            $($(#[$vattr])* pub const $name : $flagty = $flagty ( $value );)*
            #[inline]
            pub fn is_set(self, flag: Self) -> bool {
                self & flag == flag
            }
            #[inline]
            pub fn clear(&mut self, flag: Self) {
                *self &= !flag;
            }
            #[inline]
            pub fn validate(self) -> bool {
                const MASK: $inner = 0 | $($value)|*;
                self.0 & !MASK == 0
            }
        }
        impl $crate::std::ops::Not for $flagty {
            type Output = Self;
            #[inline]
            fn not(self) -> Self {
                $flagty ( !self.0 )
            }
        }
        impl $crate::std::ops::BitAnd for $flagty {
            type Output = Self;
            #[inline]
            fn bitand(self, rhs: Self) -> Self {
                $flagty ( self.0 & rhs.0 )
            }
        }
        impl $crate::std::ops::BitAndAssign for $flagty {
            #[inline]
            fn bitand_assign(&mut self, rhs: Self) {
                self.0 &= rhs.0;
            }
        }
        impl $crate::std::ops::BitOr for $flagty {
            type Output = Self;
            #[inline]
            fn bitor(self, rhs: Self) -> Self {
                $flagty ( self.0 | rhs.0 )
            }
        }
        impl $crate::std::ops::BitOrAssign for $flagty {
            #[inline]
            fn bitor_assign(&mut self, rhs: Self) {
                self.0 |= rhs.0;
            }
        }
        impl $crate::std::ops::BitXor for $flagty {
            type Output = Self;
            #[inline]
            fn bitxor(self, rhs: Self) -> Self {
                $flagty ( self.0 ^ rhs.0 )
            }
        }
        impl $crate::std::ops::BitXorAssign for $flagty {
            #[inline]
            fn bitxor_assign(&mut self, rhs: Self) {
                self.0 ^= rhs.0;
            }
        }
        impl $crate::std::fmt::Debug for $flagty {
            fn fmt(&self, fmt: &mut $crate::std::fmt::Formatter) -> $crate::std::fmt::Result {
                fmt.write_str(concat!(stringify!($flagty), "("))?;
                let mut first = true;
                $(if self.is_set($flagty :: $name) {
                    if first {
                        first = false;
                    } else {
                        fmt.write_str(" | ")?;
                    }
                    fmt.write_str(stringify!($name))?;
                })*
                if first {
                    fmt.write_str("NONE")?;
                }
                fmt.write_str(")")?;
                Ok(())
            }
        }
    }
}

pub use flags::alpha_mode::AlphaMode;
pub use flags::format::Format;
pub use flags::mode_rotation::ModeRotation;
pub use flags::mode_scaling::ModeScaling;
pub use flags::mode_scanline_order::ModeScanlineOrder;
pub use flags::present::PresentFlags;
pub use flags::scaling::Scaling;
pub use flags::swap_chain::SwapChainFlags;
pub use flags::swap_effect::SwapEffect;
pub use flags::usage::UsageFlags;

pub mod alpha_mode;
pub mod format;
pub mod mode_rotation;
pub mod mode_scaling;
pub mod mode_scanline_order;
pub mod present;
pub mod scaling;
pub mod swap_chain;
pub mod swap_effect;
pub mod usage;