GG
|
00001 // -*- C++ -*- 00002 #include <fstream> 00003 #include <string> 00004 00005 #include <GG/adobe/array.hpp> 00006 #include <GG/adobe/dictionary.hpp> 00007 00008 00009 std::string read_file(const std::string& filename) 00010 { 00011 std::string retval; 00012 std::ifstream ifs(filename.c_str()); 00013 int c; 00014 while ((c = ifs.get()) != std::ifstream::traits_type::eof()) { 00015 retval += c; 00016 } 00017 return retval; 00018 } 00019 00020 namespace adobe { namespace version_1 { 00021 00022 std::ostream& operator<<(std::ostream& stream, const type_info_t& x) 00023 { 00024 std::ostream_iterator<char> out(stream); 00025 serialize(x, out); 00026 return stream; 00027 } 00028 00029 } } 00030 00031 void verbose_dump(const adobe::array_t& array, std::size_t indent = 0); 00032 void verbose_dump(const adobe::dictionary_t& array, std::size_t indent = 0); 00033 00034 void verbose_dump(const adobe::array_t& array, std::size_t indent) 00035 { 00036 if (array.empty()) { 00037 std::cout << std::string(4 * indent, ' ') << "[]\n"; 00038 return; 00039 } 00040 00041 std::cout << std::string(4 * indent, ' ') << "[\n"; 00042 ++indent; 00043 for (adobe::array_t::const_iterator it = array.begin(); it != array.end(); ++it) { 00044 const adobe::any_regular_t& any = *it; 00045 if (any.type_info() == adobe::type_info<adobe::array_t>()) { 00046 verbose_dump(any.cast<adobe::array_t>(), indent); 00047 } else if (any.type_info() == adobe::type_info<adobe::dictionary_t>()) { 00048 verbose_dump(any.cast<adobe::dictionary_t>(), indent); 00049 } else { 00050 std::cout << std::string(4 * indent, ' ') 00051 << "type: " << any.type_info() << " " 00052 << "value: " << any << "\n"; 00053 } 00054 } 00055 --indent; 00056 std::cout << std::string(4 * indent, ' ') << "]\n"; 00057 } 00058 00059 void verbose_dump(const adobe::dictionary_t& dictionary, std::size_t indent) 00060 { 00061 if (dictionary.empty()) { 00062 std::cout << std::string(4 * indent, ' ') << "{}\n"; 00063 return; 00064 } 00065 00066 std::cout << std::string(4 * indent, ' ') << "{\n"; 00067 ++indent; 00068 for (adobe::dictionary_t::const_iterator it = dictionary.begin(); it != dictionary.end(); ++it) { 00069 const adobe::pair<adobe::name_t, adobe::any_regular_t>& pair = *it; 00070 if (pair.second.type_info() == adobe::type_info<adobe::array_t>()) { 00071 std::cout << std::string(4 * indent, ' ') << pair.first << ",\n"; 00072 verbose_dump(pair.second.cast<adobe::array_t>(), indent); 00073 } else if (pair.second.type_info() == adobe::type_info<adobe::dictionary_t>()) { 00074 std::cout << std::string(4 * indent, ' ') << pair.first << ",\n"; 00075 verbose_dump(pair.second.cast<adobe::dictionary_t>(), indent); 00076 } else { 00077 std::cout << std::string(4 * indent, ' ') 00078 << "(" << pair.first << ", " 00079 << "type: " << pair.second.type_info() << " " 00080 << "value: " << pair.second << ")\n"; 00081 } 00082 } 00083 --indent; 00084 std::cout << std::string(4 * indent, ' ') << "}\n"; 00085 }