]> git.sesse.net Git - vlc/blob - modules/stream_filter/dash/xml/Node.cpp
dash: XML: handle text nodes.
[vlc] / modules / stream_filter / dash / xml / Node.cpp
1 /*
2  * Node.cpp
3  *****************************************************************************
4  * Copyright (C) 2010 - 2011 Klagenfurt University
5  *
6  * Created on: Aug 10, 2010
7  * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
8  *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published
12  * by the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "Node.h"
29
30 #include <cassert>
31 #include <vlc_common.h>
32 #include <vlc_xml.h>
33
34 using namespace dash::xml;
35
36 const std::string   Node::EmptyString = "";
37
38 Node::Node() :
39     type( -1 )
40 {
41 }
42 Node::~Node ()
43 {
44     for(size_t i = 0; i < this->subNodes.size(); i++)
45         delete(this->subNodes.at(i));
46 }
47
48 const std::vector<Node*>&            Node::getSubNodes           () const
49 {
50     return this->subNodes;
51 }
52 void                                Node::addSubNode            (Node *node)
53 {
54     this->subNodes.push_back(node);
55 }
56 const std::string&                  Node::getName               () const
57 {
58     return this->name;
59 }
60 void                                Node::setName               (const std::string& name)
61 {
62     this->name = name;
63 }
64
65 const std::string&                  Node::getAttributeValue     (const std::string& key) const
66 {
67     std::map<std::string, std::string>::const_iterator  it = this->attributes.find( key );
68
69     if ( it != this->attributes.end() )
70         return it->second;
71     return EmptyString;
72 }
73
74 void                                Node::addAttribute          ( const std::string& key, const std::string& value)
75 {
76     this->attributes[key] = value;
77 }
78 std::vector<std::string>            Node::getAttributeKeys      () const
79 {
80     std::vector<std::string> keys;
81     std::map<std::string, std::string>::const_iterator it;
82
83     for(it = this->attributes.begin(); it != this->attributes.end(); ++it)
84     {
85         keys.push_back(it->first);
86     }
87     return keys;
88 }
89
90 bool                                Node::hasText               () const
91 {
92     return false;
93 }
94
95 const std::string&                         Node::getText               () const
96 {
97     if ( this->type == XML_READER_TEXT )
98         return this->text;
99     else
100     {
101         assert( this->subNodes.size() == 1 );
102         return this->subNodes[0]->getText();
103     }
104 }
105
106 void Node::setText(const std::string &text)
107 {
108     this->text = text;
109 }
110
111 const std::map<std::string,std::string>&   Node::getAttributes         () const
112 {
113     return this->attributes;
114 }
115
116 int Node::getType() const
117 {
118     return this->type;
119 }
120
121 void Node::setType(int type)
122 {
123     this->type = type;
124 }