A library for working with phylogenetic and population genetic data.
v0.27.0
xml/document.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
33 #include <stdexcept>
34 
35 namespace genesis {
36 namespace utils {
37 
38 // =================================================================================================
39 // Converter Functions
40 // =================================================================================================
41 
48 {
49  if (v->type() != XmlValue::kComment) {
50  throw std::domain_error(
51  "Invalid conversion from XmlValue::" + v->type_to_string() + " to XmlValue::Comment."
52  );
53  }
54  return static_cast<XmlComment*> (const_cast<XmlValue*> (v));
55 }
56 
63 {
64  if (v->type() != XmlValue::kMarkup) {
65  throw std::domain_error(
66  "Invalid conversion from XmlValue::" + v->type_to_string() + " to XmlValue::Markup."
67  );
68  }
69  return static_cast<XmlMarkup*> (const_cast<XmlValue*> (v));
70 }
71 
78 {
79  if (v->type() != XmlValue::kElement) {
80  throw std::domain_error(
81  "Invalid conversion from XmlValue::" + v->type_to_string() + " to XmlValue::Element."
82  );
83  }
84  return static_cast<XmlElement*> (const_cast<XmlValue*> (v));
85 }
86 
87 } // namespace utils
88 } // namespace genesis
genesis::utils::XmlValue::type
Type type() const
Definition: xml/document.hpp:75
genesis::utils::XmlValue::kComment
@ kComment
Definition: xml/document.hpp:55
genesis::utils::XmlValue
Definition: xml/document.hpp:51
genesis::utils::xml_value_to_element
const XmlElement * xml_value_to_element(const XmlValue *v)
Converts a pointer to an XmlValue to XmlElement if appropriate.
Definition: xml/document.cpp:77
genesis::utils::XmlElement
Definition: xml/document.hpp:149
genesis::utils::xml_value_to_comment
const XmlComment * xml_value_to_comment(const XmlValue *v)
Converts a pointer to an XmlValue to XmlComment if appropriate.
Definition: xml/document.cpp:47
genesis::utils::XmlComment
Definition: xml/document.hpp:117
genesis::utils::XmlValue::kElement
@ kElement
Definition: xml/document.hpp:57
genesis::utils::XmlMarkup
Definition: xml/document.hpp:133
genesis::utils::XmlValue::type_to_string
static std::string type_to_string(const Type t)
Definition: xml/document.hpp:60
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::xml_value_to_markup
const XmlMarkup * xml_value_to_markup(const XmlValue *v)
Converts a pointer to an XmlValue to XmlMarkup if appropriate.
Definition: xml/document.cpp:62
document.hpp
A collection of classes for working with XML documents. See XmlDocument for more.
genesis::utils::XmlValue::kMarkup
@ kMarkup
Definition: xml/document.hpp:56