Exemplo n.º 1
0
func NewVarLenType(base_type *DataType) (*VarLenType, error) {
	hid := C.H5Tvlen_create(base_type.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dt := new_vltype(hid)
	return dt, err
}
Exemplo n.º 2
0
// NewVarLenType creates a new VarLenType.
// base_type specifies the element type of the VarLenType.
func NewVarLenType(base_type *Datatype) (*VarLenType, error) {
	id := C.H5Tvlen_create(base_type.id)
	if err := checkID(id); err != nil {
		return nil, err
	}
	t := &VarLenType{Datatype{Location{Identifier{id}}}}
	runtime.SetFinalizer(t, (*VarLenType).finalizer)
	return t, nil
}
Exemplo n.º 3
0
Arquivo: put.go Projeto: postfix/hdf5
func initializeStructToPut(object *object, value reflect.Value) error {
	typo := value.Type()
	size := C.size_t(typo.Size())

	object.data = C.malloc(size)
	if object.data == nil {
		return errors.New("cannot allocate memory")
	}
	object.flag |= flagOwnedMemory

	object.tid = C.H5Tcreate(C.H5T_COMPOUND, size)
	if object.tid < 0 {
		return errors.New("cannot create a compound datatype")
	}

	count := typo.NumField()

	for i := 0; i < count; i++ {
		field := typo.Field(i)
		if len(field.PkgPath) > 0 {
			continue
		}

		o := object.new()
		if err := initializeToPut(o, value.Field(i)); err != nil {
			return err
		}

		address := unsafe.Pointer(uintptr(object.data) + uintptr(field.Offset))

		if o.flag&flagVariableLength != 0 {
			tid := C.H5Tvlen_create(o.tid)
			if tid < 0 {
				return errors.New("cannnot create a variable-length datatype")
			}

			// NOTE: It is assumed here that sizeof(hvl_t) <= v.Type().Size().
			h := (*C.hvl_t)(address)
			h.len, h.p = 1, o.data

			o = object.new()
			o.tid = tid
		} else {
			C.memcpy(address, o.data, C.size_t(value.Field(i).Type().Size()))
		}

		cname := C.CString(field.Name)
		defer C.free(unsafe.Pointer(cname))

		if C.H5Tinsert(object.tid, cname, C.size_t(field.Offset), o.tid) < 0 {
			return errors.New("cannot construct a compound datatype")
		}
	}

	return nil
}
Exemplo n.º 4
0
func NewVarLenType(base_type *Datatype) (*VarLenType, error) {
	id := C.H5Tvlen_create(base_type.id)
	err := h5err(C.herr_t(int(id)))
	if err != nil {
		return nil, err
	}
	t := &VarLenType{Datatype{Location{id}, nil}}
	runtime.SetFinalizer(t, (*VarLenType).finalizer)
	return t, err
}