Skip to content

Commit

Permalink
add glib::gobject:{TypePlugin,TypeModule,InterfaceInfo,TypeInfo,EnumV…
Browse files Browse the repository at this point in the history
…alue,FlagsValue,TypeValueTable,TypeFlags}

Signed-off-by: fbrouille <[email protected]>
  • Loading branch information
fbrouille committed Aug 12, 2023
1 parent 8986eb9 commit 711507e
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 4 deletions.
8 changes: 8 additions & 0 deletions glib/Gir_GObject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ girs_directories = ["../gir-files"]
generate = [
"GObject.BindingFlags",
"GObject.SignalFlags",
"GObject.TypeFlags",
"GObject.TypePlugin",
"GObject.TypeModule",
]

ignore = [
Expand All @@ -23,6 +26,9 @@ manual = [
"GLib.Quark",
"GObject.Object",
"GObject.Value",
"GObject.EnumValue",
"GObject.FlagsValue",
"GObject.TypeValueTable",
"GObject.ParamFlags",
"GObject.ParamSpec",
"GObject.ParamSpecChar",
Expand All @@ -48,6 +54,8 @@ manual = [
"GObject.ParamSpecOverride",
"GObject.ParamSpecGType",
"GObject.ParamSpecVariant",
"GObject.InterfaceInfo",
"GObject.TypeInfo",
]

[[object]]
Expand Down
22 changes: 21 additions & 1 deletion glib/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use std::{cmp, ffi::CStr, fmt, ptr};
use std::{cmp, ffi::CStr, fmt, marker::PhantomData, ptr};

use crate::{
translate::*,
Expand Down Expand Up @@ -300,6 +300,16 @@ unsafe impl<'a, 'b> FromValue<'a> for &'b EnumValue {
}
}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GEnumValue> for EnumValue {
type Storage = PhantomData<&'a Self>;

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GEnumValue, Self> {
Stash(&self.0 as *const gobject_ffi::GEnumValue, PhantomData)
}
}

pub struct EnumTypeChecker();
unsafe impl ValueTypeChecker for EnumTypeChecker {
type Error = InvalidEnumError;
Expand Down Expand Up @@ -806,6 +816,16 @@ impl PartialEq for FlagsValue {

impl Eq for FlagsValue {}

#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gobject_ffi::GFlagsValue> for FlagsValue {
type Storage = PhantomData<&'a Self>;

#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const gobject_ffi::GFlagsValue, Self> {
Stash(&self.0 as *const gobject_ffi::GFlagsValue, PhantomData)
}
}

// rustdoc-stripper-ignore-next
/// Builder for conveniently setting/unsetting flags and returning a `Value`.
///
Expand Down
41 changes: 41 additions & 0 deletions glib/src/gobject/auto/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,44 @@ impl FromGlib<gobject_ffi::GSignalFlags> for SignalFlags {
Self::from_bits_truncate(value)
}
}

bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[doc(alias = "GTypeFlags")]
pub struct TypeFlags: u32 {
#[doc(alias = "G_TYPE_FLAG_NONE")]
const NONE = gobject_ffi::G_TYPE_FLAG_NONE as _;
#[doc(alias = "G_TYPE_FLAG_ABSTRACT")]
const ABSTRACT = gobject_ffi::G_TYPE_FLAG_ABSTRACT as _;
#[doc(alias = "G_TYPE_FLAG_VALUE_ABSTRACT")]
const VALUE_ABSTRACT = gobject_ffi::G_TYPE_FLAG_VALUE_ABSTRACT as _;
#[doc(alias = "G_TYPE_FLAG_FINAL")]
const FINAL = gobject_ffi::G_TYPE_FLAG_FINAL as _;
#[doc(alias = "G_TYPE_FLAG_DEPRECATED")]
const DEPRECATED = gobject_ffi::G_TYPE_FLAG_DEPRECATED as _;
}
}

impl fmt::Display for TypeFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<Self as fmt::Debug>::fmt(self, f)
}
}

#[doc(hidden)]
impl IntoGlib for TypeFlags {
type GlibType = gobject_ffi::GTypeFlags;

#[inline]
fn into_glib(self) -> gobject_ffi::GTypeFlags {
self.bits()
}
}

#[doc(hidden)]
impl FromGlib<gobject_ffi::GTypeFlags> for TypeFlags {
#[inline]
unsafe fn from_glib(value: gobject_ffi::GTypeFlags) -> Self {
Self::from_bits_truncate(value)
}
}
13 changes: 13 additions & 0 deletions glib/src/gobject/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ mod signal_group;
#[cfg_attr(docsrs, doc(cfg(feature = "v2_74")))]
pub use self::signal_group::SignalGroup;

mod type_module;
pub use self::type_module::TypeModule;

mod type_plugin;
pub use self::type_plugin::TypePlugin;

mod flags;
pub use self::flags::BindingFlags;
pub use self::flags::SignalFlags;
pub use self::flags::TypeFlags;

#[doc(hidden)]
pub mod traits {
pub use super::type_module::TypeModuleExt;
pub use super::type_plugin::TypePluginExt;
}
121 changes: 121 additions & 0 deletions glib/src/gobject/auto/type_module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{
prelude::*, translate::*, EnumValue, FlagsValue, InterfaceInfo, TypeFlags, TypeInfo, TypePlugin,
};
use std::fmt;

crate::wrapper! {
#[doc(alias = "GTypeModule")]
pub struct TypeModule(Object<gobject_ffi::GTypeModule, gobject_ffi::GTypeModuleClass>) @implements TypePlugin;

match fn {
type_ => || gobject_ffi::g_type_module_get_type(),
}
}

impl TypeModule {
pub const NONE: Option<&'static TypeModule> = None;
}

mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::TypeModule>> Sealed for T {}
}

pub trait TypeModuleExt: IsA<TypeModule> + sealed::Sealed + 'static {
#[doc(alias = "g_type_module_add_interface")]
fn add_interface(
&self,
instance_type: crate::types::Type,
interface_type: crate::types::Type,
interface_info: &InterfaceInfo,
) {
unsafe {
gobject_ffi::g_type_module_add_interface(
self.as_ref().to_glib_none().0,
instance_type.into_glib(),
interface_type.into_glib(),
interface_info.to_glib_none().0,
);
}
}

#[doc(alias = "g_type_module_register_enum")]
fn register_enum(&self, name: &str, const_static_values: &EnumValue) -> crate::types::Type {
unsafe {
from_glib(gobject_ffi::g_type_module_register_enum(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
const_static_values.to_glib_none().0,
))
}
}

#[doc(alias = "g_type_module_register_flags")]
fn register_flags(&self, name: &str, const_static_values: &FlagsValue) -> crate::types::Type {
unsafe {
from_glib(gobject_ffi::g_type_module_register_flags(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
const_static_values.to_glib_none().0,
))
}
}

#[doc(alias = "g_type_module_register_type")]
fn register_type(
&self,
parent_type: crate::types::Type,
type_name: &str,
type_info: &TypeInfo,
flags: TypeFlags,
) -> crate::types::Type {
unsafe {
from_glib(gobject_ffi::g_type_module_register_type(
self.as_ref().to_glib_none().0,
parent_type.into_glib(),
type_name.to_glib_none().0,
type_info.to_glib_none().0,
flags.into_glib(),
))
}
}

#[doc(alias = "g_type_module_set_name")]
fn set_name(&self, name: &str) {
unsafe {
gobject_ffi::g_type_module_set_name(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
);
}
}

#[doc(alias = "g_type_module_unuse")]
fn unuse(&self) {
unsafe {
gobject_ffi::g_type_module_unuse(self.as_ref().to_glib_none().0);
}
}

#[doc(alias = "g_type_module_use")]
#[doc(alias = "use")]
fn use_(&self) -> bool {
unsafe {
from_glib(gobject_ffi::g_type_module_use(
self.as_ref().to_glib_none().0,
))
}
}
}

impl<O: IsA<TypeModule>> TypeModuleExt for O {}

impl fmt::Display for TypeModule {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("TypeModule")
}
}
83 changes: 83 additions & 0 deletions glib/src/gobject/auto/type_plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{prelude::*, translate::*, InterfaceInfo, TypeInfo, TypeValueTable};
use std::fmt;

crate::wrapper! {
#[doc(alias = "GTypePlugin")]
pub struct TypePlugin(Interface<gobject_ffi::GTypePlugin, gobject_ffi::GTypePluginClass>);

match fn {
type_ => || gobject_ffi::g_type_plugin_get_type(),
}
}

impl TypePlugin {
pub const NONE: Option<&'static TypePlugin> = None;
}

mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::TypePlugin>> Sealed for T {}
}

pub trait TypePluginExt: IsA<TypePlugin> + sealed::Sealed + 'static {
#[doc(alias = "g_type_plugin_complete_interface_info")]
fn complete_interface_info(
&self,
instance_type: crate::types::Type,
interface_type: crate::types::Type,
info: &mut InterfaceInfo,
) {
unsafe {
gobject_ffi::g_type_plugin_complete_interface_info(
self.as_ref().to_glib_none().0,
instance_type.into_glib(),
interface_type.into_glib(),
info.to_glib_none_mut().0,
);
}
}

#[doc(alias = "g_type_plugin_complete_type_info")]
fn complete_type_info(
&self,
g_type: crate::types::Type,
info: &mut TypeInfo,
value_table: &mut TypeValueTable,
) {
unsafe {
gobject_ffi::g_type_plugin_complete_type_info(
self.as_ref().to_glib_none().0,
g_type.into_glib(),
info.to_glib_none_mut().0,
value_table.to_glib_none_mut().0,
);
}
}

#[doc(alias = "g_type_plugin_unuse")]
fn unuse(&self) {
unsafe {
gobject_ffi::g_type_plugin_unuse(self.as_ref().to_glib_none().0);
}
}

#[doc(alias = "g_type_plugin_use")]
#[doc(alias = "use")]
fn use_(&self) {
unsafe {
gobject_ffi::g_type_plugin_use(self.as_ref().to_glib_none().0);
}
}
}

impl<O: IsA<TypePlugin>> TypePluginExt for O {}

impl fmt::Display for TypePlugin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("TypePlugin")
}
}
16 changes: 16 additions & 0 deletions glib/src/gobject/interface_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Take a look at the license at the top of the repository in the LICENSE file.

wrapper! {
#[derive(Debug)]
#[doc(alias = "GInterfaceInfo")]
pub struct InterfaceInfo(BoxedInline<gobject_ffi::GInterfaceInfo>);

match fn {
copy => |ptr| {
let copy = ffi::g_malloc(std::mem::size_of::<gobject_ffi::GInterfaceInfo>()) as *mut gobject_ffi::GInterfaceInfo;
std::ptr::copy_nonoverlapping(ptr, copy, 1);
copy
},
free => |ptr| ffi::g_free(ptr as *mut _),
}
}
9 changes: 9 additions & 0 deletions glib/src/gobject/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ pub use binding_group::BindingGroupBuilder;

pub use self::{auto::*, flags::*};
//pub use self::auto::functions::*;

mod type_value_table;
pub use type_value_table::TypeValueTable;

mod type_info;
pub use type_info::TypeInfo;

mod interface_info;
pub use interface_info::InterfaceInfo;
16 changes: 16 additions & 0 deletions glib/src/gobject/type_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Take a look at the license at the top of the repository in the LICENSE file.

wrapper! {
#[derive(Debug)]
#[doc(alias = "GTypeInfo")]
pub struct TypeInfo(BoxedInline<gobject_ffi::GTypeInfo>);

match fn {
copy => |ptr| {
let copy = ffi::g_malloc(std::mem::size_of::<gobject_ffi::GTypeInfo>()) as *mut gobject_ffi::GTypeInfo;
std::ptr::copy_nonoverlapping(ptr, copy, 1);
copy
},
free => |ptr| ffi::g_free(ptr as *mut _),
}
}
Loading

0 comments on commit 711507e

Please sign in to comment.