16 #define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL )
17 #define strtoll _strtoi64
22 #include "xDataTOM_importXML_private.h"
23 #include "xDataTOM_private.h"
25 #if defined __cplusplus
36 static int xDataTOME_initializeElement( statusMessageReporting *smr, xDataTOM_element *element, xDataTOM_element *parent,
int ordinal,
int index,
38 static void xDataTOME_displayTree( statusMessageReporting *smr, xDataTOM_element *element,
int printAttributes,
int level );
60 if( ( TOM = (xDataTOM_TOM *) smr_malloc2( smr,
sizeof( xDataTOM_TOM ), 1,
"xDataTOM_TOM" ) ) != NULL ) {
71 TOM->realFileName = NULL;
82 if( TOM == NULL )
return( NULL );
84 if( TOMp == NULL )
return( NULL );
103 if( fileName != NULL ) {
104 if( ( TOM->fileName = smr_allocateCopyString2( smr, fileName,
"fileName" ) ) == NULL )
return( 1 );
105 if( realpath( fileName, realPath ) != NULL ) {
106 if( ( TOM->realFileName = smr_allocateCopyString2( smr, realPath,
"realFileName" ) ) == NULL )
return( 1 );
116 if( TOM->root.children != NULL )
xDataTOME_displayTree( smr, TOM->root.children, printAttributes, 0 );
125 xDataTOM_element *
xDataTOM_mallocElement( statusMessageReporting *smr, xDataTOM_element *parent,
int ordinal,
int index,
char const *
name ) {
129 xDataTOM_element *element;
131 if( ( element = (xDataTOM_element *) smr_malloc2( smr,
sizeof( xDataTOM_element ), 1,
"xDataTOM_elelument" ) ) != NULL ) {
141 if( element == NULL )
return;
150 xDataTOM_element *child, *nextChild;
152 if( element == NULL )
return;
154 for( child = element->children; child != NULL; child = nextChild ) {
155 nextChild = child->next;
158 if( element->xDataInfo.ID != NULL ) {
179 printf(
"not freed for %s\n", element->xDataInfo.ID );
182 element->parent = NULL;
190 xDataTOM_element *element;
192 if( ( element =
xDataTOM_mallocElement( smr, parent, parent->numberOfChildren, index, name ) ) == NULL )
return( NULL );
193 if( parent->children == NULL ) {
194 parent->children = element; }
196 xDataTOM_element *last;
198 for( last = parent->children; last->next != NULL; last = last->next ) ;
199 last->next = element;
201 (parent->numberOfChildren)++;
210 element->ordinal = ordinal;
211 element->index = index;
212 element->parent = parent;
213 element->next = NULL;
214 element->name = smr_allocateCopyString2( smr, name,
"element->name" );
216 element->numberOfChildren = 0;
217 element->children = NULL;
225 return( TOM->root.children );
232 if( element != NULL ) element = element->children;
240 if( element != NULL ) element = element->next;
249 xDataTOM_element *child, *desired = NULL;
252 if( strcmp( child->name, name ) == 0 ) {
253 if( n == 0 ) desired = child;
258 if( required ) smr_setReportError2( smr, smr_unknownID, 1,
"elements '%s' not found in element '%s'", name, element->name ); }
260 smr_setReportError2( smr, smr_unknownID, 1,
"multiple (= %d) elements '%s' found in element '%s'", name, element->name );
271 xDataTOM_element *child;
314 int xDataTOME_getInterpolation( statusMessageReporting *smr, xDataTOM_element *element,
int index,
enum xDataTOM_interpolationFlag *independent,
315 enum xDataTOM_interpolationFlag *dependent,
enum xDataTOM_interpolationQualifier *qualifier ) {
317 xDataTOM_xDataInfo *xDI = &(element->xDataInfo);
319 if( xDI->ID == NULL )
return( 1 );
326 static void xDataTOME_displayTree( statusMessageReporting *smr, xDataTOM_element *element,
int printAttributes,
int level ) {
329 xDataTOM_element *child;
331 for( i = 0; i < level; i++ ) printf(
" " );
332 printf(
"/%s", element->name );
333 if( element->index >= 0 ) printf(
" (%d)", element->index );
334 if( printAttributes ) {
335 xDataTOM_attribute *attribute;
337 for( attribute = element->attributes.attributes; attribute != NULL; attribute = attribute->next ) {
338 printf(
" (%s, \"%s\")", attribute->name, attribute->value );
355 attributes->number = 0;
356 attributes->attributes = NULL;
363 xDataTOM_attribute *attribute, *next;
365 for( attribute = attributes->attributes; attribute != NULL; attribute = next ) {
366 next = attribute->next;
378 xDataTOM_attribute *attribute;
380 if( ( attribute = (xDataTOM_attribute *) smr_malloc2( smr,
sizeof( xDataTOM_attribute ), 1,
"xDataTOM_attribute" ) ) == NULL )
return( 1 );
381 if( ( attribute->name = smr_allocateCopyString2( smr, name,
"name" ) ) == NULL )
goto err;
382 if( ( attribute->value = smr_allocateCopyString2( smr, value,
"value" ) ) == NULL )
goto err;
383 if( attributes->attributes == NULL ) {
384 attributes->attributes = attribute; }
386 xDataTOM_attribute *last;
388 for( last = attributes->attributes; last->next != NULL; last = last->next ) ;
389 last->next = attribute;
391 attributes->number++;
405 xDataTOM_attribute *attribute;
407 for( attribute = attributes->attributes; attribute != NULL; attribute = attribute->next ) {
408 if( !strcmp( attribute->name, name ) )
return( attribute->value );
417 xDataTOM_attribute *attribute;
420 for( attribute = src->attributes; attribute != NULL; attribute = attribute->next ) {
438 if( value != NULL ) {
439 *n = (int) strtoll( value, &e, 10 );
440 if( *e == 0 )
return( 0 );
441 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"could not convert attribute %s's value = '%s' to an integer", name, value ); }
443 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"no attribute named '%s'", name );
455 if( value != NULL ) {
456 *d = strtod( value, &e );
457 if( *e == 0 )
return( 0 );
458 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"could not convert attribute %s's values = '%s' to a double", name, value ); }
460 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"no attribute named '%s'", name );
481 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo);
486 return( xDI->data = (
void *) smr_malloc2( smr, size, 1,
"xDI->data" ) );
493 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo);
495 if( xDI->ID != NULL ) {
496 return( !strcmp( xDI->ID, ID ) );
506 if( TE->xDataInfo.ID == NULL )
return( NULL );
507 return( &(TE->xDataInfo) );
517 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"element '%s' does not have xData", TE->name );
520 if( strcmp( ID, xDI->ID ) ) {
521 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1,
"xData has ID = '%s' not '%s' for element %s", xDI->ID, ID, TE->name );
528 #if defined __cplusplus
char const * xDataTOM_V_W_XYs_LegendreSeries_ID
xDataTOM_element * xDataTOME_getOneElementByName(statusMessageReporting *smr, xDataTOM_element *element, char const *name, int required)
int xDataTOM_V_W_XYs_free(xDataTOM_xDataInfo *xDI)
int xDataTOMAL_addAttribute(statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, char const *value)
int xDataTOM_regionsXYs_free(xDataTOM_xDataInfo *xDI)
int xDataTOM_polynomial_free(xDataTOM_xDataInfo *xDI)
int xDataTOMAL_convertAttributeToInteger(statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, int *n)
static int xDataTOM_initialize_xData(statusMessageReporting *smr, xDataTOM_xDataInfo *xDataInfo)
xDataTOM_element * xDataTOME_getFirstElement(xDataTOM_element *element)
void * xData_initializeData(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID, size_t size)
int xDataTOME_addAttribute(statusMessageReporting *smr, xDataTOM_element *element, char const *name, char const *value)
xDataTOM_TOM * xDataTOM_mallocTOM(statusMessageReporting *smr)
int xDataTOM_smrLibraryID
char const * xDataTOM_regionsXYs_ID
void * xDataTOM_freeTOM(statusMessageReporting *, xDataTOM_TOM **TOM)
const char * name(G4int ptype)
xDataTOM_TOM * xDataXML_importFile(statusMessageReporting *smr, char const *fileName)
void xDataTOMAL_initial(statusMessageReporting *, xDataTOM_attributionList *attributes)
char const * xDataTOM_V_W_XYs_ID
int xDataTOM_setFileNameTOM(statusMessageReporting *smr, xDataTOM_TOM *TOM, const char *fileName)
int xDataTOM_axes_release(xDataTOM_axes *axes)
xDataTOM_xDataInfo * xDataTOME_getXData(xDataTOM_element *TE)
int xDataTOM_numberOfElementsByName(statusMessageReporting *, xDataTOM_element *element, char const *name)
int xDataTOM_XYs_free(xDataTOM_xDataInfo *xDI)
int xDataTOM_V_W_XYs_LegendreSeries_free(xDataTOM_xDataInfo *xDI)
static int xDataTOME_initializeElement(statusMessageReporting *smr, xDataTOM_element *element, xDataTOM_element *parent, int ordinal, int index, char const *name)
int xDataTOM_axes_getInterpolation(statusMessageReporting *smr, xDataTOM_axes *axes, int index, enum xDataTOM_interpolationFlag *independent, enum xDataTOM_interpolationFlag *dependent, enum xDataTOM_interpolationQualifier *qualifier)
void xDataTOM_displayTree(statusMessageReporting *smr, xDataTOM_TOM *TOM, int printAttributes)
char const * xDataTOM_polynomial_ID
int xDataTOME_convertAttributeToInteger(statusMessageReporting *smr, xDataTOM_element *element, char const *name, int *n)
int xDataTOM_KalbachMann_free(xDataTOM_xDataInfo *xDI)
int xDataTOMAL_copyAttributionList(statusMessageReporting *smr, xDataTOM_attributionList *desc, xDataTOM_attributionList *src)
int smr_isOk(statusMessageReporting *smr)
void * xDataTOME_getXDataIfID(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID)
int xDataTOM_regionsW_XYs_LegendreSeries_free(xDataTOM_xDataInfo *xDI)
void * smr_freeMemory(void **p)
char const * xDataTOM_W_XYs_LegendreSeries_ID
int xDataTOME_getInterpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, enum xDataTOM_interpolationFlag *independent, enum xDataTOM_interpolationFlag *dependent, enum xDataTOM_interpolationQualifier *qualifier)
int xDataTOME_copyAttributionList(statusMessageReporting *smr, xDataTOM_attributionList *desc, xDataTOM_element *element)
xDataTOM_TOM * xDataTOM_importFile(statusMessageReporting *smr, const char *fileName)
void xDataTOMAL_release(xDataTOM_attributionList *attributes)
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
void xDataTOM_freeElement(xDataTOM_element **element)
int xDataTOM_initializeTOM(statusMessageReporting *smr, xDataTOM_TOM *TOM)
int xDataTOM_W_XYs_LegendreSeries_free(xDataTOM_xDataInfo *xDI)
xDataTOM_element * xDataTOME_getNextElement(xDataTOM_element *element)
char const * xDataTOM_W_XYs_ID
int xDataTOM_W_XYs_freeFrom_xDataInfo(xDataTOM_xDataInfo *xDI)
char const * xDataTOM_regionsW_XYs_LegendreSeries_ID
xDataTOM_element * xDataTOM_getDocumentsElement(xDataTOM_TOM *TOM)
int xDataTOMAL_convertAttributeToDouble(statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, double *d)
xDataTOM_element * xDataTOM_addElementInElement(statusMessageReporting *smr, xDataTOM_element *parent, int index, char const *name)
xDataTOM_element * xDataTOM_mallocElement(statusMessageReporting *smr, xDataTOM_element *parent, int ordinal, int index, char const *name)
void xDataTOM_releaseElement(xDataTOM_element *element)
static void xDataTOME_displayTree(statusMessageReporting *smr, xDataTOM_element *element, int printAttributes, int level)
int xDataTOM_isXDataID(xDataTOM_element *TE, char const *ID)
int xDataTOME_convertAttributeToDouble(statusMessageReporting *smr, xDataTOM_element *element, char const *name, double *d)
char const * xDataTOMAL_getAttributesValue(xDataTOM_attributionList *attributes, char const *name)
char const * xDataTOM_KalbachMann_ID
char const * xDataTOM_XYs_ID