ss_attr_t *
ss_attr_new(ss_pers_t *owner, /* The object with which the new attribute is associated. */
const char *name, /* The name of the new attribute. */
hid_t type, /* The datatype of the attribute. */
size_t count, /* Number of values in the attribute. */
const void *value, /* Optional array of COUNT values each of type TYPE. If this array is not
* supplied then the attribute's value will be initialized to all zero bytes. */
unsigned flags, /* Bit flags, such as SS_ALLSAME. */
ss_attr_t *buf, /* The optional buffer for the returned attribute link. */
ss_prop_t *props /* Attribute properties (none defined yet). */
)
{
SS_ENTER(ss_attr_new, ss_attr_tP);
ss_attr_t *attr=NULL; /* The returned attribute linke */
ss_scope_t scope; /* The scope containing OWNER and in which the attribute will be stored */
/* Check arguments */
SS_ASSERT_CLASS(owner, ss_pers_t);
if (SS_MAGIC(ss_attr_t)==SS_MAGIC_OF(owner)) SS_ERROR_FMT(USAGE, ("attribute owner must not be an attribute"));
if (!name || !*name) SS_ERROR_FMT(USAGE, ("attribute name must be specified"));
if (count<=0) SS_ERROR_FMT(USAGE, ("attribute count must be positive"));
/* Create a new attribute object */
if (NULL==ss_pers_scope(owner, &scope)) SS_ERROR(FAILED);
if (NULL==(attr=(ss_attr_t*)ss_pers_new(&scope, SS_MAGIC(ss_attr_t), NULL, flags, (ss_pers_t*)buf, props))) SS_ERROR(FAILED);
/* Initialize the attribute */
SS_ATTR(attr)->owner = *owner;
if (ss_string_set(SS_ATTR_P(attr,name), name)<0) SS_ERROR(FAILED);
if (ss_array_target(SS_ATTR_P(attr,value), type)<0) SS_ERROR(FAILED);
if (ss_array_resize(SS_ATTR_P(attr,value), count)<0) SS_ERROR(FAILED);
if (value && ss_array_put(SS_ATTR_P(attr,value), type, (size_t)0, count, value)<0) SS_ERROR(FAILED);
SS_CLEANUP:
SS_LEAVE(attr);
}