From e44f395b06569c13cfd9a1b1d79ebf3e970bfb4d Mon Sep 17 00:00:00 2001 From: matt rice Date: Fri, 12 Apr 2024 17:45:35 -0700 Subject: [PATCH] Initial attempt at PtexMetaData find_key/get_key Signed-off-by: matt rice --- ptex-sys/src/lib.rs | 12 ++++++++++++ ptex-sys/src/ptex-sys.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ptex-sys/src/lib.rs b/ptex-sys/src/lib.rs index cd86403..b1556c2 100644 --- a/ptex-sys/src/lib.rs +++ b/ptex-sys/src/lib.rs @@ -546,6 +546,18 @@ pub mod ffi { #[namespace = "Ptex::sys"] unsafe fn ptexmetadata_num_keys(metadata: *const PtexMetaData) -> i32; + /// Get the key, and meta data type for a given `index` from a PtexMetaData pointer. + /// # Safety + /// Must only be called on valid PtexMetaData pointers. + #[namespace = "Ptex::sys"] + unsafe fn ptexmetadata_get_key(metadata: *const PtexMetaData, index: i32, key: *mut *const c_char, typ: *mut MetaDataType); + + /// Find the index, and meta data type for a given `key` from a PtexMetaData pointer. + /// Returning `true` if the key is found and `false` otherwise. + /// # Safety + /// Must only be called on valid PtexMetaData pointers. + #[namespace = "Ptex::sys"] + unsafe fn ptexmetadata_find_key(metadata: *const PtexMetaData, key: *const c_char, index: *mut i32, typ: *mut MetaDataType) -> bool; /// Release a PtexMetaData /// # Safety /// This function must be called with a valid PtexMetaData pointer. diff --git a/ptex-sys/src/ptex-sys.h b/ptex-sys/src/ptex-sys.h index f9fe30a..0a267e0 100644 --- a/ptex-sys/src/ptex-sys.h +++ b/ptex-sys/src/ptex-sys.h @@ -423,6 +423,20 @@ inline int32_t ptexmetadata_num_keys(PtexMetaData *metadata) { return (int32_t) metadata->numKeys(); } +inline void ptexmetadata_get_key(PtexMetaData *metadata, int index, const char *& key, MetaDataType& typ) { + if (metadata) { + metadata->getKey(index, key, typ); + } +} + +inline bool ptexmetadata_find_key(PtexMetaData *metadata, const char *key, int &index, MetaDataType& typ) { + if (metadata) { + return metadata->findKey(key, index, typ); + } else { + return false; + } +} + inline void ptexmetadata_release(PtexMetaData *metadata) { if (metadata) { metadata->release();