xml.h

Go to the documentation of this file.
00001 #ifndef CTL_XML_H
00002 #define CTL_XML_H
00003 
00010 #include <stdio.h>
00011 #include <ctl/serial.h>
00012 
00014 #define XML_TAB_DEPTH   4
00015 
00017 #define CTL_LABEL_TYPE      szconst(char,"type")
00018 #define CTL_LABEL_MBRTYPE   szconst(char,"mbrtype")
00019 #define CTL_LABEL_COUNT     szconst(char,"count")
00020 
00021 
00028 typedef struct ctl_xmlwrite
00029 {
00030     ctl_gstring(char)* buff;
00031     FILE*           fp;     
00032     int             indent; 
00033     bool            pretty; 
00034 } ctl_xmlwrite;
00035 bool ctl_xmlwrite_begin( ctl_xmlwrite* self, ctl_gstring(char)* string );
00036 bool ctl_xmlwrite_create( ctl_xmlwrite* self, const char* szPath );
00037 void ctl_xmlwrite_close( ctl_xmlwrite* self );
00038 void ctl_xmlwrite_addheader( ctl_xmlwrite* self );
00039 void ctl_xmlwrite_newline( ctl_xmlwrite* self );
00040 void ctl_xmlwrite_indent( ctl_xmlwrite* self );
00041 void ctl_xmlwrite_outdent( ctl_xmlwrite* self );
00042 void ctl_xmlwrite_generaltag( ctl_xmlwrite* self, const char* type, const char* label );
00043 void ctl_xmlwrite_containertag( ctl_xmlwrite* self, const char* type, size_t count, const char* label );
00044 void ctl_xmlwrite_endtag( ctl_xmlwrite* self, const char* type, const char* label );
00045 void ctl_xmlwrite_string_char( ctl_xmlwrite* self, const char* begin, const char* end );
00046 void ctl_xmlwrite_string_wchar_t( ctl_xmlwrite* self, const wchar_t* begin, const wchar_t* end );
00047 
00048 
00055 struct ctl_xmlread;
00056 typedef void (*ctl_xmlread_exception)( const struct ctl_xmlread* xml, const char* reason, const char* szP0, const char* szP1 );
00061 typedef struct ctl_xmlread
00062 {
00063     ctl_xmlread_exception   except;     
00064     void*           exceptParam;
00065     const char*     szBegin;    
00066     const char*     szEnd;      
00067     const char*     szpCurr;    
00068     const char*     szpEnd;     
00069     const char*     szcCurr;    
00070     const char*     szcEnd;     
00071     bool            bRecursible;
00072 } ctl_xmlread;
00073 bool ctl_xmlread_init( ctl_xmlread* self, const char* begin, const char* end, ctl_xmlread_exception except, void* exceptParam );
00074 /* Navigate data */
00075 void ctl_xmlread_rewind( ctl_xmlread* self );
00076 bool ctl_xmlread_next( ctl_xmlread* self );
00077 bool ctl_xmlread_find( ctl_xmlread* self, const char* type );
00078 bool ctl_xmlread_findnext( ctl_xmlread* self, const char* type );
00079 bool ctl_xmlread_canrecurse( ctl_xmlread* self );
00080 bool ctl_xmlread_recurse( ctl_xmlread* newself, const ctl_xmlread* self );
00081 /* Get or compare tag's name */
00082 bool ctl_xmlread_getname( const ctl_xmlread* self, ctl_gstring(char)* str );
00083 bool ctl_xmlread_is( const ctl_xmlread* self, const char* str );
00084 /* Get translated contents of tag data */
00085 bool ctl_xmlread_getattribute( ctl_xmlread* self, ctl_gstring(char)* str, const char* label );
00086 bool ctl_xmlread_getattribute_int( ctl_xmlread* self, const char* label, int32* value );
00087 bool ctl_xmlread_getcontent( const ctl_xmlread* self, ctl_gstring(char)* str, bool eatWhite );
00088 bool ctl_xmlread_gettextbefore( const ctl_xmlread* self, ctl_gstring(char)* str, bool eatWhite );
00089 bool ctl_xmlread_gettextafter( const ctl_xmlread* self, ctl_gstring(char)* str, bool eatWhite );
00090 /* Get untranslated contents of tag data - much faster than above, for fields we don't expect to find filled with text stuff */
00091 bool ctl_xmlread_rawname( const ctl_xmlread* self, ctl_sconst(char)* str );
00092 bool ctl_xmlread_rawattribute( ctl_xmlread* self, ctl_sconst(char)* str, const char* label );
00093 bool ctl_xmlread_rawcontent( const ctl_xmlread* self, ctl_sconst(char)* str, bool eatWhite );
00094 bool ctl_xmlread_rawtextbefore( const ctl_xmlread* self, ctl_sconst(char)* str, bool eatWhite );
00095 bool ctl_xmlread_rawtextafter( const ctl_xmlread* self, ctl_sconst(char)* str, bool eatWhite );
00096 /* Some template generated stuff */
00097 bool ctl_xmlread_rawtextbefore( const ctl_xmlread* self, ctl_sconst(char)* str, bool eatWhite );
00098 bool ctl_xmlread_rawtextafter( const ctl_xmlread* self, ctl_sconst(char)* str, bool eatWhite );
00099 /* Translate a string of text in-place in its own buffer */
00100 const char* ctl_xmlread_translate_char( const ctl_xmlread* self, char* begin, const char* end, bool bEatWhite );
00101 const wchar_t* ctl_xmlread_translate_wchar_t( const ctl_xmlread* self, wchar_t* begin, const wchar_t* end, bool bEatWhite );
00102 
00104 void char_xml_write_string( const char* buff, size_t size, ctl_xmlwrite* xml, const char* label );
00105 void wchar_t_xml_write_string( const wchar_t* buff, size_t size, ctl_xmlwrite* xml, const char* label );
00106 
00108 void char_xml_write_gstring( ctl_gstring(char)* str, ctl_xmlwrite* xml, const char* label );
00109 void wchar_t_xml_write_gstring( ctl_gstring(wchar_t)* str, ctl_xmlwrite* xml, const char* label );
00110 
00112 bool char_xml_read_string( char* buff, size_t size, ctl_xmlread* self, const char* label );
00113 bool wchar_t_xml_read_string( wchar_t* buff, size_t size, ctl_xmlread* self, const char* label );
00114 
00116 bool char_xml_read_gstring( ctl_gstring(char)* str, ctl_xmlread* self, const char* label );
00117 bool wchar_t_xml_read_gstring( ctl_gstring(wchar_t)* str, ctl_xmlread* self, const char* label );
00118 
00119 /* XML Write a scalar/array of whatever type */
00120 #define DECL_scalar_write(type,char)            void ppConcat(type,_xml_write)( const type* p, ctl_xmlwrite* self, const char* label );
00121 #define DECL_scalar_write_array(type,char)      void ppConcat(type,_xml_write_array)( const type* p, size_t count, ctl_xmlwrite* self, const char* label );
00122 DEF_ENUMTYPES(DECL_scalar_write,char)
00123 DEF_ENUMTYPES(DECL_scalar_write_array,char)
00124 
00125 /* XML Read a scalar of whatever type */
00126 #define DECL_scalar_read(type,unused)           bool ppConcat(type,_xml_read)( type* p, ctl_xmlread* self, const char* label );
00127 #define DECL_scalar_read_array(type,unused)     bool ppConcat(type,_xml_read_array)( type* p, size_t count, ctl_xmlread* self, const char* label );
00128 DEF_ENUMTYPES(DECL_scalar_read,unused)
00129 DEF_ENUMTYPES(DECL_scalar_read_array,unused)
00130 #undef DECL_scalar_read
00131 #undef DECL_scalar_read_array
00132 
00133 /* XML save/restore raw data */
00134 void raw_xml_writebytes( const ctl_serial* serial, ctl_xmlwrite* xml, const char* label );
00135 bool raw_xml_readbytes( ctl_serial* serial, ctl_xmlread* self, const char* label );
00136 
00137 
00138 #endif /* CTL_XML_H */

Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6