Skip to content

Commit

Permalink
remove xml namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed May 9, 2023
1 parent 15001b8 commit fb95549
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 80 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ Serialization of `xml` is similar to `json`. The first step is also defining met
person p = {"admin", 20};
iguana::string_stream ss;
iguana::xml::to_xml(ss, p);
iguana::to_xml(ss, p);
std::cout << ss.str() << std::endl;
std::string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"> <name>buke</name> <id>1</id>";
iguana::xml::from_xml(p, xml.data(), xml.length());
iguana::from_xml(p, xml.data(), xml.length());
### A complicated example
*iguana* can deal with objects which contain another objects and containers. Here is the example:
Expand Down
5 changes: 2 additions & 3 deletions benchmark/xml_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void test_deserialize() {
ScopedTimer timer("test deserialize rpm_filelists.xml");
for (int i = 0; i < iterations; ++i) {
filelists_t filelist;
iguana::xml::from_xml<rapidxml::parse_fastest>(filelist,
xmlfilelist.data());
iguana::from_xml<rapidxml::parse_fastest>(filelist, xmlfilelist.data());
}
}
std::cout << "============ deserialize sample_rss.xml ===============\n";
Expand All @@ -62,7 +61,7 @@ void test_deserialize() {
ScopedTimer timer("test deserialize sample_rss.xml");
for (int i = 0; i < iterations; ++i) {
rss_t rss;
iguana::xml::from_xml<rapidxml::parse_fastest>(rss, xmlrss.data());
iguana::from_xml<rapidxml::parse_fastest>(rss, xmlrss.data());
// assert(rss.channel.item.size() == 99);
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ void test_json() {
void test_xml() {
person p = {"admin", 20};
iguana::string_stream ss;
iguana::xml::to_xml(ss, p);
iguana::to_xml(ss, p);
std::cout << ss << std::endl;

ss.clear();
two t = {"test", {2}, 4};
iguana::xml::to_xml(ss, t);
iguana::to_xml(ss, t);

std::cout << ss << std::endl;

two t1;
iguana::xml::from_xml(t1, ss.data());
iguana::from_xml(t1, ss.data());
std::cout << t1.age << "\n";
}

Expand Down
54 changes: 27 additions & 27 deletions example/xml_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ void test_to_xml() {

// pretty xml
std::string ss;
iguana::xml::to_xml_pretty(ss, contents);
iguana::to_xml_pretty(ss, contents);
std::cout << ss << "\n";

// non pretty xml
std::string s;
iguana::xml::to_xml(s, contents);
iguana::to_xml(s, contents);
std::cout << s << "\n";
}

Expand All @@ -56,11 +56,11 @@ void test_from_xml() {

// pretty xml
std::string ss;
iguana::xml::to_xml_pretty(ss, contents);
iguana::to_xml_pretty(ss, contents);
std::cout << ss << "\n";

Contents contents2{"test"};
iguana::xml::from_xml(contents2, ss.data());
iguana::from_xml(contents2, ss.data());
std::cout << contents2.Size << "\n";
std::cout << contents2.Owner.DisplayName << "\n";
assert(contents == contents2);
Expand Down Expand Up @@ -107,13 +107,13 @@ void test_parse_status() {
)";

status_t t{};
iguana::xml::from_xml(t, str.data());
iguana::from_xml(t, str.data());
std::cout << t.owner << "\n";
std::cout << t.mtime << ", " << t.atime << "\n";
std::cout << t.storagePolicy << "\n";

std::string ss;
iguana::xml::to_xml(ss, t);
iguana::to_xml(ss, t);
}

void test_parse_response() {
Expand All @@ -137,7 +137,7 @@ void test_parse_response() {
)";

response t{};
iguana::xml::from_xml(t, str.data());
iguana::from_xml(t, str.data());
std::cout << t.status.owner << "\n";
}

Expand All @@ -155,11 +155,11 @@ void test_optional() {
op.d = true;
op.e = 'o';
std::string ss;
iguana::xml::to_xml(ss, op);
iguana::to_xml(ss, op);
std::cout << ss << "\n";

optional_t op1;
iguana::xml::from_xml(op1, ss.data());
iguana::from_xml(op1, ss.data());
if (op1.b) {
std::cout << *op1.b << "\n";
}
Expand All @@ -183,15 +183,15 @@ void test_list() {
l.list.push_back(optional_t{5, 6, {}, 0, 'l'});

std::string ss;
iguana::xml::to_xml(ss, l);
iguana::to_xml(ss, l);
std::cout << ss << "\n";

list_t l1;
iguana::xml::from_xml(l1, ss.data());
iguana::from_xml(l1, ss.data());
std::cout << l1.list.size() << "\n";

std::string s;
iguana::xml::to_xml_pretty(s, l);
iguana::to_xml_pretty(s, l);
std::cout << s << '\n';
}

Expand Down Expand Up @@ -223,10 +223,10 @@ void test_attribute() {
)";

book_t book{};
iguana::xml::from_xml(book, str.data());
iguana::from_xml(book, str.data());
std::cout << book;
std::string ss;
iguana::xml::to_xml(ss, book);
iguana::to_xml(ss, book);
std::cout << "attr to_xml: " << ss << std::endl;
}

Expand All @@ -247,7 +247,7 @@ void test_nested_attribute() {
</library>
)";
library_t library;
iguana::xml::from_xml(library, str.data());
iguana::from_xml(library, str.data());
std::cout << "library attribute" << std::endl;
for (auto &[k, v] : library.__attr) {
std::cout << "[ " << k << " : " << v << "]"
Expand All @@ -257,13 +257,13 @@ void test_nested_attribute() {
std::cout << "\nbook\n" << library.book;

std::string ss;
iguana::xml::to_xml(ss, library);
iguana::to_xml(ss, library);
std::cout << "library to_xml: " << ss << std::endl;
}
struct movie_t {
std::string title;
std::string director;
std::unordered_map<std::string, iguana::xml::any_t> __attr;
std::unordered_map<std::string, iguana::any_t> __attr;
};
REFLECTION(movie_t, title, director, __attr);
void test_any_attribute() {
Expand All @@ -275,7 +275,7 @@ void test_any_attribute() {
</movie>
)";
movie_t movie;
iguana::xml::from_xml(movie, str.data());
iguana::from_xml(movie, str.data());
std::cout << "movie attribute :" << std::endl;
auto &attr = movie.__attr;
{
Expand Down Expand Up @@ -313,18 +313,18 @@ void test_vector() {
p.name.push_back("Bob");
p.name.push_back("bbg");
std::string ss;
iguana::xml::to_xml(ss, p);
iguana::to_xml(ss, p);
std::cout << ss << std::endl;
}

struct item_itunes_t {
iguana::xml::namespace_t<std::string_view> itunes_author;
iguana::xml::namespace_t<std::string_view> itunes_subtitle;
iguana::xml::namespace_t<int> itunes_user;
iguana::namespace_t<std::string_view> itunes_author;
iguana::namespace_t<std::string_view> itunes_subtitle;
iguana::namespace_t<int> itunes_user;
};
REFLECTION(item_itunes_t, itunes_author, itunes_subtitle, itunes_user);
struct item_t {
iguana::xml::namespace_t<item_itunes_t> item_itunes;
iguana::namespace_t<item_itunes_t> item_itunes;
};
REFLECTION(item_t, item_itunes);
void test_namespace() {
Expand All @@ -339,13 +339,13 @@ void test_namespace() {
</item>
)";
item_t it;
iguana::xml::from_xml(it, str.data());
iguana::from_xml(it, str.data());
auto itunes = it.item_itunes.get();
std::cout << "author : " << itunes.itunes_author.get() << "\n";
std::cout << "subtitle : " << itunes.itunes_subtitle.get() << "\n";
std::cout << "user : " << itunes.itunes_user.get() << "\n";
std::string ss;
iguana::xml::to_xml(ss, it);
iguana::to_xml(ss, it);
std::cout << "to_xml" << std::endl << ss << "\n";
}

Expand All @@ -364,7 +364,7 @@ void test_leafnode_attribute() {
</package>
)";
package_t package;
iguana::xml::from_xml(package, str.data());
iguana::from_xml(package, str.data());
std::cout << "package attr : \n";
for (auto &[k, v] : package.__attr) {
std::cout << "[ " << k << " : " << v << "] ";
Expand All @@ -375,7 +375,7 @@ void test_leafnode_attribute() {
}
std::cout << "\nchangelog value : \n" << package.changelog.first << "\n";
std::string ss;
iguana::xml::to_xml(ss, package);
iguana::to_xml(ss, package);
std::cout << "to_xml : \n" << ss << "\n";
}

Expand Down
2 changes: 0 additions & 2 deletions iguana/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ template <typename T> constexpr inline bool is_std_pair_v = false;
template <typename T, typename K>
constexpr inline bool is_std_pair_v<std::pair<T, K>> = true;

namespace xml {
template <typename T> class namespace_t;
template <typename T> constexpr inline bool is_namespace_v = false;

template <typename T>
constexpr inline bool is_namespace_v<namespace_t<T>> = true;
} // namespace xml

} // namespace iguana
4 changes: 2 additions & 2 deletions iguana/xml_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string>
#include <type_traits>

namespace iguana::xml {
namespace iguana {
template <typename T> void do_read(rapidxml::xml_node<char> *node, T &&t);

constexpr inline size_t find_underline(const char *str) {
Expand Down Expand Up @@ -227,4 +227,4 @@ inline bool from_xml(T &&t, char *buf) {

return false;
}
} // namespace iguana::xml
} // namespace iguana
4 changes: 2 additions & 2 deletions iguana/xml_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <rapidxml_print.hpp>
#include <string.h>

namespace iguana::xml {
namespace iguana {
// to xml
template <typename Stream, typename T>
inline void to_xml_impl(Stream &s, T &&t, std::string_view name = "");
Expand Down Expand Up @@ -188,5 +188,5 @@ inline bool to_xml_pretty(Stream &s, T &&t) {

return r;
}
} // namespace iguana::xml
} // namespace iguana
#endif // IGUANA_XML17_HPP
Loading

0 comments on commit fb95549

Please sign in to comment.