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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : /**
       4             :  * \mainpage LibGrML
       5             :  * Library to help developper to read and/or write model using GrML syntax.
       6             :  * \author   Clément Démoulins
       7             :  */
       8             : 
       9             : #include <iostream>
      10             : #include <map>
      11             : #include <string>
      12             : //#ifdef __APPLE__
      13             : #include <memory>
      14             : //#else
      15             : //#include <tr1/memory>
      16             : //#endif
      17             : 
      18             : #include "tree/tree.hh"
      19             : #include <exception>
      20             : 
      21             : 
      22             : /** An exception throw when the parsing of an XML document fail. */
      23           0 : class GrmlInputException: public std::exception {
      24             : private:
      25             :     std::string msg;
      26             : public:
      27             :     GrmlInputException():msg(){};
      28           0 :     GrmlInputException(const std::string& msg):msg(msg){};
      29             :     
      30           0 :     virtual const char* what() const throw()
      31             :     {
      32           0 :         std::string error("The input GrML file could not be imported : ");
      33           0 :         error.append(msg);
      34           0 :         return std::move(error).c_str();
      35             :     }
      36             : };
      37             : 
      38             : 
      39             : // Types definitions
      40             : 
      41             : /** Type representing a string from an XML document. */
      42             : typedef std::string XmlString;
      43             : 
      44             : /** Type representing a GrML attribute element.
      45             :  * Ex:
      46             :  * <attribute name="declaration">
      47             :  *   <attribute name="classDeclaration">
      48             :  *     <attribute name="name">C1</attribute>
      49             :  *     <attribute name="classType">
      50             :  *       …
      51             :  *     </attribute>
      52             :  *   </attribute>
      53             :  * </attribute>
      54             :  *
      55             :  * saved in memory in this way :
      56             :  * + "declaration"
      57             :  *       + "classDeclaration"
      58             :  *           + "name"
      59             :  *               + "C1"
      60             :  *           + "classType"
      61             :  *               …
      62             :  */
      63             : typedef tree<XmlString> Attribute;
      64             : typedef tree<std::string>::sibling_iterator treeSI;
      65             : 
      66             : /** Type representing a map of Attribute. */
      67             : typedef std::map<XmlString, Attribute> AttributeMap;
      68             : 
      69             : /** Type representing a list of reference. */
      70             : typedef std::vector<XmlString> XmlStringList;
      71             : 
      72             : class ModelHandler;
      73             : /** Pointer to a model handler using std::shared_ptr */
      74             : typedef std::shared_ptr<ModelHandler> ModelHandlerPtr;
      75             : 
      76             : 
      77             : /**
      78             :  * Model handler interface. Implementation of this interface receive event
      79             :  * when parsing a GrML model.
      80             :  */
      81          52 : class ModelHandler
      82             : {
      83             : protected:
      84             :     /** Constructor */
      85             : //    ModelHandler();
      86             : 
      87             :     /** Descructor */
      88          52 :     virtual ~ModelHandler() {}
      89             : 
      90             : public:
      91             : 
      92             :     /**
      93             :      * Event raised when reading a model. This event raised before all other.
      94             :      * @param formalismUrl formalism of the model
      95             :      */
      96             :     virtual void on_read_model(const XmlString& formalismUrl) = 0;
      97             : 
      98             :     /**
      99             :      * Event raise when the parser read an attribute attach to the model.
     100             :      * @param attribute attribute
     101             :      */
     102             :     virtual void on_read_model_attribute(const Attribute& attribute) = 0;
     103             : 
     104             :     /**
     105             :      * Event raise when the parser read a node element
     106             :      * @param id identifier of the node
     107             :      * @param nodeType type of the node
     108             :      * @param attributes attributes attach to the node
     109             :      * @param references list of references
     110             :      */
     111             :     virtual void on_read_node(const XmlString& id,
     112             :             const XmlString& nodeType,
     113             :             const AttributeMap& attributes,
     114             :             const XmlStringList& references) = 0;
     115             : 
     116             :     /**
     117             :      * Event raise when the parser read an arc element
     118             :      * @param id identifier of the arc
     119             :      * @param arcType type of the arc
     120             :      * @param source node identifier of the source of the arc
     121             :      * @param target node identifier of the target of the arc
     122             :      * @param attributes attributes attach to the node
     123             :      * @param references list of references
     124             :      */
     125             :     virtual void on_read_arc(const XmlString& id,
     126             :             const XmlString& arcType,
     127             :             const XmlString& source,
     128             :             const XmlString& target,
     129             :             const AttributeMap& attributes,
     130             :             const XmlStringList& references) = 0;
     131             : };
     132             : 

Generated by: LCOV version 1.13