Skip to content

Commit be72139

Browse files
authored
Merge pull request #36 from WiresmithTech/feature/refs2
Object Reference Types
2 parents dd8e048 + c461ec1 commit be72139

File tree

15 files changed

+563
-2
lines changed

15 files changed

+563
-2
lines changed

hdf5-src/ext/hdf5

Submodule hdf5 updated 4731 files

hdf5-types/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,15 @@ fn main() {
44
if std::env::var_os("DEP_HDF5_MSVC_DLL_INDIRECTION").is_some() {
55
println!("cargo::rustc-cfg=windows_dll");
66
}
7+
8+
// Declare the known HDF5 versions we might feature flag on
9+
// in this crate.
10+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"1.12.0\"))");
11+
12+
for (key, _) in std::env::vars() {
13+
if key.starts_with("DEP_HDF5_VERSION_") {
14+
let version = key.trim_start_matches("DEP_HDF5_VERSION_").replace("_", ".");
15+
println!("cargo::rustc-cfg=feature=\"{version}\"");
16+
}
17+
}
718
}

hdf5-types/src/dyn_value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ impl<'a> DynValue<'a> {
703703
FixedUnicode(_) => DynFixedString::new(buf, true).into(),
704704
VarLenAscii => DynVarLenString::new(buf, false).into(),
705705
VarLenUnicode => DynVarLenString::new(buf, true).into(),
706+
Reference(_x) => todo!(),
706707
}
707708
}
708709
}

hdf5-types/src/h5type.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::os::raw::c_void;
44
use std::ptr;
55

66
use crate::array::VarLenArray;
7+
use crate::references::Reference;
78
use crate::string::{FixedAscii, FixedUnicode, VarLenAscii, VarLenUnicode};
89

910
#[allow(non_camel_case_types)]
@@ -160,6 +161,7 @@ pub enum TypeDescriptor {
160161
VarLenArray(Box<Self>),
161162
VarLenAscii,
162163
VarLenUnicode,
164+
Reference(Reference),
163165
}
164166

165167
impl Display for TypeDescriptor {
@@ -186,6 +188,10 @@ impl Display for TypeDescriptor {
186188
TypeDescriptor::VarLenArray(ref tp) => write!(f, "[{}] (var len)", tp),
187189
TypeDescriptor::VarLenAscii => write!(f, "string (var len)"),
188190
TypeDescriptor::VarLenUnicode => write!(f, "unicode (var len)"),
191+
TypeDescriptor::Reference(Reference::Object) => write!(f, "reference (object)"),
192+
TypeDescriptor::Reference(Reference::Region) => write!(f, "reference (region)"),
193+
#[cfg(feature = "1.12.0")]
194+
TypeDescriptor::Reference(Reference::Std) => write!(f, "reference"),
189195
}
190196
}
191197
}
@@ -202,6 +208,7 @@ impl TypeDescriptor {
202208
Self::FixedAscii(len) | Self::FixedUnicode(len) => len,
203209
Self::VarLenArray(_) => mem::size_of::<hvl_t>(),
204210
Self::VarLenAscii | Self::VarLenUnicode => mem::size_of::<*const u8>(),
211+
Self::Reference(reftyp) => reftyp.size(),
205212
}
206213
}
207214

@@ -340,7 +347,7 @@ unsafe impl<T: H5Type, const N: usize> H5Type for [T; N] {
340347
}
341348
}
342349

343-
unsafe impl<T: Copy + H5Type> H5Type for VarLenArray<T> {
350+
unsafe impl<T: H5Type + Copy> H5Type for VarLenArray<T> {
344351
#[inline]
345352
fn type_descriptor() -> TypeDescriptor {
346353
TypeDescriptor::VarLenArray(Box::new(<T as H5Type>::type_descriptor()))

hdf5-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern crate quickcheck;
2020
mod array;
2121
pub mod dyn_value;
2222
mod h5type;
23+
pub mod references;
2324
mod string;
2425

2526
#[cfg(feature = "complex")]
@@ -30,6 +31,7 @@ pub use self::dyn_value::{DynValue, OwnedDynValue};
3031
pub use self::h5type::{
3132
CompoundField, CompoundType, EnumMember, EnumType, FloatSize, H5Type, IntSize, TypeDescriptor,
3233
};
34+
pub use self::references::Reference;
3335
pub use self::string::{FixedAscii, FixedUnicode, StringError, VarLenAscii, VarLenUnicode};
3436

3537
pub(crate) unsafe fn malloc(n: usize) -> *mut core::ffi::c_void {

hdf5-types/src/references.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Types for references.
2+
3+
use std::mem;
4+
5+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6+
pub enum Reference {
7+
Object,
8+
Region,
9+
#[cfg(feature = "1.12.0")]
10+
Std,
11+
}
12+
13+
impl Reference {
14+
pub fn size(self) -> usize {
15+
match self {
16+
Self::Object => mem::size_of::<hdf5_sys::h5r::hobj_ref_t>(),
17+
Self::Region => mem::size_of::<hdf5_sys::h5r::hdset_reg_ref_t>(),
18+
#[cfg(feature = "1.12.0")]
19+
Self::Std => mem::size_of::<hdf5_sys::h5r::H5R_ref_t>(),
20+
}
21+
}
22+
}

hdf5/src/globals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ link_hid!(H5T_STD_B64BE, h5t::H5T_STD_B64BE);
7777
link_hid!(H5T_STD_B64LE, h5t::H5T_STD_B64LE);
7878
link_hid!(H5T_STD_REF_OBJ, h5t::H5T_STD_REF_OBJ);
7979
link_hid!(H5T_STD_REF_DSETREG, h5t::H5T_STD_REF_DSETREG);
80+
#[cfg(feature = "1.12.0")]
81+
link_hid!(H5T_STD_REF, h5t::H5T_STD_REF);
8082
link_hid!(H5T_UNIX_D32BE, h5t::H5T_UNIX_D32BE);
8183
link_hid!(H5T_UNIX_D32LE, h5t::H5T_UNIX_D32LE);
8284
link_hid!(H5T_UNIX_D64BE, h5t::H5T_UNIX_D64BE);

hdf5/src/hl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod group;
1111
pub mod location;
1212
pub mod object;
1313
pub mod plist;
14+
pub mod references;
1415
pub mod selection;
1516

1617
pub use self::{

hdf5/src/hl/datatype.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ impl Datatype {
410410
}
411411
TD::VarLenAscii => string_type(None, H5T_cset_t::H5T_CSET_ASCII),
412412
TD::VarLenUnicode => string_type(None, H5T_cset_t::H5T_CSET_UTF8),
413+
#[cfg(feature = "1.12.0")]
414+
TD::Reference(hdf5_types::Reference::Std) => {
415+
Ok(h5try!(H5Tcopy(*crate::globals::H5T_STD_REF)))
416+
}
417+
TD::Reference(hdf5_types::Reference::Object) => {
418+
Ok(h5try!(H5Tcopy(*crate::globals::H5T_STD_REF_OBJ)))
419+
}
420+
TD::Reference(hdf5_types::Reference::Region) => {
421+
Ok(h5try!(H5Tcopy(*crate::globals::H5T_STD_REF_DSETREG)))
422+
}
413423
}
414424
});
415425

hdf5/src/hl/location.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ impl Location {
146146
pub fn open_by_token(&self, token: LocationToken) -> Result<Self> {
147147
H5O_open_by_token(self.id(), token)
148148
}
149+
150+
/// Generate a [object reference](ObjectReference) to the object for a reference storage.
151+
///
152+
/// This can be a group, dataset or datatype. Other objects are not supported.
153+
pub fn reference<R: ObjectReference>(&self, name: &str) -> Result<R> {
154+
R::create(self, name)
155+
}
156+
157+
/// Get a reference back to the referenced object from a standard reference.
158+
///
159+
/// This can be called against any object in the same file as the referenced object.
160+
pub fn dereference<R: ObjectReference>(&self, reference: &R) -> Result<ReferencedObject> {
161+
reference.dereference(self)
162+
}
149163
}
150164

151165
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)