diff --git a/include/pdal/Metadata.hpp b/include/pdal/Metadata.hpp index f7f0e140e0..5f8606b10b 100644 --- a/include/pdal/Metadata.hpp +++ b/include/pdal/Metadata.hpp @@ -121,8 +121,8 @@ class PDAL_DLL Metadata ~Metadata(); - template inline void set(T const& v) { m_variant = v; } - template inline T get() { return boost::get(m_variant); } + template inline void setValue(T const& v) { m_variant = v; } + template inline T getValue() { return boost::get(m_variant); } template inline T cast() { return boost::lexical_cast(m_variant); } Metadata& operator=(Metadata const& rhs); @@ -137,6 +137,10 @@ class PDAL_DLL Metadata std::string const& getNamespace() const { return m_namespace; } void setNamespace(std::string const& ns) { m_namespace = ns; } + std::vector getAttributeNames() const; + void addAttribute(std::string const& name, std::string const value); + std::string getAttribute(std::string const& name) const; + private: metadata::Variant m_variant; std::string m_name; diff --git a/src/Metadata.cpp b/src/Metadata.cpp index 433250c97c..373557f0ab 100644 --- a/src/Metadata.cpp +++ b/src/Metadata.cpp @@ -71,6 +71,34 @@ Metadata::~Metadata() } +std::vector Metadata::getAttributeNames() const +{ + std::vector output; + metadata::MetadataAttributeM::const_iterator i = m_attributes.begin(); + while (i != m_attributes.end()) + { + output.push_back(i->first); + ++i; + } + + return output; +} + + +void Metadata::addAttribute(std::string const& name, std::string const value) +{ + std::pair p(name, value); + m_attributes.insert(p); +} + +std::string Metadata::getAttribute(std::string const& name) const +{ + metadata::MetadataAttributeM::const_iterator p = m_attributes.find(name); + if (p != m_attributes.end()) + return p->second; + else + return std::string(""); +} Metadata& Metadata::operator=(Metadata const& rhs) { diff --git a/test/unit/MetadataTest.cpp b/test/unit/MetadataTest.cpp index 4a80d08950..6c384c5f25 100644 --- a/test/unit/MetadataTest.cpp +++ b/test/unit/MetadataTest.cpp @@ -68,16 +68,26 @@ BOOST_AUTO_TEST_CASE(test_construction) pdal::Bounds b(1.1,2.2,3.3,101.1,102.2,103.3); - m.set(u32); + m.setValue(u32); - BOOST_CHECK_EQUAL(m.get(), 32u); - BOOST_CHECK_THROW(m.get(), boost::bad_get); + m.addAttribute("some_id", "some_value"); + m.addAttribute("another_id", "another_value"); + + std::vector names = m.getAttributeNames(); + BOOST_CHECK_EQUAL(names.size(), 2); + + BOOST_CHECK_EQUAL(m.getAttribute("some_id"), "some_value"); + BOOST_CHECK_EQUAL(m.getAttribute("another_id"), "another_value"); + + BOOST_CHECK_EQUAL(m.getValue(), 32u); + BOOST_CHECK_THROW(m.getValue(), boost::bad_get); - BOOST_CHECK_EQUAL(m.cast(), 32); - m.set(bytes); + BOOST_CHECK_EQUAL(m.cast(), 32); + m.setValue(bytes); std::string base64("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw=="); - BOOST_CHECK_EQUAL( boost::lexical_cast(m.get()), base64); + BOOST_CHECK_EQUAL( boost::lexical_cast(m.getValue()), base64); + BOOST_CHECK_THROW(m.getValue(), boost::bad_get); return; }