Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 86c1856
Author: Dan Smith <[email protected]>
Date:   Fri Dec 10 11:57:26 2021 -0500

    xml.lite tweaks from coda-oss

commit f21f79d
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 17:36:09 2021 -0500

    test_xmlParser might be be running in coda-oss

commit 3526cd0
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 16:09:17 2021 -0500

    "private" is part of name mangling

commit 351a45f
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 15:54:13 2021 -0500

    more xml.lite updates from coda-oss

commit 1c72ba2
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 15:15:34 2021 -0500

    trying to fine the right macro for SWIG

commit 8d6e11d
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 14:51:34 2021 -0500

    need updates to Python bindings too

commit e208dd4
Author: Dan Smith <[email protected]>
Date:   Thu Dec 9 14:41:12 2021 -0500

    xml.lite changes from coda-oss

commit 169df75
Author: Dan Smith <[email protected]>
Date:   Wed Dec 8 14:32:37 2021 -0500

    latest from coda-oss
  • Loading branch information
Dan Smith committed Dec 10, 2021
1 parent 25b83eb commit 01f811e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
48 changes: 46 additions & 2 deletions externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define __XML_LITE_ELEMENT_H__
#pragma once

#include <assert.h>

#include <memory>
#include <string>
#include <new> // std::nothrow_t
Expand Down Expand Up @@ -405,9 +407,9 @@ class Element
* Adds a child element to this element
* \param node the child element to add
*/
virtual void addChild(std::unique_ptr<Element>&& node);
virtual Element& addChild(std::unique_ptr<Element>&& node);
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
virtual void addChild(mem::auto_ptr<Element> node);
virtual Element& addChild(mem::auto_ptr<Element> node);
#endif

/*!
Expand Down Expand Up @@ -477,6 +479,9 @@ class Element
const std::string& formatter) const;
};

extern void create(const std::string& name, const std::string& uri, const std::string& value, Element& parent,
Element*& result);

#ifndef SWIG
// The (old) version of SWIG we're using doesn't like certain C++11 features.

Expand Down Expand Up @@ -535,6 +540,45 @@ inline void setValue(Element& element, const T& value)
{
setValue(element, value, details::toString<T>);
}

template <typename T, typename ToString>
inline Element& createElement(const std::string& name, const std::string& uri, const T& value, Element& parent,
ToString toString)
{
Element* retval;
xml::lite::create(name, uri, toString(value), parent, retval);
assert(retval != nullptr);
return *retval;
}
template<typename T>
inline Element& createElement(const std::string& name, const std::string& uri, const T& value, Element& parent)
{
return createElement(name, uri, value, parent, details::toString<T>);
}

template <typename T, typename ToString>
inline Element& createElement(const std::string& name, const std::string& uri, const sys::Optional<T>& v, Element& parent,
ToString toString)
{
return createElement(name, uri, v.value(), parent, toString);
}
template<typename T>
inline Element& createElement(const std::string& name, const std::string& uri, const sys::Optional<T>& v, Element& parent)
{
return createElement(name, uri, v.value(), parent);
}
template <typename T, typename ToString>
inline Element* createOptonalElement(const std::string& name, const std::string& uri, const sys::Optional<T>& v, Element& parent,
ToString toString)
{
return v.has_value() ? &createElement(name, uri, v, parent, toString) : nullptr;
}
template<typename T>
inline Element* createOptonalElement(const std::string& name, const std::string& uri, const sys::Optional<T>& v, Element& parent)
{
return v.has_value() ? &createElement(name, uri, v, parent) : nullptr;
}

#endif // SWIG

}
Expand Down
17 changes: 13 additions & 4 deletions externals/coda-oss/modules/c++/xml.lite/source/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,16 @@ void xml::lite::Element::addChild(xml::lite::Element * node)
node->setParent(this);
}

void xml::lite::Element::addChild(std::unique_ptr<xml::lite::Element>&& node)
xml::lite::Element& xml::lite::Element::addChild(std::unique_ptr<xml::lite::Element>&& node)
{
auto retval = node.get();
addChild(node.release());
return *retval;
}
#if CODA_OSS_autoptr_is_std // std::auto_ptr removed in C++17
void xml::lite::Element::addChild(mem::auto_ptr<xml::lite::Element> node)
xml::lite::Element& xml::lite::Element::addChild(mem::auto_ptr<xml::lite::Element> node)
{
addChild(std::unique_ptr<xml::lite::Element>(node.release()));
return addChild(std::unique_ptr<xml::lite::Element>(node.release()));
}
#endif

Expand Down Expand Up @@ -527,4 +529,11 @@ void xml::lite::Element::setCharacterData(const std::string& characters, StringE
void xml::lite::Element::setCharacterData(const sys::U8string& characters)
{
setCharacterData(str::c_str<std::string::const_pointer>(characters), StringEncoding::Utf8);
}
}

void xml::lite::create(const std::string& name, const std::string& uri,
const std::string& value, Element& parent, Element* &result)
{
auto elem = Element::create(name, uri, value);
result = & parent.addChild(std::move(elem));
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ namespace fs = std::filesystem;

static fs::path findRoot(const fs::path& p)
{
if (p.empty())
{
return p;
}
const fs::path LICENSE("LICENSE");
const fs::path README_md("README.md");
const fs::path CMakeLists_txt("CMakeLists.txt");
Expand Down Expand Up @@ -266,10 +262,11 @@ static void testReadEncodedXmlFile(const std::string& testName, const std::strin
{
const auto coda_oss = findRoot();
const auto unittests = coda_oss / "modules" / "c++" / "xml.lite" / "unittests";

const auto path = unittests / xmlFile;
if (!exists(path)) // running in "externals" of a different project
if (!exists(path)) // running in "externals" of a different project
{
std::clog << "Path does not exist: '" << path << "'\n";
return;
}
io::FileInputStream input(path.string());
Expand Down Expand Up @@ -311,6 +308,7 @@ static void testReadXmlFile(const std::string& testName, const std::string& xmlF
const auto path = unittests / xmlFile;
if (!exists(path)) // running in "externals" of a different project
{
std::clog << "Path does not exist: '" << path << "'\n";
return;
}
io::FileInputStream input(path.string());
Expand Down

0 comments on commit 01f811e

Please sign in to comment.