GG: TestingUtils.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

TestingUtils.h
1 // -*- C++ -*-
2 #include <fstream>
3 #include <string>
4
5 #include <GG/adobe/array.hpp>
6 #include <GG/adobe/dictionary.hpp>
7
8
9 std::string read_file(const std::string& filename)
10 {
11 std::string retval;
12 std::ifstream ifs(filename.c_str());
13 int c;
14 while ((c = ifs.get()) != std::ifstream::traits_type::eof()) {
15 retval += c;
16 }
17 return retval;
18 }
19
20 namespace adobe { namespace version_1 {
21
22 std::ostream& operator<<(std::ostream& stream, const type_info_t& x)
23 {
24 std::ostream_iterator<char> out(stream);
25 serialize(x, out);
26 return stream;
27 }
28
29 } }
30
31 void verbose_dump(const adobe::array_t& array, std::size_t indent = 0);
32 void verbose_dump(const adobe::dictionary_t& array, std::size_t indent = 0);
33
34 void verbose_dump(const adobe::array_t& array, std::size_t indent)
35 {
36 if (array.empty()) {
37 std::cout << std::string(4 * indent, ' ') << "[]\n";
38 return;
39 }
40
41 std::cout << std::string(4 * indent, ' ') << "[\n";
42 ++indent;
43 for (adobe::array_t::const_iterator it = array.begin(); it != array.end(); ++it) {
44 const adobe::any_regular_t& any = *it;
45 if (any.type_info() == adobe::type_info<adobe::array_t>()) {
46 verbose_dump(any.cast<adobe::array_t>(), indent);
47 } else if (any.type_info() == adobe::type_info<adobe::dictionary_t>()) {
48 verbose_dump(any.cast<adobe::dictionary_t>(), indent);
49 } else {
50 std::cout << std::string(4 * indent, ' ')
51 << "type: " << any.type_info() << " "
52 << "value: " << any << "\n";
53 }
54 }
55 --indent;
56 std::cout << std::string(4 * indent, ' ') << "]\n";
57 }
58
59 void verbose_dump(const adobe::dictionary_t& dictionary, std::size_t indent)
60 {
61 if (dictionary.empty()) {
62 std::cout << std::string(4 * indent, ' ') << "{}\n";
63 return;
64 }
65
66 std::cout << std::string(4 * indent, ' ') << "{\n";
67 ++indent;
68 for (adobe::dictionary_t::const_iterator it = dictionary.begin(); it != dictionary.end(); ++it) {
69 const adobe::pair<adobe::name_t, adobe::any_regular_t>& pair = *it;
70 if (pair.second.type_info() == adobe::type_info<adobe::array_t>()) {
71 std::cout << std::string(4 * indent, ' ') << pair.first << ",\n";
72 verbose_dump(pair.second.cast<adobe::array_t>(), indent);
73 } else if (pair.second.type_info() == adobe::type_info<adobe::dictionary_t>()) {
74 std::cout << std::string(4 * indent, ' ') << pair.first << ",\n";
75 verbose_dump(pair.second.cast<adobe::dictionary_t>(), indent);
76 } else {
77 std::cout << std::string(4 * indent, ' ')
78 << "(" << pair.first << ", "
79 << "type: " << pair.second.type_info() << " "
80 << "value: " << pair.second << ")\n";
81 }
82 }
83 --indent;
84 std::cout << std::string(4 * indent, ' ') << "}\n";
85 }