LCOV - code coverage report
Current view: top level - builds/barbot/Cosmos/src/libgrml - expatmodelparser.hh (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 2 0.0 %
Date: 2021-06-16 15:43:28 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <iostream>
       4             : #include <istream>
       5             : #include <fstream>
       6             : #include <map>
       7             : #include <stack>
       8             : #include <string>
       9             : #include <algorithm>
      10             : #include <functional>
      11             : #include <locale>
      12             : 
      13             : #include <expat.h>
      14             : 
      15             : #include "tree/tree.hh"
      16             : #include "modelhandler.hh"
      17             : 
      18             : #define BUFFER_SIZE 10240
      19             : 
      20             : enum parser_state
      21             : {
      22             :     MODEL,
      23             :     NODE,
      24             :     ARC,
      25             :     ATTRIBUTE
      26             : };
      27             : 
      28           0 : class IOError: public std::runtime_error
      29             : {
      30             : public:
      31             :     IOError(std::string message) throw();
      32             : };
      33             : 
      34             : 
      35           0 : class ExpatError: public std::runtime_error
      36             : {
      37             : private:
      38             :     XML_Error error_code;
      39             : 
      40             : public:
      41             :     ExpatError(XML_Error error_code) throw();
      42             :     const char* what() const throw();
      43             : };
      44             : 
      45             : 
      46             : /**
      47             :  * Parser of model using expat library.
      48             :  * This parser can read a GrML file or a standard input stream.
      49             :  */
      50             : class ExpatModelParser
      51             : {
      52             : private:
      53             :     ModelHandlerPtr handler;
      54             :     XML_Parser parser;
      55             :     XmlString xmlData;
      56             : 
      57             :     // Stack of state of the parser
      58             :     std::stack<parser_state> state;
      59             : 
      60             :     // Temporary stored parsed data
      61             :     XmlString id, type, source, target;
      62             :     Attribute attribute;
      63             :     Attribute::iterator attributeIterator;
      64             :     AttributeMap attributes;
      65             :     XmlStringList references;
      66             : 
      67             :     // Expat functions
      68             :     static void on_start_element(void *userData, const XML_Char *name, const XML_Char **atts);
      69             :     static void on_end_element(void *userData, const XML_Char *name);
      70             :     static void on_characters(void *userData, const XML_Char *s, int len);
      71             : 
      72             : public:
      73             :     /**
      74             :      * Constructor
      75             :      * @param h pointer to a model handler.
      76             :      */
      77             :     ExpatModelParser(ModelHandlerPtr h);
      78             :     ~ExpatModelParser();
      79             : 
      80             :     /**
      81             :      * Parse a file.
      82             :      * @param filename path to the file
      83             :      */
      84             :     void parse_file(const std::string& filename);
      85             : 
      86             :     /**
      87             :      * Parse from an input stream
      88             :      * @param in input stream
      89             :      */
      90             :     void parse_stream(std::istream& in);
      91             : 
      92             :     /**
      93             :      * Trim a string
      94             :      * @param s the string
      95             :      */
      96             :     static void trim(std::string& s);
      97             : 
      98             : };

Generated by: LCOV version 1.13