| 113 | // ---------------------------------------------------------------------------------------- |
| 114 | |
| 115 | void print_config_reader_contents ( |
| 116 | const config_reader& cr, |
| 117 | int depth |
| 118 | ) |
| 119 | { |
| 120 | // Make a string with depth*4 spaces in it. |
| 121 | const string padding(depth*4, ' '); |
| 122 | |
| 123 | // We can obtain a list of all the keys and sub-blocks defined |
| 124 | // at the current level in the config reader like so: |
| 125 | vector<string> keys, blocks; |
| 126 | cr.get_keys(keys); |
| 127 | cr.get_blocks(blocks); |
| 128 | |
| 129 | // Now print all the key/value pairs |
| 130 | for (unsigned long i = 0; i < keys.size(); ++i) |
| 131 | cout << padding << keys[i] << " = " << cr[keys[i]] << endl; |
| 132 | |
| 133 | // Now print all the sub-blocks. |
| 134 | for (unsigned long i = 0; i < blocks.size(); ++i) |
| 135 | { |
| 136 | // First print the block name |
| 137 | cout << padding << blocks[i] << " { " << endl; |
| 138 | // Now recursively print the contents of the sub block. Note that the cr.block() |
| 139 | // function returns another config_reader that represents the sub-block. |
| 140 | print_config_reader_contents(cr.block(blocks[i]), depth+1); |
| 141 | cout << padding << "}" << endl; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // ---------------------------------------------------------------------------------------- |
| 146 | |