tag.cpp 994 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) 2005 Carl Barron. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying file
  3. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "tag.hpp"
  5. #include <iostream>
  6. #include <algorithm>
  7. namespace
  8. {
  9. struct print_pair
  10. {
  11. template <class P>
  12. void operator () (const P &x)
  13. {
  14. std::cout << '\t' << x.first << ':' << x.second <<'\n';
  15. }
  16. };
  17. }
  18. void walk_data::operator () (const std::string &x)
  19. {
  20. std::cout << "String:" << x <<'\n';
  21. }
  22. void walk_data::operator () (const tag &t)
  23. {
  24. std::cout << "Tag:" << t.id << '\n';
  25. std::cout << "Attributes\n";
  26. std::for_each
  27. (
  28. t.attributes.begin(),
  29. t.attributes.end(),
  30. print_pair()
  31. );
  32. std::cout << "Children:\n";
  33. std::for_each
  34. (
  35. t.children.begin(),
  36. t.children.end(),
  37. boost::apply_visitor(*this)
  38. );
  39. std::cout << "End of tag:" << t.id << '\n';
  40. }