Skip to content

Commit

Permalink
xml.lite tweaks from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 14, 2021
1 parent 813be14 commit 3610f8e
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <string>
#include <vector>
#include <tuple>

#include "sys/Conf.h"
#include "except/Exception.h"
Expand Down Expand Up @@ -60,9 +59,7 @@ class AttributeNode
public:

//! Constructor
AttributeNode()
{
}
AttributeNode() = default;

/*!
* Copy constructor
Expand All @@ -79,9 +76,7 @@ class AttributeNode
AttributeNode& operator=(const AttributeNode& attributeNode);

//! Destructor
~AttributeNode()
{
}
~AttributeNode() = default;

/*!
* This function takes a fully qualified name.
Expand All @@ -90,6 +85,7 @@ class AttributeNode
* \param qname The fully qualified name
*/
void setQName(const std::string& qname);
void setQName(const xml::lite::QName& qname);

/*!
* Set the local (unqualified portion) of the name
Expand All @@ -108,7 +104,11 @@ class AttributeNode
* Set the URI association in the QName
* \param uri The new uri
*/
void setUri(const std::string& uri);
void setUri(const xml::lite::Uri&);
void setUri(const std::string& uri)
{
setUri(Uri(uri));
}

/*!
* Set the attribute value
Expand All @@ -122,6 +122,7 @@ class AttributeNode
* \return The uri
*/
std::string getUri() const;
void getUri(xml::lite::Uri&) const;
std::string getLocalName() const;
std::string getPrefix() const;
std::string getValue() const;
Expand All @@ -130,6 +131,7 @@ class AttributeNode
return mValue;
}
std::string getQName() const;
void getQName(xml::lite::QName&) const;

protected:

Expand All @@ -151,15 +153,11 @@ class AttributeNode
* this data structure everywhere. That also allows us to
* simplify future dom classes
*/
class Attributes
struct Attributes final
{
public:

typedef std::vector<AttributeNode> Attributes_T;
//! Default constructor
Attributes()
{
}
Attributes() = default;

//! Copy constructor
Attributes(const Attributes & attributes);
Expand All @@ -168,9 +166,7 @@ class Attributes
Attributes & operator=(const Attributes & attributes);

//! Destructor
~Attributes()
{
}
~Attributes() = default;

/*!
* Adds an attribute to the list of attributes.
Expand Down Expand Up @@ -198,19 +194,23 @@ class Attributes
* \param localName The local name of the attribute
* \return the index or -1 if none found
*/
int getIndex(const std::string & uri, const std::string & localName) const;
int getIndex(const std::tuple<std::string, std::string>& name) const
int getIndex(const xml::lite::QName& name) const;
int getIndex(const std::string& uri, const std::string& localName) const
{
return getIndex(std::get<0>(name), std::get<1>(name));
return getIndex(QName(uri, localName));
}

/*!
* Return the number of attributes in the list.
* \return The number of attributes contained herein
*/
size_t size() const
{
return mAttributes.size();
}
int getLength() const
{
return (int) mAttributes.size();
return static_cast<int>(size());
}

/*!
Expand All @@ -222,6 +222,7 @@ class Attributes
std::string getLocalName(int i) const;

std::string getQName(int i) const;
void getQName(int i, xml::lite::QName&) const;

/*!
* Look up an attribute's Namespace URI by index.
Expand All @@ -230,6 +231,7 @@ class Attributes
* \throw IndexOutOfRangeException if the index is out of range
*/
std::string getUri(int i) const;
void getUri(int i, xml::lite::Uri&) const;

/*!
* Look up an attribute's value by index.
Expand Down Expand Up @@ -268,10 +270,10 @@ class Attributes
* \return The value
* \throw NoSuchKeyException If the uri/localName is not found
*/
std::string getValue(const std::string & uri, const std::string & localName) const;
std::string getValue(const std::tuple<std::string, std::string>& name) const
std::string getValue(const xml::lite::QName&) const;
std::string getValue(const std::string & uri, const std::string & localName) const
{
return getValue(std::get<0>(name), std::get<1>(name));
return getValue(QName(uri, localName));
}

/*!
Expand All @@ -281,10 +283,10 @@ class Attributes
* \param result The value, if found
* \return If the uri/localName is not found or not
*/
bool getValue(const std::string& uri, const std::string& localName, std::string& result) const;
bool getValue(const std::tuple<std::string, std::string>& name, std::string& result) const
bool getValue(const xml::lite::QName&, std::string& result) const;
bool getValue(const std::string& uri, const std::string& localName, std::string& result) const
{
return getValue(std::get<0>(name), std::get<1>(name), result);
return getValue(QName(uri, localName), result);
}

/*!
Expand Down Expand Up @@ -472,23 +474,23 @@ template <typename ToType>
inline auto castValue(const Attributes& attributes, const std::string & uri, const std::string & localName, ToType toType)
-> decltype(toType(std::string()))
{
return castValue(attributes, std::make_tuple(uri, localName), toType);
return castValue(attributes, QName(uri, localName), toType);
}
template <typename T>
inline T getValue(const Attributes& attributes, const std::string & uri, const std::string & localName)
{
return getValue<T>(attributes, std::make_tuple(uri, localName));
return getValue<T>(attributes, QName(uri, localName));
}

template <typename T, typename ToType>
inline bool castValue(const Attributes& attributes, const std::string & uri, const std::string & localName, T& result, ToType toType)
{
return getValue(attributes, std::make_tuple(uri, localName), result, toType);
return getValue(attributes, QName(uri, localName), result, toType);
}
template <typename T>
inline bool getValue(const Attributes& attributes, const std::string & uri, const std::string & localName, T& result)
{
return getValue(attributes, std::make_tuple(uri, localName), result);
return getValue(attributes, QName(uri, localName), result);
}

/*!
Expand Down Expand Up @@ -563,21 +565,20 @@ inline bool setValue(Attributes& attributes, const std::string& qname, const T&
* \return If the uri/localName is not found or not
*/
template <typename T, typename ToString>
inline bool setValue(Attributes& attributes, const std::tuple<std::string, std::string>& name, const T& value,
ToString toString)
inline bool setValue(Attributes& attributes, const xml::lite::QName& name, const T& value, ToString toString)
{
return setValue_(attributes, name, value, toString);
}
template <typename T>
inline bool setValue(Attributes& attributes, const std::tuple<std::string, std::string>& name, const T& value)
inline bool setValue(Attributes& attributes, const xml::lite::QName& name, const T& value)
{
return setValue_(attributes, name, value, details::toString<T>);
}
template <typename T, typename ToString>
inline bool setValue(Attributes& attributes, const std::string & uri, const std::string & localName, const T& value,
ToString toString)
{
return setValue(attributes, std::make_tuple(uri, localName), value, toString);
return setValue(attributes, QName(uri, localName), value, toString);
}
template <typename T>
inline bool setValue(Attributes& attributes, const std::string & uri, const std::string & localName, const T& value)
Expand Down
Loading

0 comments on commit 3610f8e

Please sign in to comment.