Commit 329fde434a836aba90fc15dd11ea7bf136c210af
1 parent
e3a47b69
Add GXmlElement::has_attribute() method and correct tscalc flag handling in GModel.
Showing
6 changed files
with
111 additions
and
18 deletions
ChangeLog
| 1 | -2015-02-04 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2015-02-05 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Version 1.0.0 released |
| 4 | 4 | ======================== |
| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | Do not dump unqueried parameters (#1349) |
| 13 | 13 | Add GBilinear class |
| 14 | 14 | Add WCS projections (MOL) |
| 15 | + Add GXmlElement::has_attribute() method | |
| 15 | 16 | |
| 16 | 17 | |
| 17 | 18 | 2015-01-07 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | ... | ... |
NEWS
| ... | ... | @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.0.0 |
| 2 | 2 | |
| 3 | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | |
| 5 | -4 February 2015 | |
| 5 | +5 February 2015 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | 1. Introduction |
| ... | ... | @@ -93,7 +93,8 @@ bilinear interpolations within GammaLib. |
| 93 | 93 | |
| 94 | 94 | 14. XML module |
| 95 | 95 | -------------- |
| 96 | -None | |
| 96 | +The method GXmlElement::has_attribute() has been added to check whether an | |
| 97 | +XML element contains a given attribute. | |
| 97 | 98 | |
| 98 | 99 | |
| 99 | 100 | 15. VO module | ... | ... |
include/GXmlElement.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GXmlElement.hpp - XML element node class definition * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2014 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2015 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -61,15 +61,16 @@ public: |
| 61 | 61 | virtual void clear(void); |
| 62 | 62 | virtual GXmlElement* clone(void) const; |
| 63 | 63 | virtual std::string classname(void) const; |
| 64 | - const std::string& name(void) const { return m_name; } | |
| 65 | - void name(const std::string& name) { m_name=name; } | |
| 64 | + const std::string& name(void) const; | |
| 65 | + void name(const std::string& name); | |
| 66 | 66 | std::string attribute(const std::string& name) const; |
| 67 | 67 | void attribute(const std::string& name, const std::string& value); |
| 68 | + bool has_attribute(const std::string& name) const; | |
| 68 | 69 | void remove_attribute(const std::string& name); |
| 69 | - GXmlNode* parent(void) const { return m_parent; } | |
| 70 | - void parent(GXmlNode* node) { m_parent = node; } | |
| 70 | + GXmlNode* parent(void) const; | |
| 71 | + void parent(GXmlNode* parent); | |
| 71 | 72 | virtual void write(GUrl& url, const int& indent = 0) const; |
| 72 | - virtual NodeType type(void) const { return NT_ELEMENT; } | |
| 73 | + virtual NodeType type(void) const; | |
| 73 | 74 | virtual std::string print(const GChatter& chatter = NORMAL, |
| 74 | 75 | const int& indent = 0) const; |
| 75 | 76 | |
| ... | ... | @@ -100,4 +101,66 @@ std::string GXmlElement::classname(void) const |
| 100 | 101 | return ("GXmlElement"); |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + | |
| 105 | +/***********************************************************************//** | |
| 106 | + * @brief Return XML element name | |
| 107 | + * | |
| 108 | + * @return XML element name. | |
| 109 | + ***************************************************************************/ | |
| 110 | +inline | |
| 111 | +const std::string& GXmlElement::name(void) const | |
| 112 | +{ | |
| 113 | + return (m_name); | |
| 114 | +} | |
| 115 | + | |
| 116 | + | |
| 117 | +/***********************************************************************//** | |
| 118 | + * @brief Set XML element name | |
| 119 | + * | |
| 120 | + * @param[in] name XML element name. | |
| 121 | + ***************************************************************************/ | |
| 122 | +inline | |
| 123 | +void GXmlElement::name(const std::string& name) | |
| 124 | +{ | |
| 125 | + m_name = name; | |
| 126 | + return; | |
| 127 | +} | |
| 128 | + | |
| 129 | + | |
| 130 | +/***********************************************************************//** | |
| 131 | + * @brief Return parent of XML element | |
| 132 | + * | |
| 133 | + * @return Parent of XML element. | |
| 134 | + ***************************************************************************/ | |
| 135 | +inline | |
| 136 | +GXmlNode* GXmlElement::parent(void) const | |
| 137 | +{ | |
| 138 | + return (m_parent); | |
| 139 | +} | |
| 140 | + | |
| 141 | + | |
| 142 | +/***********************************************************************//** | |
| 143 | + * @brief Set parent of XML element | |
| 144 | + * | |
| 145 | + * @param[in] node Parent of XML element. | |
| 146 | + ***************************************************************************/ | |
| 147 | +inline | |
| 148 | +void GXmlElement::parent(GXmlNode* parent) | |
| 149 | +{ | |
| 150 | + m_parent = parent; | |
| 151 | + return; | |
| 152 | +} | |
| 153 | + | |
| 154 | + | |
| 155 | +/***********************************************************************//** | |
| 156 | + * @brief Return XML node type | |
| 157 | + * | |
| 158 | + * @return XML node type (NT_ELEMENT). | |
| 159 | + ***************************************************************************/ | |
| 160 | +inline | |
| 161 | +GXmlNode::NodeType GXmlElement::type(void) const | |
| 162 | +{ | |
| 163 | + return (NT_ELEMENT); | |
| 164 | +} | |
| 165 | + | |
| 103 | 166 | #endif /* GXMLELEMENT_HPP */ | ... | ... |
pyext/GXmlElement.i
| ... | ... | @@ -50,9 +50,10 @@ public: |
| 50 | 50 | void name(const std::string& name); |
| 51 | 51 | std::string attribute(const std::string& name) const; |
| 52 | 52 | void attribute(const std::string& name, const std::string& value); |
| 53 | + bool has_attribute(const std::string& name) const; | |
| 53 | 54 | void remove_attribute(const std::string& name); |
| 54 | 55 | GXmlNode* parent(void) const; |
| 55 | - void parent(GXmlNode* node); | |
| 56 | + void parent(GXmlNode* parent); | |
| 56 | 57 | virtual void write(GUrl& url, const int& indent = 0) const; |
| 57 | 58 | virtual NodeType type(void) const; |
| 58 | 59 | }; | ... | ... |
src/model/GModelSky.cpp
| ... | ... | @@ -666,16 +666,16 @@ void GModelSky::read(const GXmlElement& xml) |
| 666 | 666 | name(xml.attribute("name")); |
| 667 | 667 | |
| 668 | 668 | // Set model TS |
| 669 | - std::string ts = xml.attribute("ts"); | |
| 670 | - if (ts.length() > 0) { | |
| 669 | + if (xml.has_attribute("ts")) { | |
| 670 | + std::string ts = xml.attribute("ts"); | |
| 671 | 671 | this->ts(gammalib::todouble(ts)); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - // Check flag if TS value should be computed | |
| 675 | - bool tscalc = (xml.attribute("tscalc") == "1") ? true : false; | |
| 676 | - | |
| 677 | - // Set flag if TS value should be computed | |
| 678 | - this->tscalc(tscalc); | |
| 674 | + // Set TS computation flag | |
| 675 | + if (xml.has_attribute("tscalc")) { | |
| 676 | + bool tscalc = (xml.attribute("tscalc") == "1") ? true : false; | |
| 677 | + this->tscalc(tscalc); | |
| 678 | + } | |
| 679 | 679 | |
| 680 | 680 | // Set instruments |
| 681 | 681 | instruments(xml.attribute("instrument")); | ... | ... |
src/xml/GXmlElement.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GXmlElement.cpp - XML element node class implementation * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2015 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -264,6 +264,33 @@ void GXmlElement::attribute(const std::string& name, const std::string& value) |
| 264 | 264 | |
| 265 | 265 | |
| 266 | 266 | /***********************************************************************//** |
| 267 | + * @brief Check if element has a given attribute | |
| 268 | + * | |
| 269 | + * @param[in] name Attribute name. | |
| 270 | + * @return True if attribute exists, false otherwise. | |
| 271 | + * | |
| 272 | + * Checks whether the element contains an attribute with @p name. If the | |
| 273 | + * attribute was found true is returned, false otherwise. | |
| 274 | + ***************************************************************************/ | |
| 275 | +bool GXmlElement::has_attribute(const std::string& name) const | |
| 276 | +{ | |
| 277 | + // Initialise found flag | |
| 278 | + bool found = false; | |
| 279 | + | |
| 280 | + // Search attribute value in list of attributes | |
| 281 | + for (int i = 0; i < m_attr.size(); ++i) { | |
| 282 | + if (m_attr[i]->name() == name) { | |
| 283 | + found = true; | |
| 284 | + break; | |
| 285 | + } | |
| 286 | + } | |
| 287 | + | |
| 288 | + // Return found flag | |
| 289 | + return found; | |
| 290 | +} | |
| 291 | + | |
| 292 | + | |
| 293 | +/***********************************************************************//** | |
| 267 | 294 | * @brief Remove attribute from element |
| 268 | 295 | * |
| 269 | 296 | * @param[in] name Attribute name. | ... | ... |