Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
2 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
#ifndef __TRADXML_H__
19
#define __TRADXML_H__
20
 
21
#include <stdio.h>
22
#include <string>
3 andreas 23
#include <iterator>
2 andreas 24
#include "terror.h"
25
#include "mxml.h"
26
 
27
class TReadXML
28
{
3 andreas 29
    public:
44 andreas 30
        TReadXML(const std::string& fname, bool trim=false);
3 andreas 31
        ~TReadXML();
2 andreas 32
 
3 andreas 33
        std::string& findElement(const std::string& name);
34
        std::string& findElement(const std::string& name, const std::string& attr);
35
        std::string& findElement(mxml_node_t *node, const std::string& name);
36
        std::string& findElement(mxml_node_t *node, const std::string& name, const std::string& attr);
37
        std::string& findNextElement(const std::string& name);
38
        std::string& findNextElement(const std::string& name, const std::string& attr);
39
        bool success() { return mValid; }
40
        std::string& getAttribute() { return mAttribute; }
41
        std::string& getAttribute(const std::string& name);
42
        std::string& getAttribute(const std::string& name, int index);
2 andreas 43
 
3 andreas 44
        std::string getText() { return mxmlGetText(mNode, 0); }
45
        int getInt() { return mxmlGetInteger(mNode); }
46
        double getDouble() { return mxmlGetReal(mNode); }
2 andreas 47
 
3 andreas 48
        mxml_node_t *getFirstChild();
49
        mxml_node_t *getNextChild();
50
        mxml_node_t *getLastChild();
51
 
52
        mxml_node_t *getFirstChild(mxml_node_t *node);
53
        mxml_node_t *getNextChild(mxml_node_t *node);
54
        mxml_node_t *getLastChild(mxml_node_t *node);
55
 
56
        std::string& getTextFromNode(mxml_node_t *n);
57
        int getIntFromNode(mxml_node_t *n);
58
        double getDoubleFromNode(mxml_node_t *n);
59
        std::string getAttributeFromNode(mxml_node_t *n, const std::string& attr);
60
        std::string& getElementName();
61
        std::string& getElementName(mxml_node_t *node);
62
        std::string& GetLastElementName() { return mElement; }
63
 
64
        mxml_node_t *getRoot() { return mTree; }
65
        mxml_node_t *getNode() { return mNode; }
66
        mxml_node_t *getLastNode() { return mLastNode; }
67
 
2 andreas 68
	protected:
44 andreas 69
        bool openFile(bool trim=false);
3 andreas 70
        void extractValue(mxml_node_t *n);
2 andreas 71
 
72
	private:
3 andreas 73
        TReadXML() {}
74
        std::string _typeName(mxml_type_t t);   // For internal debugging only!
75
 
76
        std::string mFName;             // The path and file name of the XML to parse
77
        mxml_node_t *mTree{0};          // The root of the tree
78
        mxml_node_t *mNode{0};          // The actual node
79
        mxml_node_t *mLastNode{0};      // The previous node, if any
80
        mxml_node_t *inode{0};          // Used internal for "iterating"
81
        std::string mValue;             // The content of last search
82
        std::string mAttribute;         // The last attribute found
83
        std::string mElement;           // The name of the current element
84
        bool mValid{false};             // TRUE = Last search was successfull
2 andreas 85
};
86
 
87
#endif