Skip to content

Commit

Permalink
Revert moving SMA-X specific conveninece methods here.
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 9, 2024
1 parent b42ceb1 commit 06c4d6c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 94 deletions.
6 changes: 0 additions & 6 deletions include/xchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ XField *xSetSubstruct(XStructure *s, const char *name, XStructure *substruct);
int xReduceDims(int *ndim, int *sizes);
int xReduceAllDims(XStructure *s);

// Convenience method for structure fields --------------->
boolean xGetBooleanField(const XStructure *s, const char *name, boolean defaultValue);
long long xGetLongField(const XStructure *s, const char *name, long long defaultValue);
double xGetDoubleField(const XStructure *s, const char *name, double defaultValue);
char *xGetRawField(const XStructure *s, const char *name, char *defaultValue);

// Sorting, ordering
int xSortFields(XStructure *s, int (*cmp)(const XField **f1, const XField **f2), boolean recursive);
int xSortFieldsByName(XStructure *s, boolean recursive);
Expand Down
88 changes: 0 additions & 88 deletions src/xstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,94 +226,6 @@ XField *xGetField(const XStructure *s, const char *id) {
return NULL;
}

/**
* Returns the first value in a structure's field as an integer, or the specified default
* value if there is no such fiield in the structure, or the content cannot be parse into an integer.
*
* @param s Pointer to the XStructure.
* @param name Field name
* @param defaultValue Value to return if no corresponding integer field value.
* @return The (first) field value as a long long, or the default value if there is no such field.
*
* @sa xGetField()
*/
boolean xGetBooleanField(const XStructure *s, const char *name, boolean defaultValue) {
boolean b;
const XField *f = xGetField(s, name);

if(!f) return defaultValue;

b = xParseBoolean(f->value, NULL);
if(b < 0) return defaultValue;
return b;
}

/**
* Returns the first value in a structure's field as an integer, or the specified default
* value if there is no such fiield in the structure, or the content cannot be parse into an integer.
*
* @param s Pointer to the XStructure.
* @param name Field name
* @param defaultValue Value to return if no corresponding integer field value.
* @return The (first) field value as a long long, or the default value if there is no such field.
*
* @sa xGetField()
*/
long long xGetLongField(const XStructure *s, const char *name, long long defaultValue) {
int i;
char *end;
const XField *f = xGetField(s, name);

if(!f) return defaultValue;

i = strtol(f->value, &end, 0);
if(end == f->value) return defaultValue;
if(errno == ERANGE) return defaultValue;
return i;
}


/**
* Returns the first value in a structure's field as a double precision float, or the specified
* default value if there is no such fiield in the structure, or the content cannot be parse into an double.
*
* @param s Pointer to the XStructure.
* @param name Field name
* @param defaultValue Value to return if no corresponding integer field value.
* @return The (first) field value as a double, or the specified default if there is no such field.
*
* @sa xGetField()
*/
double xGetDoubleField(const XStructure *s, const char *name, double defaultValue) {
double d;
char *end;
const XField *f = xGetField(s, name);

if(!f) return defaultValue;

d = strtod(f->value, &end);
if(end == f->value) return defaultValue;
if(errno == ERANGE) return defaultValue;
return d;
}

/**
* Returns the string value in a structure's field, or the specified default value if there is no
* such fiield in the structure.
*
* @param s Pointer to the XStructure.
* @param name Field name
* @param defaultValue Value to return if no corresponding integer field value.
* @return The field's string (raw) value, or the specified default if there is no such field.
*
* @sa xGetField()
*/
char *xGetRawField(const XStructure *s, const char *name, char *defaultValue) {
const XField *f = xGetField(s, name);
if(!f) return defaultValue;
return f->value;
}

/**
* Returns a substructure by the specified name, or NULL if no such sub-structure exists.
*
Expand Down

0 comments on commit 06c4d6c

Please sign in to comment.