ParserDefinitionDecoder.hpp 2.29 KB
Newer Older
1 2 3 4
#ifndef PARSERDEFINITIONDECODER_HPP
#define PARSERDEFINITIONDECODER_HPP

#include <iostream>
Johnny Jazeix's avatar
Johnny Jazeix committed
5 6
#include <fstream>
#include <map>
7

8
#include "Definition.hpp"
Johnny Jazeix's avatar
Johnny Jazeix committed
9
#include "Line.hpp"
10

11 12 13 14 15 16 17
#define WARN_IF(condition, message) if (condition)	\
        std::cerr << message << std::endl;

#define DIE_IF(condition, message) if (condition){      \
        std::cerr << message << std::endl;              \
        return;}

Johnny Jazeix's avatar
Johnny Jazeix committed
18 19 20 21
/*!
 *
 * \class ParserDefinitionDecoder
 * \brief Parse the definitions of the trace and stock them.
Pascal Noisette's avatar
Pascal Noisette committed
22
 *
Johnny Jazeix's avatar
Johnny Jazeix committed
23
 */
Pascal Noisette's avatar
Pascal Noisette committed
24
class ParserDefinitionDecoder{
25

26
    /**
27
     * Reads line to find events definition
28 29
     *
     */
Pascal Noisette's avatar
Pascal Noisette committed
30

31
private:
Johnny Jazeix's avatar
Johnny Jazeix committed
32
    /*! \brief Hash table to retrive easily event in Parser Event. */
33
    std::map<unsigned int, Definition> _definitions;
34
    int _state;
35
    unsigned int _current_definition;
36 37
    static const int _OUT_A_DEFINITION = 0;
    static const int _IN_A_DEFINITION = 1;
Pascal Noisette's avatar
Pascal Noisette committed
38

39
public:
40 41 42 43
    /*!
     * \fn ParserDefinitionDecoder
     * \brief constructor
     */
44
    ParserDefinitionDecoder();
45 46 47 48 49

    /*!
     *  \fn definitions_number
     *  \return : the number of definitions in the map
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
50
    int definitions_number();
51 52

    /*!
53
     *  \fn store_definition(Line &)
54
     *  \param l the line to store.
55
     */
56
    void store_definition(Line &l);
57 58

    /*!
59 60
     *  \fn get_definition(unsigned int i)
     *  \param i : the unsigned integer matching the definition we want
61 62
     *  \return : the i-th definition
     */
63
    Definition &get_definition(unsigned int i);
64 65 66 67 68

    /*!
     *  \fn get_hash_table_of_definitions
     *  \return : the hash table of definitions
     */
69
    std::map<unsigned int,Definition> *get_hash_table_of_definitions();
70 71

    /*!
72
     *  \fn enter_definition(Line &line)
73
     *  \param line line
74
     */
Pascal Noisette's avatar
Pascal Noisette committed
75
    void enter_definition(Line &line);
76 77
 
    /*!
78
     *  \fn leave_definition(Line&line)
79
     *  \param line
80
     */
81
    void leave_definition(Line &line);
82 83

    /*!
84
     *  \fn add_field_to_definition(std::string& first_token, Line& line)
85 86
     *  \param first_token : the name of the file to parse
     *  \param line : the structure of data to fill
87 88 89 90 91 92 93 94
     */
    void add_field_to_definition(std::string& first_token, Line& line);

    /*! \fn print_definitions
     * \brief Print all the definitions. Useful for debug.
     */
    void print_definitions();

95 96 97
};

#endif // PARSERDEFINITIONDECODER_HPP