182 typename Graph::Edge>& map) |
184 typename Graph::Edge>& map) |
183 : _graph(graph), _map(map) {} |
185 : _graph(graph), _map(map) {} |
184 |
186 |
185 typename Graph::Arc operator()(const std::string& str) { |
187 typename Graph::Arc operator()(const std::string& str) { |
186 if (str.empty() || (str[0] != '+' && str[0] != '-')) { |
188 if (str.empty() || (str[0] != '+' && str[0] != '-')) { |
187 throw DataFormatError("Item must start with '+' or '-'"); |
189 throw FormatError("Item must start with '+' or '-'"); |
188 } |
190 } |
189 typename std::map<std::string, typename Graph::Edge> |
191 typename std::map<std::string, typename Graph::Edge> |
190 ::const_iterator it = _map.find(str.substr(1)); |
192 ::const_iterator it = _map.find(str.substr(1)); |
191 if (it == _map.end()) { |
193 if (it == _map.end()) { |
192 throw DataFormatError("Item not found"); |
194 throw FormatError("Item not found"); |
193 } |
195 } |
194 return _graph.direct(it->second, str[0] == '+'); |
196 return _graph.direct(it->second, str[0] == '+'); |
195 } |
197 } |
196 }; |
198 }; |
197 |
199 |
262 return '\v'; |
264 return '\v'; |
263 case 'x': |
265 case 'x': |
264 { |
266 { |
265 int code; |
267 int code; |
266 if (!is.get(c) || !isHex(c)) |
268 if (!is.get(c) || !isHex(c)) |
267 throw DataFormatError("Escape format error"); |
269 throw FormatError("Escape format error"); |
268 else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c); |
270 else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c); |
269 else code = code * 16 + valueHex(c); |
271 else code = code * 16 + valueHex(c); |
270 return code; |
272 return code; |
271 } |
273 } |
272 default: |
274 default: |
273 { |
275 { |
274 int code; |
276 int code; |
275 if (!isOct(c)) |
277 if (!isOct(c)) |
276 throw DataFormatError("Escape format error"); |
278 throw FormatError("Escape format error"); |
277 else if (code = valueOct(c), !is.get(c) || !isOct(c)) |
279 else if (code = valueOct(c), !is.get(c) || !isOct(c)) |
278 is.putback(c); |
280 is.putback(c); |
279 else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) |
281 else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) |
280 is.putback(c); |
282 is.putback(c); |
281 else code = code * 8 + valueOct(c); |
283 else code = code * 8 + valueOct(c); |
507 /// \brief Constructor |
510 /// \brief Constructor |
508 /// |
511 /// |
509 /// Construct a directed graph reader, which reads from the given |
512 /// Construct a directed graph reader, which reads from the given |
510 /// file. |
513 /// file. |
511 DigraphReader(const std::string& fn, Digraph& digraph) |
514 DigraphReader(const std::string& fn, Digraph& digraph) |
512 : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph), |
515 : _is(new std::ifstream(fn.c_str())), local_is(true), |
|
516 _filename(fn), _digraph(digraph), |
513 _use_nodes(false), _use_arcs(false), |
517 _use_nodes(false), _use_arcs(false), |
514 _skip_nodes(false), _skip_arcs(false) {} |
518 _skip_nodes(false), _skip_arcs(false) { |
|
519 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
520 } |
515 |
521 |
516 /// \brief Constructor |
522 /// \brief Constructor |
517 /// |
523 /// |
518 /// Construct a directed graph reader, which reads from the given |
524 /// Construct a directed graph reader, which reads from the given |
519 /// file. |
525 /// file. |
520 DigraphReader(const char* fn, Digraph& digraph) |
526 DigraphReader(const char* fn, Digraph& digraph) |
521 : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph), |
527 : _is(new std::ifstream(fn)), local_is(true), |
|
528 _filename(fn), _digraph(digraph), |
522 _use_nodes(false), _use_arcs(false), |
529 _use_nodes(false), _use_arcs(false), |
523 _skip_nodes(false), _skip_arcs(false) {} |
530 _skip_nodes(false), _skip_arcs(false) { |
|
531 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
532 } |
524 |
533 |
525 /// \brief Destructor |
534 /// \brief Destructor |
526 ~DigraphReader() { |
535 ~DigraphReader() { |
527 for (typename NodeMaps::iterator it = _node_maps.begin(); |
536 for (typename NodeMaps::iterator it = _node_maps.begin(); |
528 it != _node_maps.end(); ++it) { |
537 it != _node_maps.end(); ++it) { |
893 std::vector<std::string> tokens(map_num); |
902 std::vector<std::string> tokens(map_num); |
894 for (int i = 0; i < map_num; ++i) { |
903 for (int i = 0; i < map_num; ++i) { |
895 if (!_reader_bits::readToken(line, tokens[i])) { |
904 if (!_reader_bits::readToken(line, tokens[i])) { |
896 std::ostringstream msg; |
905 std::ostringstream msg; |
897 msg << "Column not found (" << i + 1 << ")"; |
906 msg << "Column not found (" << i + 1 << ")"; |
898 throw DataFormatError(msg.str().c_str()); |
907 throw FormatError(msg.str()); |
899 } |
908 } |
900 } |
909 } |
901 if (line >> std::ws >> c) |
910 if (line >> std::ws >> c) |
902 throw DataFormatError("Extra character on the end of line"); |
911 throw FormatError("Extra character on the end of line"); |
903 |
912 |
904 Node n; |
913 Node n; |
905 if (!_use_nodes) { |
914 if (!_use_nodes) { |
906 n = _digraph.addNode(); |
915 n = _digraph.addNode(); |
907 if (label_index != -1) |
916 if (label_index != -1) |
908 _node_index.insert(std::make_pair(tokens[label_index], n)); |
917 _node_index.insert(std::make_pair(tokens[label_index], n)); |
909 } else { |
918 } else { |
910 if (label_index == -1) |
919 if (label_index == -1) |
911 throw DataFormatError("Label map not found in file"); |
920 throw FormatError("Label map not found in file"); |
912 typename std::map<std::string, Node>::iterator it = |
921 typename std::map<std::string, Node>::iterator it = |
913 _node_index.find(tokens[label_index]); |
922 _node_index.find(tokens[label_index]); |
914 if (it == _node_index.end()) { |
923 if (it == _node_index.end()) { |
915 std::ostringstream msg; |
924 std::ostringstream msg; |
916 msg << "Node with label not found: " << tokens[label_index]; |
925 msg << "Node with label not found: " << tokens[label_index]; |
917 throw DataFormatError(msg.str().c_str()); |
926 throw FormatError(msg.str()); |
918 } |
927 } |
919 n = it->second; |
928 n = it->second; |
920 } |
929 } |
921 |
930 |
922 for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
931 for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
985 |
994 |
986 std::string source_token; |
995 std::string source_token; |
987 std::string target_token; |
996 std::string target_token; |
988 |
997 |
989 if (!_reader_bits::readToken(line, source_token)) |
998 if (!_reader_bits::readToken(line, source_token)) |
990 throw DataFormatError("Source not found"); |
999 throw FormatError("Source not found"); |
991 |
1000 |
992 if (!_reader_bits::readToken(line, target_token)) |
1001 if (!_reader_bits::readToken(line, target_token)) |
993 throw DataFormatError("Target not found"); |
1002 throw FormatError("Target not found"); |
994 |
1003 |
995 std::vector<std::string> tokens(map_num); |
1004 std::vector<std::string> tokens(map_num); |
996 for (int i = 0; i < map_num; ++i) { |
1005 for (int i = 0; i < map_num; ++i) { |
997 if (!_reader_bits::readToken(line, tokens[i])) { |
1006 if (!_reader_bits::readToken(line, tokens[i])) { |
998 std::ostringstream msg; |
1007 std::ostringstream msg; |
999 msg << "Column not found (" << i + 1 << ")"; |
1008 msg << "Column not found (" << i + 1 << ")"; |
1000 throw DataFormatError(msg.str().c_str()); |
1009 throw FormatError(msg.str()); |
1001 } |
1010 } |
1002 } |
1011 } |
1003 if (line >> std::ws >> c) |
1012 if (line >> std::ws >> c) |
1004 throw DataFormatError("Extra character on the end of line"); |
1013 throw FormatError("Extra character on the end of line"); |
1005 |
1014 |
1006 Arc a; |
1015 Arc a; |
1007 if (!_use_arcs) { |
1016 if (!_use_arcs) { |
1008 |
1017 |
1009 typename NodeIndex::iterator it; |
1018 typename NodeIndex::iterator it; |
1010 |
1019 |
1011 it = _node_index.find(source_token); |
1020 it = _node_index.find(source_token); |
1012 if (it == _node_index.end()) { |
1021 if (it == _node_index.end()) { |
1013 std::ostringstream msg; |
1022 std::ostringstream msg; |
1014 msg << "Item not found: " << source_token; |
1023 msg << "Item not found: " << source_token; |
1015 throw DataFormatError(msg.str().c_str()); |
1024 throw FormatError(msg.str()); |
1016 } |
1025 } |
1017 Node source = it->second; |
1026 Node source = it->second; |
1018 |
1027 |
1019 it = _node_index.find(target_token); |
1028 it = _node_index.find(target_token); |
1020 if (it == _node_index.end()) { |
1029 if (it == _node_index.end()) { |
1021 std::ostringstream msg; |
1030 std::ostringstream msg; |
1022 msg << "Item not found: " << target_token; |
1031 msg << "Item not found: " << target_token; |
1023 throw DataFormatError(msg.str().c_str()); |
1032 throw FormatError(msg.str()); |
1024 } |
1033 } |
1025 Node target = it->second; |
1034 Node target = it->second; |
1026 |
1035 |
1027 a = _digraph.addArc(source, target); |
1036 a = _digraph.addArc(source, target); |
1028 if (label_index != -1) |
1037 if (label_index != -1) |
1029 _arc_index.insert(std::make_pair(tokens[label_index], a)); |
1038 _arc_index.insert(std::make_pair(tokens[label_index], a)); |
1030 } else { |
1039 } else { |
1031 if (label_index == -1) |
1040 if (label_index == -1) |
1032 throw DataFormatError("Label map not found in file"); |
1041 throw FormatError("Label map not found in file"); |
1033 typename std::map<std::string, Arc>::iterator it = |
1042 typename std::map<std::string, Arc>::iterator it = |
1034 _arc_index.find(tokens[label_index]); |
1043 _arc_index.find(tokens[label_index]); |
1035 if (it == _arc_index.end()) { |
1044 if (it == _arc_index.end()) { |
1036 std::ostringstream msg; |
1045 std::ostringstream msg; |
1037 msg << "Arc with label not found: " << tokens[label_index]; |
1046 msg << "Arc with label not found: " << tokens[label_index]; |
1038 throw DataFormatError(msg.str().c_str()); |
1047 throw FormatError(msg.str()); |
1039 } |
1048 } |
1040 a = it->second; |
1049 a = it->second; |
1041 } |
1050 } |
1042 |
1051 |
1043 for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) { |
1052 for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) { |
1058 while (readLine() && line >> c && c != '@') { |
1067 while (readLine() && line >> c && c != '@') { |
1059 line.putback(c); |
1068 line.putback(c); |
1060 |
1069 |
1061 std::string attr, token; |
1070 std::string attr, token; |
1062 if (!_reader_bits::readToken(line, attr)) |
1071 if (!_reader_bits::readToken(line, attr)) |
1063 throw DataFormatError("Attribute name not found"); |
1072 throw FormatError("Attribute name not found"); |
1064 if (!_reader_bits::readToken(line, token)) |
1073 if (!_reader_bits::readToken(line, token)) |
1065 throw DataFormatError("Attribute value not found"); |
1074 throw FormatError("Attribute value not found"); |
1066 if (line >> c) |
1075 if (line >> c) |
1067 throw DataFormatError("Extra character on the end of line"); |
1076 throw FormatError("Extra character on the end of line"); |
1068 |
1077 |
1069 { |
1078 { |
1070 std::set<std::string>::iterator it = read_attr.find(attr); |
1079 std::set<std::string>::iterator it = read_attr.find(attr); |
1071 if (it != read_attr.end()) { |
1080 if (it != read_attr.end()) { |
1072 std::ostringstream msg; |
1081 std::ostringstream msg; |
1073 msg << "Multiple occurence of attribute " << attr; |
1082 msg << "Multiple occurence of attribute " << attr; |
1074 throw DataFormatError(msg.str().c_str()); |
1083 throw FormatError(msg.str()); |
1075 } |
1084 } |
1076 read_attr.insert(attr); |
1085 read_attr.insert(attr); |
1077 } |
1086 } |
1078 |
1087 |
1079 { |
1088 { |
1291 /// \brief Constructor |
1302 /// \brief Constructor |
1292 /// |
1303 /// |
1293 /// Construct an undirected graph reader, which reads from the given |
1304 /// Construct an undirected graph reader, which reads from the given |
1294 /// file. |
1305 /// file. |
1295 GraphReader(const std::string& fn, Graph& graph) |
1306 GraphReader(const std::string& fn, Graph& graph) |
1296 : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph), |
1307 : _is(new std::ifstream(fn.c_str())), local_is(true), |
|
1308 _filename(fn), _graph(graph), |
1297 _use_nodes(false), _use_edges(false), |
1309 _use_nodes(false), _use_edges(false), |
1298 _skip_nodes(false), _skip_edges(false) {} |
1310 _skip_nodes(false), _skip_edges(false) { |
|
1311 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
1312 } |
1299 |
1313 |
1300 /// \brief Constructor |
1314 /// \brief Constructor |
1301 /// |
1315 /// |
1302 /// Construct an undirected graph reader, which reads from the given |
1316 /// Construct an undirected graph reader, which reads from the given |
1303 /// file. |
1317 /// file. |
1304 GraphReader(const char* fn, Graph& graph) |
1318 GraphReader(const char* fn, Graph& graph) |
1305 : _is(new std::ifstream(fn)), local_is(true), _graph(graph), |
1319 : _is(new std::ifstream(fn)), local_is(true), |
|
1320 _filename(fn), _graph(graph), |
1306 _use_nodes(false), _use_edges(false), |
1321 _use_nodes(false), _use_edges(false), |
1307 _skip_nodes(false), _skip_edges(false) {} |
1322 _skip_nodes(false), _skip_edges(false) { |
|
1323 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
1324 } |
1308 |
1325 |
1309 /// \brief Destructor |
1326 /// \brief Destructor |
1310 ~GraphReader() { |
1327 ~GraphReader() { |
1311 for (typename NodeMaps::iterator it = _node_maps.begin(); |
1328 for (typename NodeMaps::iterator it = _node_maps.begin(); |
1312 it != _node_maps.end(); ++it) { |
1329 it != _node_maps.end(); ++it) { |
1721 std::vector<std::string> tokens(map_num); |
1738 std::vector<std::string> tokens(map_num); |
1722 for (int i = 0; i < map_num; ++i) { |
1739 for (int i = 0; i < map_num; ++i) { |
1723 if (!_reader_bits::readToken(line, tokens[i])) { |
1740 if (!_reader_bits::readToken(line, tokens[i])) { |
1724 std::ostringstream msg; |
1741 std::ostringstream msg; |
1725 msg << "Column not found (" << i + 1 << ")"; |
1742 msg << "Column not found (" << i + 1 << ")"; |
1726 throw DataFormatError(msg.str().c_str()); |
1743 throw FormatError(msg.str()); |
1727 } |
1744 } |
1728 } |
1745 } |
1729 if (line >> std::ws >> c) |
1746 if (line >> std::ws >> c) |
1730 throw DataFormatError("Extra character on the end of line"); |
1747 throw FormatError("Extra character on the end of line"); |
1731 |
1748 |
1732 Node n; |
1749 Node n; |
1733 if (!_use_nodes) { |
1750 if (!_use_nodes) { |
1734 n = _graph.addNode(); |
1751 n = _graph.addNode(); |
1735 if (label_index != -1) |
1752 if (label_index != -1) |
1736 _node_index.insert(std::make_pair(tokens[label_index], n)); |
1753 _node_index.insert(std::make_pair(tokens[label_index], n)); |
1737 } else { |
1754 } else { |
1738 if (label_index == -1) |
1755 if (label_index == -1) |
1739 throw DataFormatError("Label map not found in file"); |
1756 throw FormatError("Label map not found in file"); |
1740 typename std::map<std::string, Node>::iterator it = |
1757 typename std::map<std::string, Node>::iterator it = |
1741 _node_index.find(tokens[label_index]); |
1758 _node_index.find(tokens[label_index]); |
1742 if (it == _node_index.end()) { |
1759 if (it == _node_index.end()) { |
1743 std::ostringstream msg; |
1760 std::ostringstream msg; |
1744 msg << "Node with label not found: " << tokens[label_index]; |
1761 msg << "Node with label not found: " << tokens[label_index]; |
1745 throw DataFormatError(msg.str().c_str()); |
1762 throw FormatError(msg.str()); |
1746 } |
1763 } |
1747 n = it->second; |
1764 n = it->second; |
1748 } |
1765 } |
1749 |
1766 |
1750 for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
1767 for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
1813 |
1830 |
1814 std::string source_token; |
1831 std::string source_token; |
1815 std::string target_token; |
1832 std::string target_token; |
1816 |
1833 |
1817 if (!_reader_bits::readToken(line, source_token)) |
1834 if (!_reader_bits::readToken(line, source_token)) |
1818 throw DataFormatError("Node u not found"); |
1835 throw FormatError("Node u not found"); |
1819 |
1836 |
1820 if (!_reader_bits::readToken(line, target_token)) |
1837 if (!_reader_bits::readToken(line, target_token)) |
1821 throw DataFormatError("Node v not found"); |
1838 throw FormatError("Node v not found"); |
1822 |
1839 |
1823 std::vector<std::string> tokens(map_num); |
1840 std::vector<std::string> tokens(map_num); |
1824 for (int i = 0; i < map_num; ++i) { |
1841 for (int i = 0; i < map_num; ++i) { |
1825 if (!_reader_bits::readToken(line, tokens[i])) { |
1842 if (!_reader_bits::readToken(line, tokens[i])) { |
1826 std::ostringstream msg; |
1843 std::ostringstream msg; |
1827 msg << "Column not found (" << i + 1 << ")"; |
1844 msg << "Column not found (" << i + 1 << ")"; |
1828 throw DataFormatError(msg.str().c_str()); |
1845 throw FormatError(msg.str()); |
1829 } |
1846 } |
1830 } |
1847 } |
1831 if (line >> std::ws >> c) |
1848 if (line >> std::ws >> c) |
1832 throw DataFormatError("Extra character on the end of line"); |
1849 throw FormatError("Extra character on the end of line"); |
1833 |
1850 |
1834 Edge e; |
1851 Edge e; |
1835 if (!_use_edges) { |
1852 if (!_use_edges) { |
1836 |
1853 |
1837 typename NodeIndex::iterator it; |
1854 typename NodeIndex::iterator it; |
1838 |
1855 |
1839 it = _node_index.find(source_token); |
1856 it = _node_index.find(source_token); |
1840 if (it == _node_index.end()) { |
1857 if (it == _node_index.end()) { |
1841 std::ostringstream msg; |
1858 std::ostringstream msg; |
1842 msg << "Item not found: " << source_token; |
1859 msg << "Item not found: " << source_token; |
1843 throw DataFormatError(msg.str().c_str()); |
1860 throw FormatError(msg.str()); |
1844 } |
1861 } |
1845 Node source = it->second; |
1862 Node source = it->second; |
1846 |
1863 |
1847 it = _node_index.find(target_token); |
1864 it = _node_index.find(target_token); |
1848 if (it == _node_index.end()) { |
1865 if (it == _node_index.end()) { |
1849 std::ostringstream msg; |
1866 std::ostringstream msg; |
1850 msg << "Item not found: " << target_token; |
1867 msg << "Item not found: " << target_token; |
1851 throw DataFormatError(msg.str().c_str()); |
1868 throw FormatError(msg.str()); |
1852 } |
1869 } |
1853 Node target = it->second; |
1870 Node target = it->second; |
1854 |
1871 |
1855 e = _graph.addEdge(source, target); |
1872 e = _graph.addEdge(source, target); |
1856 if (label_index != -1) |
1873 if (label_index != -1) |
1857 _edge_index.insert(std::make_pair(tokens[label_index], e)); |
1874 _edge_index.insert(std::make_pair(tokens[label_index], e)); |
1858 } else { |
1875 } else { |
1859 if (label_index == -1) |
1876 if (label_index == -1) |
1860 throw DataFormatError("Label map not found in file"); |
1877 throw FormatError("Label map not found in file"); |
1861 typename std::map<std::string, Edge>::iterator it = |
1878 typename std::map<std::string, Edge>::iterator it = |
1862 _edge_index.find(tokens[label_index]); |
1879 _edge_index.find(tokens[label_index]); |
1863 if (it == _edge_index.end()) { |
1880 if (it == _edge_index.end()) { |
1864 std::ostringstream msg; |
1881 std::ostringstream msg; |
1865 msg << "Edge with label not found: " << tokens[label_index]; |
1882 msg << "Edge with label not found: " << tokens[label_index]; |
1866 throw DataFormatError(msg.str().c_str()); |
1883 throw FormatError(msg.str()); |
1867 } |
1884 } |
1868 e = it->second; |
1885 e = it->second; |
1869 } |
1886 } |
1870 |
1887 |
1871 for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { |
1888 for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { |
1886 while (readLine() && line >> c && c != '@') { |
1903 while (readLine() && line >> c && c != '@') { |
1887 line.putback(c); |
1904 line.putback(c); |
1888 |
1905 |
1889 std::string attr, token; |
1906 std::string attr, token; |
1890 if (!_reader_bits::readToken(line, attr)) |
1907 if (!_reader_bits::readToken(line, attr)) |
1891 throw DataFormatError("Attribute name not found"); |
1908 throw FormatError("Attribute name not found"); |
1892 if (!_reader_bits::readToken(line, token)) |
1909 if (!_reader_bits::readToken(line, token)) |
1893 throw DataFormatError("Attribute value not found"); |
1910 throw FormatError("Attribute value not found"); |
1894 if (line >> c) |
1911 if (line >> c) |
1895 throw DataFormatError("Extra character on the end of line"); |
1912 throw FormatError("Extra character on the end of line"); |
1896 |
1913 |
1897 { |
1914 { |
1898 std::set<std::string>::iterator it = read_attr.find(attr); |
1915 std::set<std::string>::iterator it = read_attr.find(attr); |
1899 if (it != read_attr.end()) { |
1916 if (it != read_attr.end()) { |
1900 std::ostringstream msg; |
1917 std::ostringstream msg; |
1901 msg << "Multiple occurence of attribute " << attr; |
1918 msg << "Multiple occurence of attribute " << attr; |
1902 throw DataFormatError(msg.str().c_str()); |
1919 throw FormatError(msg.str()); |
1903 } |
1920 } |
1904 read_attr.insert(attr); |
1921 read_attr.insert(attr); |
1905 } |
1922 } |
1906 |
1923 |
1907 { |
1924 { |
2072 |
2091 |
2073 /// \brief Constructor |
2092 /// \brief Constructor |
2074 /// |
2093 /// |
2075 /// Construct a section reader, which reads from the given file. |
2094 /// Construct a section reader, which reads from the given file. |
2076 SectionReader(const std::string& fn) |
2095 SectionReader(const std::string& fn) |
2077 : _is(new std::ifstream(fn.c_str())), local_is(true) {} |
2096 : _is(new std::ifstream(fn.c_str())), local_is(true), |
|
2097 _filename(fn) { |
|
2098 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
2099 } |
2078 |
2100 |
2079 /// \brief Constructor |
2101 /// \brief Constructor |
2080 /// |
2102 /// |
2081 /// Construct a section reader, which reads from the given file. |
2103 /// Construct a section reader, which reads from the given file. |
2082 SectionReader(const char* fn) |
2104 SectionReader(const char* fn) |
2083 : _is(new std::ifstream(fn)), local_is(true) {} |
2105 : _is(new std::ifstream(fn)), local_is(true), |
|
2106 _filename(fn) { |
|
2107 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
2108 } |
2084 |
2109 |
2085 /// \brief Destructor |
2110 /// \brief Destructor |
2086 ~SectionReader() { |
2111 ~SectionReader() { |
2087 for (Sections::iterator it = _sections.begin(); |
2112 for (Sections::iterator it = _sections.begin(); |
2088 it != _sections.end(); ++it) { |
2113 it != _sections.end(); ++it) { |
2234 line >> c; |
2259 line >> c; |
2235 _reader_bits::readToken(line, section); |
2260 _reader_bits::readToken(line, section); |
2236 _reader_bits::readToken(line, caption); |
2261 _reader_bits::readToken(line, caption); |
2237 |
2262 |
2238 if (line >> c) |
2263 if (line >> c) |
2239 throw DataFormatError("Extra character on the end of line"); |
2264 throw FormatError("Extra character on the end of line"); |
2240 |
2265 |
2241 if (extra_sections.find(section) != extra_sections.end()) { |
2266 if (extra_sections.find(section) != extra_sections.end()) { |
2242 std::ostringstream msg; |
2267 std::ostringstream msg; |
2243 msg << "Multiple occurence of section " << section; |
2268 msg << "Multiple occurence of section " << section; |
2244 throw DataFormatError(msg.str().c_str()); |
2269 throw FormatError(msg.str()); |
2245 } |
2270 } |
2246 Sections::iterator it = _sections.find(section); |
2271 Sections::iterator it = _sections.find(section); |
2247 if (it != _sections.end()) { |
2272 if (it != _sections.end()) { |
2248 extra_sections.insert(section); |
2273 extra_sections.insert(section); |
2249 it->second->process(*_is, line_num); |
2274 it->second->process(*_is, line_num); |
2250 } |
2275 } |
2251 readLine(); |
2276 readLine(); |
2252 skipSection(); |
2277 skipSection(); |
2253 } catch (DataFormatError& error) { |
2278 } catch (FormatError& error) { |
2254 error.line(line_num); |
2279 error.line(line_num); |
|
2280 error.file(_filename); |
2255 throw; |
2281 throw; |
2256 } |
2282 } |
2257 } |
2283 } |
2258 for (Sections::iterator it = _sections.begin(); |
2284 for (Sections::iterator it = _sections.begin(); |
2259 it != _sections.end(); ++it) { |
2285 it != _sections.end(); ++it) { |
2260 if (extra_sections.find(it->first) == extra_sections.end()) { |
2286 if (extra_sections.find(it->first) == extra_sections.end()) { |
2261 std::ostringstream os; |
2287 std::ostringstream os; |
2262 os << "Cannot find section: " << it->first; |
2288 os << "Cannot find section: " << it->first; |
2263 throw DataFormatError(os.str().c_str()); |
2289 throw FormatError(os.str()); |
2264 } |
2290 } |
2265 } |
2291 } |
2266 } |
2292 } |
2267 |
2293 |
2268 /// @} |
2294 /// @} |
2358 /// \brief Constructor |
2384 /// \brief Constructor |
2359 /// |
2385 /// |
2360 /// Construct an \e LGF contents reader, which reads from the given |
2386 /// Construct an \e LGF contents reader, which reads from the given |
2361 /// file. |
2387 /// file. |
2362 LgfContents(const std::string& fn) |
2388 LgfContents(const std::string& fn) |
2363 : _is(new std::ifstream(fn.c_str())), local_is(true) {} |
2389 : _is(new std::ifstream(fn.c_str())), local_is(true) { |
|
2390 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
2391 } |
2364 |
2392 |
2365 /// \brief Constructor |
2393 /// \brief Constructor |
2366 /// |
2394 /// |
2367 /// Construct an \e LGF contents reader, which reads from the given |
2395 /// Construct an \e LGF contents reader, which reads from the given |
2368 /// file. |
2396 /// file. |
2369 LgfContents(const char* fn) |
2397 LgfContents(const char* fn) |
2370 : _is(new std::ifstream(fn)), local_is(true) {} |
2398 : _is(new std::ifstream(fn)), local_is(true) { |
|
2399 if (!(*_is)) throw IoError(fn, "Cannot open file"); |
|
2400 } |
2371 |
2401 |
2372 /// \brief Destructor |
2402 /// \brief Destructor |
2373 ~LgfContents() { |
2403 ~LgfContents() { |
2374 if (local_is) delete _is; |
2404 if (local_is) delete _is; |
2375 } |
2405 } |