Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
xData.cc File Reference
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "xData.h"

Go to the source code of this file.

Functions

xData_documentxData_parseReadFile (statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
 
xData_documentxData_parseString (statusMessageReporting *smr, const char *str, xData_xDataTypeOk func, void *userData)
 
xData_documentxData_parseMalloc (statusMessageReporting *smr, xData_xDataTypeOk func, void *userData)
 
int xData_parseInitialize (statusMessageReporting *smr, xData_document *doc, xData_xDataTypeOk func, void *userData)
 
int xData_parseEndOfXML (statusMessageReporting *smr, xData_document *doc)
 
void * xData_parseFree (statusMessageReporting *smr, xData_document *doc)
 
int xData_parse (xData_document *doc, const char *s)
 
int xData_parseIsError (xData_document *doc)
 
xData_elementxData_getDocumentsElement (xData_document *doc)
 
xData_elementxData_getFirstElement (xData_element *element)
 
xData_elementxData_getNextElement (xData_element *element)
 
enum xData_itemMode xData_getFirstItem (xData_element *element, xData_item *item)
 
enum xData_itemMode xData_getNextItem (xData_item *item)
 
char * xData_getAttributesValue (xData_attributionList *attributes, const char *name)
 
const char * xData_getAttributesValueInElement (xData_element *element, const char *name)
 
int xData_initializeAttributionList (statusMessageReporting *, xData_attributionList *attributes)
 
int xData_copyAttributionList (statusMessageReporting *smr, xData_attributionList *dest, xData_attributionList *src)
 
int xData_attributeListLength (xData_attributionList *attributes)
 
xData_attributexData_attributeByIndex (xData_attributionList *attributes, int index)
 
int xData_releaseAttributionList (statusMessageReporting *smr, xData_attributionList *attributes)
 
xData_elementxData_getElements_xDataElement (statusMessageReporting *smr, xData_element *element)
 
int xData_getCommonData (statusMessageReporting *smr, xData_element *element, xData_Int *index, xData_Int *start, xData_Int *end, xData_Int *length)
 
int xData_xDataTypeConvertAttributes (statusMessageReporting *smr, xData_element *element)
 
xData_Int xData_convertAttributeTo_xData_Int (statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
 
int xData_convertAttributeToDouble (statusMessageReporting *smr, xData_element *element, const char *name, double *d)
 
int xData_numberOfElementsByTagName (statusMessageReporting *, xData_element *element, const char *tagName)
 
xData_elementListxData_getElementsByTagName (statusMessageReporting *smr, xData_element *element, const char *tagName)
 
xData_elementListxData_getElementsByTagNameAndSort (statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
 
xData_elementxData_getOneElementByTagName (statusMessageReporting *smr, xData_element *element, char *name, int required)
 
void xData_freeElementList (statusMessageReporting *smr, xData_elementList *list)
 
int xData_is_xDataType (statusMessageReporting *smr, xDataType *xDT, char const *const type, int setMsg)
 
char constxData_getFileName (xData_document *doc)
 
int xData_setFileName (statusMessageReporting *smr, xData_document *doc, char const *fileName)
 
xData_documentxData_getElementsDocument (xData_element *element)
 
void * xData_get_smrUserInterfaceFromDocument (xData_document *doc)
 
void * xData_get_smrUserInterfaceFromElement (xData_element *element)
 
int xData_stringTo_xData_Int (statusMessageReporting *smr, void *smrUserInterface, char const *c, xData_Int *value, char const *endings, char **e)
 
int xData_stringTo_double (statusMessageReporting *smr, void *smrUserInterface, char const *c, double *value, char const *endings, char **e)
 
int xData_addToAccessed (statusMessageReporting *, xData_element *element, int increment)
 
int xData_getAccessed (statusMessageReporting *, xData_element *element)
 

Function Documentation

◆ xData_addToAccessed()

◆ xData_attributeByIndex()

xData_attribute * xData_attributeByIndex ( xData_attributionList attributes,
int  index 
)

Definition at line 603 of file xData.cc.

603 {
604
605 if( index >= attributes->number ) return( NULL );
606 return( &(attributes->attributes[index]) );
607}
xData_attribute * attributes
Definition: xData.h:129

◆ xData_attributeListLength()

int xData_attributeListLength ( xData_attributionList attributes)

Definition at line 596 of file xData.cc.

596 {
597
598 return( attributes->number );
599}

◆ xData_convertAttributeTo_xData_Int()

xData_Int xData_convertAttributeTo_xData_Int ( statusMessageReporting smr,
xData_element element,
const char *  name,
xData_Int n 
)

Definition at line 710 of file xData.cc.

710 {
711/*
712* Returns 1 if no such attribute, -1 if error converting to xData_Int and 0 if successful.
713*/
714 const char *value;
715 char *e;
716
717 if( ( value = xData_getAttributesValueInElement( element, name ) ) == NULL ) return( 1 );
718 //*n = strtoll( value, &e, 10 );
719 *n = strtol( value, &e, 10 );
720 if( *e != 0 ) {
721 smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( element ), __FILE__, __LINE__, 1,
722 "could not convert attribute %s's value = %s to an integer", name, value );
723 return( -1 );
724 }
725 return( 0 );
726}
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
void * xData_get_smrUserInterfaceFromElement(xData_element *element)
Definition: xData.cc:952
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
Definition: xData.cc:546

Referenced by tpia_angularEnergy_getFromElement(), tpia_channel_getFromElement(), tpia_misc_getEqualProbableBin(), tpia_misc_getEqualProbableBins(), tpia_target_heated_read(), and xData_xDataTypeConvertAttributes().

◆ xData_convertAttributeToDouble()

int xData_convertAttributeToDouble ( statusMessageReporting smr,
xData_element element,
const char *  name,
double *  d 
)

Definition at line 730 of file xData.cc.

730 {
731/*
732* Returns 1 if no such attribute, -1 if error converting to double and 0 if successful.
733*/
734 const char *value;
735 char *e;
736
737 if( ( value = xData_getAttributesValueInElement( element, name ) ) == NULL ) return( 1 );
738 *d = strtod( value, &e );
739 if( *e != 0 ) {
740 smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( element) , __FILE__, __LINE__, 1,
741 "could not convert attribute %s's values = %s to a double", name, value );
742 return( -1 );
743 }
744 return( 0 );
745}

Referenced by tpia_angularEnergy_getFromElement(), tpia_misc_getEqualProbableBins(), and tpia_target_read().

◆ xData_copyAttributionList()

int xData_copyAttributionList ( statusMessageReporting smr,
xData_attributionList dest,
xData_attributionList src 
)

Definition at line 564 of file xData.cc.

564 {
565/*
566* The dest must not be active, else a memory leak will occur, as this routine does no free-ing.
567*/
568 int i;
569 size_t lens;
570 xData_attribute *d, *s;
571 char *p;
572
573 //if( ( dest->attributes = xData_malloc2( smr, src->size, 0, "attributes" ) ) == NULL ) return( 1 );
574 if( ( dest->attributes = (xData_attribute*) xData_malloc2( smr, src->size, 0, "attributes" ) ) == NULL ) return( 1 );
575 dest->number = src->number;
576 dest->size = src->size;
577 d = dest->attributes;
578 s = src->attributes;
579 p = (char *) &(dest->attributes[src->number]);
580 for( i = 0; i < src->number; i++, s++, d++ ) {
581 lens = strlen( s->name ) + 1;
582 d->name = p;
583 strcpy( p, s->name );
584 p += lens;
585 lens = strlen( s->value ) + 1;
586 d->value= p;
587 strcpy( p, s->value );
588 p += lens;
589 }
590
591 return( 0 );
592}
char * name
Definition: xData.h:122
char * value
Definition: xData.h:123
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313

Referenced by tpia_channel_getFromElement(), tpia_product_getFromElement(), tpia_target_heated_read(), and tpia_target_read().

◆ xData_freeElementList()

void xData_freeElementList ( statusMessageReporting smr,
xData_elementList list 
)

Definition at line 832 of file xData.cc.

832 {
833
834 xData_free( smr, list );
835}
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89

Referenced by tpia_angularEnergy_getFromElement(), tpia_Legendre_getFromElement(), tpia_misc_getEqualProbableBins(), tpia_product_getDecayChannelFromElement(), and xData_getOneElementByTagName().

◆ xData_get_smrUserInterfaceFromDocument()

void * xData_get_smrUserInterfaceFromDocument ( xData_document doc)

Definition at line 944 of file xData.cc.

944 {
945
946 if( doc == NULL ) return( NULL );
947 return( &(doc->smrUserInterface ) );
948}
xData_smr smrUserInterface
Definition: xData.h:205

Referenced by xData_get_smrUserInterfaceFromElement(), and xData_parseEndOfXML().

◆ xData_get_smrUserInterfaceFromElement()

void * xData_get_smrUserInterfaceFromElement ( xData_element element)

Definition at line 952 of file xData.cc.

952 {
953
955}
xData_document * xData_getElementsDocument(xData_element *element)
Definition: xData.cc:934
void * xData_get_smrUserInterfaceFromDocument(xData_document *doc)
Definition: xData.cc:944

Referenced by getRowStartEndAtIndex(), xData_1d_x_copyData(), xData_convertAttributeTo_xData_Int(), xData_convertAttributeToDouble(), xData_getCommonData(), xData_getOneElementByTagName(), xData_is_xDataType(), and xData_xDataTypeConvertAttributes().

◆ xData_getAccessed()

int xData_getAccessed ( statusMessageReporting smr,
xData_element element 
)

Definition at line 1087 of file xData.cc.

1087 {
1088
1089 return( element->accessed );
1090}

◆ xData_getAttributesValue()

char * xData_getAttributesValue ( xData_attributionList attributes,
const char *  name 
)

Definition at line 530 of file xData.cc.

530 {
531
532 int i;
533 char *value = NULL;
534
535 for( i = 0; i < attributes->number; i++ ) {
536 if( !strcmp( attributes->attributes[i].name, name ) ) {
537 value = attributes->attributes[i].value;
538 break;
539 }
540 }
541 return( value );
542}

Referenced by tpia_misc_pointerToAttributeIfAllOk(), tpia_multiplicity_getTimeScaleFromElement(), tpia_target_getAttributesValue(), tpia_target_heated_read(), and xData_getAttributesValueInElement().

◆ xData_getAttributesValueInElement()

const char * xData_getAttributesValueInElement ( xData_element element,
const char *  name 
)

Definition at line 546 of file xData.cc.

546 {
547
548 return( (const char *) xData_getAttributesValue( &(element->attributes), name ) );
549}
xData_attributionList attributes
Definition: xData.h:186
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
Definition: xData.cc:530

Referenced by tpia_frame_setFromElement(), tpia_map_readFile(), tpia_target_read(), xData_convertAttributeTo_xData_Int(), xData_convertAttributeToDouble(), and xData_getElementsByTagNameAndSort().

◆ xData_getCommonData()

int xData_getCommonData ( statusMessageReporting smr,
xData_element element,
xData_Int index,
xData_Int start,
xData_Int end,
xData_Int length 
)

Definition at line 652 of file xData.cc.

653 {
654
655 if( element->xDataTypeInfo.typeString == NULL ) {
656 smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( element ), __FILE__, __LINE__, 1, "element %s is not xData", element->fullName );
657 return( 1 );
658 }
659 *index = element->xDataTypeInfo.index;
660 *start = element->xDataTypeInfo.start;
661 *end = element->xDataTypeInfo.end;
662 *length = element->xDataTypeInfo.length;
663 return( 0 );
664}
xData_Int length
Definition: xData.h:162
xData_Int index
Definition: xData.h:162
xData_Int end
Definition: xData.h:162
const char * typeString
Definition: xData.h:156
xData_Int start
Definition: xData.h:162
char * fullName
Definition: xData.h:185
xDataType xDataTypeInfo
Definition: xData.h:187

◆ xData_getDocumentsElement()

xData_element * xData_getDocumentsElement ( xData_document doc)

Definition at line 476 of file xData.cc.

476{ return( doc->root.children ); }
xData_rootElement root
Definition: xData.h:208
xData_element * children
Definition: xData.h:172

Referenced by tpia_map_readFile(), tpia_target_heated_read(), and tpia_target_read().

◆ xData_getElements_xDataElement()

xData_element * xData_getElements_xDataElement ( statusMessageReporting smr,
xData_element element 
)

Definition at line 622 of file xData.cc.

622 {
623
624 //return( xData_getOneElementByTagName( smr, element, "xData", 1 ) );
625 return( xData_getOneElementByTagName( smr, element, (char*) "xData", 1 ) );
626}
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
Definition: xData.cc:810

Referenced by tpia_misc_getEqualProbableBins().

◆ xData_getElementsByTagName()

xData_elementList * xData_getElementsByTagName ( statusMessageReporting smr,
xData_element element,
const char *  tagName 
)

Definition at line 761 of file xData.cc.

761 {
762
763 int n = xData_numberOfElementsByTagName( smr, element, tagName );
764 size_t size;
765 xData_element *child;
767 xData_elementList *list = NULL;
768
769
770 size = sizeof( xData_elementList ) + n * sizeof( xData_elementListItem );
771 //if( ( list = xData_malloc2( smr, size, 0, "list" ) ) != NULL ) {
772 if( ( list = (xData_elementList*) xData_malloc2( smr, size, 0, "list" ) ) != NULL ) {
773 list->n = n;
774 p = list->items = (xData_elementListItem *) &(list[1]);
775 for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) {
776 if( !strcmp( child->name, tagName ) ) {
777 p->element = child;
778 p->sortString = NULL;
779 p++;
780 }
781 }
782 }
783 return( list );
784}
xData_element * element
Definition: xData.h:145
const char * sortString
Definition: xData.h:146
xData_elementListItem * items
Definition: xData.h:151
char * name
Definition: xData.h:184
int xData_numberOfElementsByTagName(statusMessageReporting *, xData_element *element, const char *tagName)
Definition: xData.cc:750
xData_element * xData_getNextElement(xData_element *element)
Definition: xData.cc:478
xData_element * xData_getFirstElement(xData_element *element)
Definition: xData.cc:477
struct xData_elementList_s xData_elementList
Definition: xData.h:97

Referenced by tpia_product_getDecayChannelFromElement(), xData_getElementsByTagNameAndSort(), and xData_getOneElementByTagName().

◆ xData_getElementsByTagNameAndSort()

xData_elementList * xData_getElementsByTagNameAndSort ( statusMessageReporting smr,
xData_element element,
const char *  tagName,
const char *  sortAttributeName,
xData_sortElementFunc  sortFunction 
)

Definition at line 788 of file xData.cc.

789 {
790
791 int i;
792 xData_elementList *list = xData_getElementsByTagName( smr, element, tagName );
794
795 if( list != NULL ) {
796 if( sortFunction == NULL ) {
797 sortFunction = (xData_sortElementFunc) xData_elementList_defaultSorter;
798 if( sortAttributeName == NULL ) sortFunction = (xData_sortElementFunc) xData_elementList_indexSorter;
799 }
800 if( sortAttributeName == NULL ) sortAttributeName = "index";
801 for( i = 0, p = list->items; i < list->n; i++, p++ ) p->sortString = xData_getAttributesValueInElement( p->element, sortAttributeName );
802 qsort( list->items, list->n, sizeof( xData_elementListItem ), sortFunction );
803 }
804
805 return( list );
806}
xData_elementList * xData_getElementsByTagName(statusMessageReporting *smr, xData_element *element, const char *tagName)
Definition: xData.cc:761
int(* xData_sortElementFunc)(const void *, const void *)
Definition: xData.h:99

Referenced by tpia_angularEnergy_getFromElement(), tpia_Legendre_getFromElement(), and tpia_misc_getEqualProbableBins().

◆ xData_getElementsDocument()

xData_document * xData_getElementsDocument ( xData_element element)

Definition at line 934 of file xData.cc.

934 {
935
936 xData_rootElement* root = element->parentRoot;
937
938 while( root->parentRoot != NULL ) root = root->parentRoot;
939 return( root->xData_doc );
940}
xData_rootElement * parentRoot
Definition: xData.h:181
xData_document * xData_doc
Definition: xData.h:167
xData_rootElement * parentRoot
Definition: xData.h:169

Referenced by xData_get_smrUserInterfaceFromElement().

◆ xData_getFileName()

char const * xData_getFileName ( xData_document doc)

Definition at line 914 of file xData.cc.

914 {
915
916 return( doc->fileName );
917}
char * fileName
Definition: xData.h:202

◆ xData_getFirstElement()

◆ xData_getFirstItem()

enum xData_itemMode xData_getFirstItem ( xData_element element,
xData_item item 
)

Definition at line 482 of file xData.cc.

482 {
483
484 item->parentElement = element;
485 item->element = xData_getFirstElement( element );
486 if( item->element == NULL ) {
487 item->mode = xData_itemModeText;
488 if( element->text.length == 0 ) item->mode = xData_itemModeEnd; }
489 else {
491 if( 0 < item->element->textOffset ) item->mode = xData_itemModeText;
492 }
493 item->textOffset = 0;
494 item->textLength = element->text.length;
495 if( item->element != NULL ) item->textLength = item->element->textOffset;
496 item->text = element->text.text;
497 return( item->mode );
498}
xData_text text
Definition: xData.h:189
size_t textOffset
Definition: xData.h:188
enum xData_itemMode mode
Definition: xData.h:215
char * text
Definition: xData.h:218
size_t textOffset
Definition: xData.h:216
xData_element * element
Definition: xData.h:214
size_t textLength
Definition: xData.h:217
xData_element * parentElement
Definition: xData.h:213
char * text
Definition: xData.h:136
size_t length
Definition: xData.h:135
@ xData_itemModeText
Definition: xData.h:80
@ xData_itemModeEnd
Definition: xData.h:80
@ xData_itemModeElement
Definition: xData.h:80

◆ xData_getNextElement()

xData_element * xData_getNextElement ( xData_element element)

◆ xData_getNextItem()

enum xData_itemMode xData_getNextItem ( xData_item item)

Definition at line 502 of file xData.cc.

502 {
503
504 if( item->mode != xData_itemModeEnd ) {
505 if( item->mode == xData_itemModeText ) {
507 if( item->element == NULL ) item->mode = xData_itemModeEnd;
508 item->textOffset += item->textLength;
509 item->textLength = 0;
510 item->text = &(item->parentElement->text.text[item->textOffset]); }
511 else {
512 item->element = item->element->next;
513 item->mode = xData_itemModeText;
514 if( item->element == NULL ) {
515 if( item->textOffset < item->parentElement->text.length ) {
516 item->textLength = item->parentElement->text.length - item->textOffset; }
517 else {
518 item->mode = xData_itemModeEnd;
519 } }
520 else {
521 item->textLength = item->element->textOffset - item->textOffset;
522 }
523 }
524 }
525 return( item->mode );
526}

◆ xData_getOneElementByTagName()

xData_element * xData_getOneElementByTagName ( statusMessageReporting smr,
xData_element element,
char *  name,
int  required 
)

Definition at line 810 of file xData.cc.

810 {
811
812 xData_elementList *list;
813 xData_element *xData = NULL;
814
815 if( ( list = xData_getElementsByTagName( smr, element, name ) ) != NULL ) {
816 if( list->n == 0 ) {
817 if( required ) smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( element ), __FILE__, __LINE__,
818 1, "element %s does not have sub-element named %s", element->fullName, name ); }
819 else if( list->n > 1 ) {
820 smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( element ), __FILE__, __LINE__, 1,
821 "element %s contains more than one sub-element named %s", element->fullName, name ); }
822 else {
823 xData = list->items[0].element;
824 }
825 xData_freeElementList( smr, list );
826 }
827 return( xData );
828}
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)
Definition: xData.cc:832

Referenced by tpia_angularEnergy_getFromElement(), tpia_channel_getFromElement(), tpia_misc_get2d_xShared_yHistogram_data(), tpia_misc_get2dx_y_data(), tpia_misc_get2dxindex_y_data(), tpia_misc_getEqualProbableBin(), tpia_target_heated_read(), and xData_getElements_xDataElement().

◆ xData_initializeAttributionList()

int xData_initializeAttributionList ( statusMessageReporting smr,
xData_attributionList attributes 
)

Definition at line 554 of file xData.cc.

554 {
555
556 attributes->number = 0;
557 attributes->size = 0;
558 attributes->attributes = NULL;
559 return( 0 );
560}

◆ xData_is_xDataType()

int xData_is_xDataType ( statusMessageReporting smr,
xDataType xDT,
char const *const  type,
int  setMsg 
)

Definition at line 900 of file xData.cc.

900 {
901
902 if( xDT->typeString == NULL ) {
903 if( setMsg ) smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( xDT->element ), __FILE__, __LINE__, 1,
904 "element %s not xData object", xDT->element->fullName ); }
905 else if( xDT->typeString != type ) {
906 if( setMsg ) smr_setMessageError( smr, xData_get_smrUserInterfaceFromElement( xDT->element ), __FILE__, __LINE__, 1,
907 "Element %s is not xData object of type %s", type );
908 }
909 return( xDT->typeString == type );
910}
xData_element * element
Definition: xData.h:157

Referenced by xData_is_1d_x(), xData_is_2d_xindex_y(), xData_is_2d_xShared_yHistogram(), xData_is_2d_xy(), and xData_is_matrix().

◆ xData_numberOfElementsByTagName()

int xData_numberOfElementsByTagName ( statusMessageReporting smr,
xData_element element,
const char *  tagName 
)

Definition at line 750 of file xData.cc.

750 {
751
752 int n = 0;
753 xData_element *child;
754
755 for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) if( !strcmp( child->name, tagName ) ) n++;
756 return( n );
757}

Referenced by tpia_target_heated_read(), and xData_getElementsByTagName().

◆ xData_parse()

int xData_parse ( xData_document doc,
const char *  s 
)

Definition at line 251 of file xData.cc.

251 {
252
253 if( doc->status != xData_statusParsing ) return( doc->status );
254 if( XML_Parse( doc->xmlParser, s, strlen( s ), 0 ) == XML_STATUS_ERROR ) return( -1 );
255 return( 0 );
256}
#define XML_STATUS_ERROR
Definition: include/expat.h:47
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
Definition: xmlparse.cc:1430
XML_Parser xmlParser
Definition: xData.h:207
enum xData_status status
Definition: xData.h:198
@ xData_statusParsing
Definition: xData.h:77

Referenced by xData_parseReadFile(), and xData_parseString().

◆ xData_parseEndOfXML()

int xData_parseEndOfXML ( statusMessageReporting smr,
xData_document doc 
)

Definition at line 187 of file xData.cc.

187 {
188
189 if( doc->xmlParser ) {
190 doc->err = XML_GetErrorCode( doc->xmlParser );
193 if( smr_isOk( smr ) && ( XML_Parse( doc->xmlParser, NULL, 0, 1 ) == XML_STATUS_ERROR ) ) {
196 "status = %d\nXML_Error code = %d\nXML_ErrorString = %s\nerror line, column = %d, %d", xData_errXMLParser,
197 doc->err, XML_ErrorString( doc->err ), doc->err_line, doc->err_column );
198 }
200 doc->xmlParser = NULL;
202 }
203 return( 0 );
204}
XML_GetErrorCode(XML_Parser parser)
Definition: xmlparse.cc:1755
XML_ParserFree(XML_Parser parser)
Definition: xmlparse.cc:1082
XML_ErrorString(enum XML_Error code)
Definition: xmlparse.cc:1848
int smr_isOk(statusMessageReporting *smr)
XML_Size err_line
Definition: xData.h:201
enum XML_Error err
Definition: xData.h:200
XML_Size err_column
Definition: xData.h:201
@ xData_statusError
Definition: xData.h:77
@ xData_statusCompleted
Definition: xData.h:77
@ xData_errXMLParser
Definition: xData.h:79
XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser parser)
Definition: xmlparse.cc:1800
XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser parser)
Definition: xmlparse.cc:1790

Referenced by xData_parseFree(), xData_parseReadFile(), and xData_parseString().

◆ xData_parseFree()

void * xData_parseFree ( statusMessageReporting smr,
xData_document doc 
)

Definition at line 208 of file xData.cc.

208 {
209
210 xData_parseEndOfXML( smr, doc );
211 //doc->root.children = xData_parseFreeElement( smr, doc->root.children );
212 doc->root.children = (xData_element*) xData_parseFreeElement( smr, doc->root.children );
213 //doc->fileName = xData_free( smr, doc->fileName );
214 doc->fileName = (char*) xData_free( smr, doc->fileName );
215 xData_smrUserInterfaceFree( doc );
216 xData_free( smr, doc );
217 return( NULL );
218}
int xData_parseEndOfXML(statusMessageReporting *smr, xData_document *doc)
Definition: xData.cc:187

Referenced by tpia_map_readFile(), tpia_target_heated_read(), tpia_target_read(), xData_parseMalloc(), xData_parseReadFile(), and xData_parseString().

◆ xData_parseInitialize()

int xData_parseInitialize ( statusMessageReporting smr,
xData_document doc,
xData_xDataTypeOk  func,
void *  userData 
)

Definition at line 157 of file xData.cc.

157 {
158
159 XML_Parser xmlParser;
160
162 doc->error = xData_errNone;
163 //doc->err = 0;
164 doc->err = (XML_Error) 0;
165 doc->err_line = 0;
166 doc->err_column = 0;
167 doc->fileName = NULL;
168 doc->xDataTypeOk_userFunction = func;
170 xData_smrUserInterfaceInitialize( doc );
171 doc->smr= smr;
172 doc->xmlParser = xmlParser = XML_ParserCreate( NULL );
173 if( xmlParser == NULL ) {
174 smr_setMessageError( smr, NULL, __FILE__, __LINE__, xData_errXML_ParserCreate, "XML_ParserCreate failed" ); }
175 else {
176 XML_SetUserData( doc->xmlParser, doc );
177 xData_parseInitializeRootElement( doc, &(doc->root), NULL, 0 );
178 doc->currentRoot = &(doc->root);
179 XML_SetElementHandler( xmlParser, xData_parseStartElement, xData_parseEndElement );
180 XML_SetCharacterDataHandler( xmlParser, xData_parseCharacterData );
181 }
182 return( !smr_isOk( smr ) );
183}
XML_ParserCreate(const XML_Char *encoding)
Definition: xmlparse.cc:658
XML_SetUserData(XML_Parser parser, void *userData)
Definition: xmlparse.cc:1173
XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
Definition: xmlparse.cc:1214
XML_Error
Definition: include/expat.h:54
XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler handler)
Definition: xmlparse.cc:1235
statusMessageReporting * smr
Definition: xData.h:206
void * xDataTypeOk_userData
Definition: xData.h:204
xData_rootElement * currentRoot
Definition: xData.h:209
xData_xDataTypeOk xDataTypeOk_userFunction
Definition: xData.h:203
enum xData_errorCodes error
Definition: xData.h:199
@ xData_errXML_ParserCreate
Definition: xData.h:78
@ xData_errNone
Definition: xData.h:78
#define userData
Definition: xmlparse.cc:555

Referenced by xData_parseMalloc().

◆ xData_parseIsError()

int xData_parseIsError ( xData_document doc)

Definition at line 469 of file xData.cc.

469 {
470
471 return( doc->status == xData_statusError );
472}

◆ xData_parseMalloc()

xData_document * xData_parseMalloc ( statusMessageReporting smr,
xData_xDataTypeOk  func,
void *  userData 
)

Definition at line 141 of file xData.cc.

141 {
142/*
143* Returns NULL is any error occurred.
144*/
145 xData_document *doc;
146
147 //if( ( doc = xData_malloc2( smr, sizeof( xData_document ), 1, "xData_document" ) ) != NULL ) {
148 if( ( doc = (xData_document*) xData_malloc2( smr, sizeof( xData_document ), 1, "xData_document" ) ) != NULL ) {
149 //if( xData_parseInitialize( smr, doc, func, userData ) ) doc = xData_parseFree( smr, doc );
150 if( xData_parseInitialize( smr, doc, func, userData ) ) doc = (xData_document*) xData_parseFree( smr, doc );
151 }
152 return( doc );
153}
int xData_parseInitialize(statusMessageReporting *smr, xData_document *doc, xData_xDataTypeOk func, void *userData)
Definition: xData.cc:157
void * xData_parseFree(statusMessageReporting *smr, xData_document *doc)
Definition: xData.cc:208

Referenced by xData_parseReadFile(), and xData_parseString().

◆ xData_parseReadFile()

xData_document * xData_parseReadFile ( statusMessageReporting smr,
const char *  fileName,
xData_xDataTypeOk  func,
void *  userData 
)

Definition at line 84 of file xData.cc.

84 {
85/*
86* Returns NULL is any error occurred. If an error occurs in an expat routine, xData_parseEndOfXML will set smr appropriately.
87*/
88 int f;
89 char buffer[10 * 1000];
90 ssize_t count, n = sizeof( buffer ) - 1;
91 ssize_t s = 0;
92 xData_document *doc = NULL;
93
94 if( ( doc = xData_parseMalloc( smr, func, userData ) ) != NULL ) {
95 if( xData_setFileName( smr, doc, fileName ) == 0 ) {
96 f = open( fileName, O_RDONLY );
97 if( f == -1 ) {
98 xData_parseEndOfXML( smr, doc );
99 smr_setMessageError( smr, NULL, __FILE__, __LINE__, xData_errFileError, "could not open file %s", fileName ); }
100 else {
101 while( ( count = read( f, buffer, n ) ) > 0 ) {
102 s += count;
103 buffer[count] = 0;
104 if( xData_parse( doc, buffer ) ) break;
105 if( !smr_isOk( doc->smr ) ) break;
106 }
107 close( f );
108 xData_parseEndOfXML( smr, doc );
109 if( count < 0 ) smr_setMessageError( smr, NULL, __FILE__, __LINE__, xData_errFileError,
110 "read failed with errno = %d for %s", errno, fileName );
111 }
112 }
113 if( ( doc != NULL ) && ( !smr_isOk( smr ) ) ) {
114 xData_parseFree( smr, doc );
115 doc = NULL;
116 }
117 }
118 return( doc );
119}
int xData_parse(xData_document *doc, const char *s)
Definition: xData.cc:251
int xData_setFileName(statusMessageReporting *smr, xData_document *doc, char const *fileName)
Definition: xData.cc:921
xData_document * xData_parseMalloc(statusMessageReporting *smr, xData_xDataTypeOk func, void *userData)
Definition: xData.cc:141
@ xData_errFileError
Definition: xData.h:78
#define buffer
Definition: xmlparse.cc:611

Referenced by tpia_map_readFile(), tpia_target_heated_read(), and tpia_target_read().

◆ xData_parseString()

xData_document * xData_parseString ( statusMessageReporting smr,
const char *  str,
xData_xDataTypeOk  func,
void *  userData 
)

Definition at line 123 of file xData.cc.

123 {
124/*
125* Returns NULL is any error occurred. If an error occurs in an expat routine, xData_parseEndOfXML will set smr appropriately.
126*/
127 xData_document *doc = NULL;
128 if( ( doc = xData_parseMalloc( smr, func, userData ) ) != NULL ) {
129 xData_parse( doc, str );
130 xData_parseEndOfXML( smr, doc );
131 if( !smr_isOk( smr ) ) {
132 xData_parseFree( smr, doc );
133 doc = NULL;
134 }
135 }
136 return( doc );
137}

◆ xData_releaseAttributionList()

int xData_releaseAttributionList ( statusMessageReporting smr,
xData_attributionList attributes 
)

Definition at line 611 of file xData.cc.

611 {
612
613 attributes->number = 0;
614 attributes->size = 0;
615 //attributes->attributes = xData_free( smr, attributes->attributes );
616 attributes->attributes = (xData_attribute*) xData_free( smr, attributes->attributes );
617 return( 0 );
618}

Referenced by tpia_channel_release(), tpia_product_release(), tpia_target_heated_release(), and tpia_target_release().

◆ xData_setFileName()

int xData_setFileName ( statusMessageReporting smr,
xData_document doc,
char const fileName 
)

Definition at line 921 of file xData.cc.

921 {
922
923 doc->fileName = (char*) xData_free( smr, doc->fileName );
924 if( fileName != NULL ) {
925 //if( ( doc->fileName = xData_malloc2( smr, strlen( fileName ) + 1, 0, "doc->fileName" ) ) == NULL ) return( 1 );
926 if( ( doc->fileName = (char*) xData_malloc2( smr, strlen( fileName ) + 1, 0, "doc->fileName" ) ) == NULL ) return( 1 );
927 strcpy( doc->fileName, fileName );
928 }
929 return( 0 );
930}

Referenced by xData_parseReadFile().

◆ xData_stringTo_double()

int xData_stringTo_double ( statusMessageReporting smr,
void *  smrUserInterface,
char const c,
double *  value,
char const endings,
char **  e 
)

Definition at line 1044 of file xData.cc.

1044 {
1045
1046 char const *s;
1047 char tmp[64];
1048 int status = 1, n = sizeof( tmp );
1049
1050 for( s = c; *s != 0; s++ ) if( !isspace( *s ) ) break;
1051 *value = strtod( s, e );
1052 if( *e == s ) {
1053 smr_setMessageError(smr, smrUserInterface, __FILE__, __LINE__, 1, "could not convert \"%s\" to an double", xData_shortStringForMessage( n, tmp, c ));}
1054 else {
1055 if( *endings == 0 ) while( isspace( **e ) ) (*e)++;
1056 if( **e == 0 ) {
1057 status = 0; }
1058 else {
1059 if( *endings == 0 ) {
1060 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1, "double string \"%s\" does not end with a '\\0'",
1061 xData_shortStringForMessage( n, tmp, c ) ); }
1062 else {
1063 if( strchr( endings, **e ) == NULL ) {
1064 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1, "double string \"%s\" does not end with a white space or a '\\0\'",
1065 xData_shortStringForMessage( n, tmp, c ) ); }
1066 else {
1067 status = 0;
1068 }
1069 }
1070 }
1071 }
1072 return( status );
1073}

◆ xData_stringTo_xData_Int()

int xData_stringTo_xData_Int ( statusMessageReporting smr,
void *  smrUserInterface,
char const c,
xData_Int value,
char const endings,
char **  e 
)

Definition at line 1010 of file xData.cc.

1010 {
1011
1012 char const *s;
1013 char tmp[64];
1014 int status = 1, n = sizeof( tmp );
1015
1016 for( s = c; *s != 0; s++ ) if( !isspace( *s ) ) break;
1017 //*value = strtoll( s, e, 10 );
1018 *value = strtol( s, e, 10 );
1019 if( *e == s ) {
1020 smr_setMessageError(smr, smrUserInterface, __FILE__, __LINE__, 1, "could not convert \"%s\" to an integer", xData_shortStringForMessage( n, tmp, c ));}
1021 else {
1022 if( *endings == 0 ) while( isspace( **e ) ) (*e)++;
1023 if( **e == 0 ) {
1024 status = 0; }
1025 else {
1026 if( *endings == 0 ) {
1027 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1, "integer string \"%s\" does not end with a '\\0'",
1028 xData_shortStringForMessage( n, tmp, c ) ); }
1029 else {
1030 if( strchr( endings, **e ) == NULL ) {
1031 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1, "integer string \"%s\" does not end with a white space or a '\\0\'",
1032 xData_shortStringForMessage( n, tmp, c ) ); }
1033 else {
1034 status = 0;
1035 }
1036 }
1037 }
1038 }
1039 return( status );
1040}

◆ xData_xDataTypeConvertAttributes()

int xData_xDataTypeConvertAttributes ( statusMessageReporting smr,
xData_element element 
)

Definition at line 668 of file xData.cc.

668 {
669
670 xDataType *xDT = &(element->xDataTypeInfo);
671 void *smrUser = xData_get_smrUserInterfaceFromElement( element );
672
673 xDT->index = -1;
674 xDT->start = -1;
675 xDT->end = -1;
676 xDT->length = -1;
677 if( ( xDT->indexPresent = xData_convertAttributeTo_xData_Int( smr, element, "index", &(xDT->index) ) ) < 0 ) return( 1 );
678 if( ( xDT->startPresent = xData_convertAttributeTo_xData_Int( smr, element, "start", &(xDT->start) ) ) < 0 ) return( 1 );
679 if( ( xDT->endPresent = xData_convertAttributeTo_xData_Int( smr, element, "end", &(xDT->end) ) ) < 0 ) return( 1 );
680 if( ( xDT->lengthPresent = xData_convertAttributeTo_xData_Int( smr, element, "length", &(xDT->length) ) ) < 0 ) return( 1 );
681 if( ( xDT->endPresent > 0 ) ) {
682 if( xDT->lengthPresent > 0 ) {
683 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1, "missing length (or end) in xData" );
684 return( 1 );
685 }
686 xDT->end = xDT->length; }
687 else {
688 if( xDT->lengthPresent > 0 ) xDT->length = xDT->end;
689 }
690
691 if( xDT->startPresent > 0 ) xDT->start = 0;
692 if( xDT->start < 0 ) {
693 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1, "start = %d < 0", xDT->start );
694 return( 1 );
695 }
696 if( xDT->end < xDT->start ) {
697 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1, "start = %d >= end = %d", xDT->start, xDT->end );
698 return( 1 );
699 }
700 if( xDT->length < 0 ) {
701 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1, "length = %d < 0", xDT->length );
702 return( 1 );
703 }
704
705 return( 0 );
706}
signed char startPresent
Definition: xData.h:161
signed char lengthPresent
Definition: xData.h:161
signed char indexPresent
Definition: xData.h:161
signed char endPresent
Definition: xData.h:161
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
Definition: xData.cc:710

Referenced by xData_init_1d_x(), xData_init_2d_xindex_y(), xData_init_2d_xShared_yHistogram(), xData_init_2d_xy(), and xData_init_matrix().