os: turn Xml_node::Attribute to Xml_attribute
Moving the XML attribute class to the Genode namespace simplifies the API.
This commit is contained in:
parent
394fce110e
commit
e1b4408090
|
@ -17,14 +17,22 @@
|
|||
#include <util/token.h>
|
||||
#include <base/exception.h>
|
||||
|
||||
namespace Genode { class Xml_node; }
|
||||
namespace Genode {
|
||||
|
||||
class Xml_attribute;
|
||||
class Xml_node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Representation of an XML node
|
||||
* Representation of an XML-node attribute
|
||||
*
|
||||
* An attribute has the form 'name="value"'.
|
||||
*/
|
||||
class Genode::Xml_node
|
||||
class Genode::Xml_attribute
|
||||
{
|
||||
private:
|
||||
|
||||
/**
|
||||
* Scanner policy that accepts hyphens in identifiers
|
||||
*/
|
||||
|
@ -38,32 +46,6 @@ class Genode::Xml_node
|
|||
*/
|
||||
typedef ::Genode::Token<Scanner_policy_xml_identifier> Token;
|
||||
|
||||
/**
|
||||
* Forward declaration needed for befriending Tag with Attribut
|
||||
*/
|
||||
class Tag;
|
||||
|
||||
public:
|
||||
|
||||
/*********************
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
class Exception : public ::Genode::Exception { };
|
||||
class Invalid_syntax : public Exception { };
|
||||
class Nonexistent_sub_node : public Exception { };
|
||||
class Nonexistent_attribute : public Exception { };
|
||||
|
||||
|
||||
/**
|
||||
* Representation of an XML-node attribute
|
||||
*
|
||||
* An attribute has the form 'name="value"'.
|
||||
*/
|
||||
class Attribute
|
||||
{
|
||||
private:
|
||||
|
||||
Token _name;
|
||||
Token _value;
|
||||
|
||||
|
@ -84,7 +66,7 @@ class Genode::Xml_node
|
|||
* construct an 'Xml_attribute' from a token sequence via an
|
||||
* assignment from the leading 'Token'.
|
||||
*/
|
||||
Attribute(Token t) :
|
||||
Xml_attribute(Token t) :
|
||||
_name(t.eat_whitespace()), _value(_name.next().next())
|
||||
{
|
||||
if (_name.type() != Token::IDENT)
|
||||
|
@ -101,6 +83,14 @@ class Genode::Xml_node
|
|||
|
||||
public:
|
||||
|
||||
/*********************
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
class Invalid_syntax : public Exception { };
|
||||
class Nonexistent_attribute : public Exception { };
|
||||
|
||||
|
||||
/**
|
||||
* Return attribute type as null-terminated string
|
||||
*/
|
||||
|
@ -177,9 +167,42 @@ class Genode::Xml_node
|
|||
/**
|
||||
* Return next attribute in attribute list
|
||||
*/
|
||||
Attribute next() const { return Attribute(_next()); }
|
||||
Xml_attribute next() const { return Xml_attribute(_next()); }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Representation of an XML node
|
||||
*/
|
||||
class Genode::Xml_node
|
||||
{
|
||||
private:
|
||||
|
||||
typedef Xml_attribute::Token Token;
|
||||
|
||||
/**
|
||||
* Forward declaration needed for befriending Tag with Xml_attribute
|
||||
*/
|
||||
class Tag;
|
||||
|
||||
public:
|
||||
|
||||
/*********************
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
typedef Genode::Exception Exception;
|
||||
typedef Xml_attribute::Nonexistent_attribute Nonexistent_attribute;
|
||||
typedef Xml_attribute::Invalid_syntax Invalid_syntax;
|
||||
|
||||
class Nonexistent_sub_node : public Exception { };
|
||||
|
||||
|
||||
/**
|
||||
* Type definition for maintaining backward compatibility
|
||||
*/
|
||||
typedef Xml_attribute Attribute;
|
||||
|
||||
private:
|
||||
|
||||
class Tag
|
||||
|
@ -231,7 +254,7 @@ class Genode::Xml_node
|
|||
Token delimiter = _name.next();
|
||||
if (supposed_type != END)
|
||||
try {
|
||||
for (Attribute a = _name.next(); ; a = a._next())
|
||||
for (Xml_attribute a = _name.next(); ; a = a._next())
|
||||
delimiter = a._next();
|
||||
} catch (Nonexistent_attribute) { }
|
||||
|
||||
|
@ -303,7 +326,7 @@ class Genode::Xml_node
|
|||
/**
|
||||
* Return first attribute of tag
|
||||
*/
|
||||
Attribute attribute() const { return Attribute(_name.next()); }
|
||||
Xml_attribute attribute() const { return Xml_attribute(_name.next()); }
|
||||
};
|
||||
|
||||
class Comment
|
||||
|
@ -694,10 +717,10 @@ class Genode::Xml_node
|
|||
* \throw Nonexistent_attribute no such attribute exists
|
||||
* \return XML attribute
|
||||
*/
|
||||
Attribute attribute(unsigned idx) const
|
||||
Xml_attribute attribute(unsigned idx) const
|
||||
{
|
||||
/* get first attribute of the node */
|
||||
Attribute a = _start_tag.attribute();
|
||||
Xml_attribute a = _start_tag.attribute();
|
||||
|
||||
/* skip attributes until we reach the target index */
|
||||
for (; idx > 0; idx--)
|
||||
|
@ -713,10 +736,10 @@ class Genode::Xml_node
|
|||
* \throw Nonexistent_attribute no such attribute exists
|
||||
* \return XML attribute
|
||||
*/
|
||||
Attribute attribute(const char *type) const
|
||||
Xml_attribute attribute(const char *type) const
|
||||
{
|
||||
/* iterate, beginning with the first attribute of the node */
|
||||
for (Attribute a = _start_tag.attribute(); ; a = a.next())
|
||||
for (Xml_attribute a = _start_tag.attribute(); ; a = a.next())
|
||||
if (a.has_type(type))
|
||||
return a;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue