Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

MemoryFlags

https://learn.microsoft.com/en-us/windows/win32/menurc/common-resource-attributes https://learn.microsoft.com/en-us/windows/win32/menurc/resourceheader

res.MemoryFlags
pub const MemoryFlags = packed struct(u16)

File

Code

pub const MemoryFlags = packed struct(u16) {
    value: u16,

    pub const MOVEABLE: u16 = 0x10;
    // TODO: SHARED and PURE seem to be the same thing? Testing seems to confirm this but
    //       would like to find mention of it somewhere.
    pub const SHARED: u16 = 0x20;
    pub const PURE: u16 = 0x20;
    pub const PRELOAD: u16 = 0x40;
    pub const DISCARDABLE: u16 = 0x1000;

    /// Note: The defaults can have combinations that are not possible to specify within
    ///       an .rc file, as the .rc attributes imply other values (i.e. specifying
    ///       DISCARDABLE always implies MOVEABLE and PURE/SHARED, and yet RT_ICON
    ///       has a default of only MOVEABLE | DISCARDABLE).
    pub fn defaults(predefined_resource_type: ?RT) MemoryFlags {
        if (predefined_resource_type == null) {
            return MemoryFlags{ .value = MOVEABLE | SHARED };
        } else {
            return switch (predefined_resource_type.?) {
                // zig fmt: off
                .RCDATA, .BITMAP, .HTML, .MANIFEST,
                .ACCELERATOR, .VERSION, .MESSAGETABLE,
                .DLGINIT, .TOOLBAR, .PLUGPLAY,
                .VXD, => MemoryFlags{ .value = MOVEABLE | SHARED },

                .GROUP_ICON, .GROUP_CURSOR,
                .STRING, .FONT, .DIALOG, .MENU,
                .DLGINCLUDE, => MemoryFlags{ .value = MOVEABLE | SHARED | DISCARDABLE },

                .ICON, .CURSOR, .ANIICON, .ANICURSOR => MemoryFlags{ .value = MOVEABLE | DISCARDABLE },
                .FONTDIR => MemoryFlags{ .value = MOVEABLE | PRELOAD },
                // zig fmt: on
                // Same as predefined_resource_type == null
                _ => return MemoryFlags{ .value = MOVEABLE | SHARED },
            };
        }
    }

    pub fn set(self: *MemoryFlags, attribute: CommonResourceAttributes) void {
        switch (attribute) {
            .preload => self.value |= PRELOAD,
            .loadoncall => self.value &= ~PRELOAD,
            .moveable => self.value |= MOVEABLE,
            .fixed => self.value &= ~(MOVEABLE | DISCARDABLE),
            .shared => self.value |= SHARED,
            .nonshared => self.value &= ~(SHARED | DISCARDABLE),
            .pure => self.value |= PURE,
            .impure => self.value &= ~(PURE | DISCARDABLE),
            .discardable => self.value |= DISCARDABLE | MOVEABLE | PURE,
        }
    }

    pub fn setGroup(self: *MemoryFlags, attribute: CommonResourceAttributes, implied_shared_or_pure: bool) void {
        switch (attribute) {
            .preload => {
                self.value |= PRELOAD;
                if (implied_shared_or_pure) self.value &= ~SHARED;
            },
            .loadoncall => {
                self.value &= ~PRELOAD;
                if (implied_shared_or_pure) self.value |= SHARED;
            },
            else => self.set(attribute),
        }
    }
}