LCOV - code coverage report
Current view: top level - shell/inc/internal - xml_parser.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 5 0.0 %
Date: 2014-11-03 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SHELL_INC_INTERNAL_XML_PARSER_HXX
      21             : #define INCLUDED_SHELL_INC_INTERNAL_XML_PARSER_HXX
      22             : 
      23             : #include <expat.h>
      24             : #include <stdexcept>
      25             : 
      26             : 
      27           0 : class xml_parser_exception : public std::runtime_error
      28             : {
      29             : public:
      30             : 
      31           0 :     xml_parser_exception(
      32             :         const std::string& error_msg,
      33             :         int error_code,
      34             :         int line_number,
      35             :         int column_number,
      36             :         long byte_index) :
      37             :         std::runtime_error(error_msg),
      38             :         error_code_(error_code),
      39             :         line_number_(line_number),
      40             :         column_number_(column_number),
      41           0 :         byte_index_(byte_index)
      42           0 :     {}
      43             : 
      44             :     int  error_code_;
      45             :     int  line_number_;
      46             :     int  column_number_;
      47             :     long byte_index_;
      48             : };
      49             : 
      50             : 
      51             : 
      52             : //  Simple wrapper around expat, the xml parser library
      53             : //  created by James Clark
      54             : 
      55             : class i_xml_parser_event_handler;
      56             : 
      57             : class xml_parser
      58             : {
      59             : public:
      60             :     xml_parser(const XML_Char* EncodingName = 0);
      61             : 
      62             :     ~xml_parser();
      63             : 
      64             :     /** Parse a XML data stream
      65             : 
      66             :         @param      pXmlData
      67             :                     Pointer to a buffer containing the xml data
      68             : 
      69             :         @param      Length
      70             :                     Length of the buffer containing the xml data
      71             : 
      72             :         @param      IsFinal
      73             :                     Indicates whether these are the last xml data
      74             :                     of an xml document to parse. For very large
      75             :                     xml documents it may be useful to read and
      76             :                     parse the document partially.
      77             : 
      78             :         @precond    XmlData must not be null
      79             : 
      80             :         @throws     SaxException
      81             :                     If the used Sax parser returns an error. The SaxException
      82             :                     contains detailed information about the error.  */
      83             :     void parse(const char* XmlData, size_t Length, bool IsFinal = true);
      84             : 
      85             :     /** Set a document handler
      86             : 
      87             :         @descr      A document handler implements the interface i_xml_parser_event_handler.
      88             :                     The document handler receive notifications of various events
      89             :                     from the sax parser for instance "start_document".
      90             : 
      91             :                     The client is responsible for the life time management of
      92             :                     the given document handler, that means the document handler
      93             :                     instance must exist until a new one was set or until the parser
      94             :                     no longer exist.
      95             : 
      96             :         @param      SaxDocumentHandler
      97             :                     The new document handler, may be null if not interessted in
      98             :                     sax parser events.
      99             : 
     100             :         @postcond   currently used document handler == pSaxDocumentHandler  */
     101             :     void set_document_handler(i_xml_parser_event_handler* event_handler);
     102             : 
     103             :     /** Returns the currently used document handler or null if
     104             :         no document handler was set before. */
     105           0 :     i_xml_parser_event_handler* get_document_handler() const { return document_handler_;}
     106             : private:
     107             : 
     108             :     void init();
     109             : 
     110             : private:
     111             :     i_xml_parser_event_handler* document_handler_;
     112             :     XML_Parser xml_parser_;
     113             : 
     114             : // prevent copy and assignment
     115             : private:
     116             :     xml_parser(const xml_parser&);
     117             :     xml_parser& operator=(const xml_parser&);
     118             : };
     119             : 
     120             : #endif
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10