Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:31:07

0001 #ifndef __XRDXMLREADER_HH__
0002 #define __XRDXMLREADER_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d X m l R e a d e r . h h                        */
0006 /*                                                                            */
0007 /* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031   
0032 //-----------------------------------------------------------------------------
0033 //! The XrdXmlReader object provides a virtual interface to read xml files,
0034 //! irrespective of the underlying mplementation. Obtain an XML reader using
0035 //! GetRead(). You may also wish to call Init() prior to obtaining a reader
0036 //! in multi-threader applications. As some implementations may not be MT-safe.
0037 //! See GetReader() for more information.
0038 //-----------------------------------------------------------------------------
0039 
0040 class XrdXmlReader
0041 {
0042 public:
0043 
0044 //-----------------------------------------------------------------------------
0045 //! Get attributes from an XML tag. GetAttributes() should only be called after
0046 //! a successful GetElement() call.
0047 //!
0048 //! @param  aname    Pointer to an array of attribute names whose values are
0049 //!                  to be returned. The last entry in the array must be nil.
0050 //!
0051 //! @param  aval     Pointer to an array where the corresponding attribute
0052 //!                  values are to be placed in 1-to-1 correspondence. The
0053 //!                  values must be freed using free().
0054 //!
0055 //! @return true     One or more attributes have been returned.
0056 //!         false    No specified attributes were found.
0057 //-----------------------------------------------------------------------------
0058 
0059 virtual bool    GetAttributes(const char **aname, char **aval)=0;
0060 
0061 //-----------------------------------------------------------------------------
0062 //! Find an XML tag element.
0063 //!
0064 //! @param  ename    Pointer to an array of tag names any of which should be
0065 //!                  searched for. The last entry in the array must be nil.
0066 //!                  The first element of the array should contain the name of
0067 //!                  the context tag. Elements are searched only within the
0068 //!                  scope of that tag. When searching for the first desired
0069 //!                  tag, use a null string to indicate document scope.
0070 //!
0071 //! @param  reqd     When true one of the tag elements listed in ename must be
0072 //!                  found otherwise an error is generated.
0073 //!
0074 //! @return =0       No specified tag was found. Note that this corresponds to
0075 //!                  encountering the tag present in ename[0], i.e. scope end.
0076 //!         >0       A tag was found, the return value is the index into ename
0077 //!                  that corresponds to the tag's name.
0078 //-----------------------------------------------------------------------------
0079 
0080 virtual int     GetElement(const char **ename, bool reqd=false)=0;
0081 
0082 //-----------------------------------------------------------------------------
0083 //! Get the description of the last error encountered.
0084 //!
0085 //! @param  ecode    The error code associated with the error.
0086 //!
0087 //! @return Pointer to text describing the error. The text may be destroyed on a
0088 //!         subsequent call to any other method. Otherwise it is stable. A nil
0089 //!         pointer indicates that no error is present.
0090 //-----------------------------------------------------------------------------
0091 virtual
0092 const char     *GetError(int &ecode)=0;
0093 
0094 //-----------------------------------------------------------------------------
0095 //! Get a reader object to parse an XML file.
0096 //!
0097 //! @param  fname    Pointer to the filepath of the file to be parsed.
0098 //!
0099 //! @param  enc      Pointer to the encoding specification. When nil, UTF-8 is
0100 //!                  used. Currently, this parameter is ignored.
0101 //!
0102 //! @param  impl     Pointer to the desired implementation. When nil, the
0103 //!                  default implementation, tinyxml, is used. The following
0104 //!                  are supported
0105 //!
0106 //!                  tinyxml   - builtin xml reader. Each instance is independent
0107 //!                              Since it builds a full DOM tree in memory, it
0108 //!                              is only good for small amounts of xml. Certain
0109 //!                              esoteric xml features are not supported.
0110 //!
0111 //!                  libxml2   - full-fledged xml reader. Instances are not
0112 //!                              independent if multiple uses involve setting
0113 //!                              callbacks, allocators, or I/O overrides. For
0114 //!                              MT-safeness, it must be initialized in the
0115 //!                              main thread (see Init() below). It is used in
0116 //!                              streaming mode and is good for large documents.
0117 //!
0118 //!
0119 //! @return !0       Pointer to an XML reader object.
0120 //! @return =0       An XML reader object could not be created; errno holds
0121 //!                  the error code of the reason.
0122 //-----------------------------------------------------------------------------
0123 static
0124 XrdXmlReader   *GetReader(const char *fname,
0125                           const char *enc=0, const char *impl=0);
0126 
0127 //-----------------------------------------------------------------------------
0128 //! Get the text portion of an XML tag element. GetText() should only be called
0129 //! after a successful call to GetElement() with a possibly intervening call
0130 //! to GetAttributes().
0131 //!
0132 //! @param  ename    Pointer to the corresponding tag name.
0133 //!
0134 //! @param  reqd     When true text must exist and not be null. Otherwise, an
0135 //!                  error is generated if the text is missing or null.
0136 //!
0137 //! @return =0       No text found.
0138 //! @return !0       Pointer  to the tag's text field. It must be free using
0139 //!                  free().
0140 //-----------------------------------------------------------------------------
0141 
0142 virtual char   *GetText(const char *ename, bool reqd=false)=0;
0143 
0144 //-----------------------------------------------------------------------------
0145 //! Preinitialze the desired implementation for future use. This is meant to be
0146 //! used in multi-threaded applications, as some implementation must be
0147 //! initialized using the main thread before spawning other threads. An exmaple
0148 //! is libxml2 which is generally MT-unsafe unles preinitialized.
0149 //!
0150 //! @param  impl     Pointer to the desired implementation. When nil, the
0151 //!                  default implementation is used. Currently, only "libxml2"
0152 //!                  and "tinyxml" are supported.
0153 //!
0154 //! @return true     Initialization suceeded.
0155 //! @return false    Initialization failed, errno has the reason.
0156 //-----------------------------------------------------------------------------
0157 
0158 static bool     Init(const char *impl=0);
0159 
0160 //-----------------------------------------------------------------------------
0161 //! Constructor & Destructor
0162 //-----------------------------------------------------------------------------
0163 
0164                 XrdXmlReader() {}
0165 virtual        ~XrdXmlReader() {}
0166 
0167 private:
0168 
0169 };
0170 #endif