| ... | ... |
@@ -1094,140 +1094,138 @@ |
| 1094 | 1094 |
throw DataFormatError(msg.str().c_str()); |
| 1095 | 1095 |
} |
| 1096 | 1096 |
read_attr.insert(attr); |
| 1097 | 1097 |
} |
| 1098 | 1098 |
|
| 1099 | 1099 |
{
|
| 1100 | 1100 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
| 1101 | 1101 |
while (it != _attributes.end() && it->first == attr) {
|
| 1102 | 1102 |
it->second->set(token); |
| 1103 | 1103 |
++it; |
| 1104 | 1104 |
} |
| 1105 | 1105 |
} |
| 1106 | 1106 |
|
| 1107 | 1107 |
} |
| 1108 | 1108 |
if (readSuccess()) {
|
| 1109 | 1109 |
line.putback(c); |
| 1110 | 1110 |
} |
| 1111 | 1111 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1112 | 1112 |
it != _attributes.end(); ++it) {
|
| 1113 | 1113 |
if (read_attr.find(it->first) == read_attr.end()) {
|
| 1114 | 1114 |
std::ostringstream msg; |
| 1115 | 1115 |
msg << "Attribute not found in file: " << it->first; |
| 1116 | 1116 |
throw DataFormatError(msg.str().c_str()); |
| 1117 | 1117 |
} |
| 1118 | 1118 |
} |
| 1119 | 1119 |
} |
| 1120 | 1120 |
|
| 1121 | 1121 |
public: |
| 1122 | 1122 |
|
| 1123 | 1123 |
/// \name Execution of the reader |
| 1124 | 1124 |
/// @{
|
| 1125 | 1125 |
|
| 1126 | 1126 |
/// \brief Start the batch processing |
| 1127 | 1127 |
/// |
| 1128 | 1128 |
/// This function starts the batch processing |
| 1129 | 1129 |
void run() {
|
| 1130 | 1130 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
| 1131 | 1131 |
if (!*_is) {
|
| 1132 | 1132 |
throw DataFormatError("Cannot find file");
|
| 1133 | 1133 |
} |
| 1134 | 1134 |
|
| 1135 | 1135 |
bool nodes_done = false; |
| 1136 | 1136 |
bool arcs_done = false; |
| 1137 | 1137 |
bool attributes_done = false; |
| 1138 | 1138 |
std::set<std::string> extra_sections; |
| 1139 | 1139 |
|
| 1140 | 1140 |
line_num = 0; |
| 1141 | 1141 |
readLine(); |
| 1142 |
skipSection(); |
|
| 1142 | 1143 |
|
| 1143 | 1144 |
while (readSuccess()) {
|
| 1144 |
skipSection(); |
|
| 1145 | 1145 |
try {
|
| 1146 | 1146 |
char c; |
| 1147 | 1147 |
std::string section, caption; |
| 1148 | 1148 |
line >> c; |
| 1149 | 1149 |
_reader_bits::readToken(line, section); |
| 1150 | 1150 |
_reader_bits::readToken(line, caption); |
| 1151 | 1151 |
|
| 1152 | 1152 |
if (line >> c) |
| 1153 | 1153 |
throw DataFormatError("Extra character on the end of line");
|
| 1154 | 1154 |
|
| 1155 | 1155 |
if (section == "nodes" && !nodes_done) {
|
| 1156 | 1156 |
if (_nodes_caption.empty() || _nodes_caption == caption) {
|
| 1157 | 1157 |
readNodes(); |
| 1158 | 1158 |
nodes_done = true; |
| 1159 | 1159 |
} |
| 1160 | 1160 |
} else if ((section == "arcs" || section == "edges") && |
| 1161 | 1161 |
!arcs_done) {
|
| 1162 | 1162 |
if (_arcs_caption.empty() || _arcs_caption == caption) {
|
| 1163 | 1163 |
readArcs(); |
| 1164 | 1164 |
arcs_done = true; |
| 1165 | 1165 |
} |
| 1166 | 1166 |
} else if (section == "attributes" && !attributes_done) {
|
| 1167 | 1167 |
if (_attributes_caption.empty() || _attributes_caption == caption) {
|
| 1168 | 1168 |
readAttributes(); |
| 1169 | 1169 |
attributes_done = true; |
| 1170 | 1170 |
} |
| 1171 | 1171 |
} else {
|
| 1172 | 1172 |
if (extra_sections.find(section) != extra_sections.end()) {
|
| 1173 | 1173 |
std::ostringstream msg; |
| 1174 | 1174 |
msg << "Multiple occurence of section " << section; |
| 1175 | 1175 |
throw DataFormatError(msg.str().c_str()); |
| 1176 | 1176 |
} |
| 1177 | 1177 |
Sections::iterator it = _sections.find(section); |
| 1178 | 1178 |
if (it != _sections.end()) {
|
| 1179 | 1179 |
extra_sections.insert(section); |
| 1180 | 1180 |
it->second->process(*_is, line_num); |
| 1181 |
readLine(); |
|
| 1182 |
} else {
|
|
| 1183 |
readLine(); |
|
| 1184 |
skipSection(); |
|
| 1185 | 1181 |
} |
| 1182 |
readLine(); |
|
| 1183 |
skipSection(); |
|
| 1186 | 1184 |
} |
| 1187 | 1185 |
} catch (DataFormatError& error) {
|
| 1188 | 1186 |
error.line(line_num); |
| 1189 | 1187 |
throw; |
| 1190 | 1188 |
} |
| 1191 | 1189 |
} |
| 1192 | 1190 |
|
| 1193 | 1191 |
if (!nodes_done) {
|
| 1194 | 1192 |
throw DataFormatError("Section @nodes not found");
|
| 1195 | 1193 |
} |
| 1196 | 1194 |
|
| 1197 | 1195 |
if (!arcs_done) {
|
| 1198 | 1196 |
throw DataFormatError("Section @arcs not found");
|
| 1199 | 1197 |
} |
| 1200 | 1198 |
|
| 1201 | 1199 |
if (!attributes_done && !_attributes.empty()) {
|
| 1202 | 1200 |
throw DataFormatError("Section @attributes not found");
|
| 1203 | 1201 |
} |
| 1204 | 1202 |
|
| 1205 | 1203 |
} |
| 1206 | 1204 |
|
| 1207 | 1205 |
/// @} |
| 1208 | 1206 |
|
| 1209 | 1207 |
}; |
| 1210 | 1208 |
|
| 1211 | 1209 |
/// \relates DigraphReader |
| 1212 | 1210 |
template <typename Digraph> |
| 1213 | 1211 |
DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
|
| 1214 | 1212 |
DigraphReader<Digraph> tmp(is, digraph); |
| 1215 | 1213 |
return tmp; |
| 1216 | 1214 |
} |
| 1217 | 1215 |
|
| 1218 | 1216 |
/// \relates DigraphReader |
| 1219 | 1217 |
template <typename Digraph> |
| 1220 | 1218 |
DigraphReader<Digraph> digraphReader(const std::string& fn, |
| 1221 | 1219 |
Digraph& digraph) {
|
| 1222 | 1220 |
DigraphReader<Digraph> tmp(fn, digraph); |
| 1223 | 1221 |
return tmp; |
| 1224 | 1222 |
} |
| 1225 | 1223 |
|
| 1226 | 1224 |
/// \relates DigraphReader |
| 1227 | 1225 |
template <typename Digraph> |
| 1228 | 1226 |
DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
|
| 1229 | 1227 |
DigraphReader<Digraph> tmp(fn, digraph); |
| 1230 | 1228 |
return tmp; |
| 1231 | 1229 |
} |
| 1232 | 1230 |
|
| 1233 | 1231 |
/// \ingroup lemon_io |
| ... | ... |
@@ -1936,140 +1934,138 @@ |
| 1936 | 1934 |
std::ostringstream msg; |
| 1937 | 1935 |
msg << "Multiple occurence of attribute " << attr; |
| 1938 | 1936 |
throw DataFormatError(msg.str().c_str()); |
| 1939 | 1937 |
} |
| 1940 | 1938 |
read_attr.insert(attr); |
| 1941 | 1939 |
} |
| 1942 | 1940 |
|
| 1943 | 1941 |
{
|
| 1944 | 1942 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
| 1945 | 1943 |
while (it != _attributes.end() && it->first == attr) {
|
| 1946 | 1944 |
it->second->set(token); |
| 1947 | 1945 |
++it; |
| 1948 | 1946 |
} |
| 1949 | 1947 |
} |
| 1950 | 1948 |
|
| 1951 | 1949 |
} |
| 1952 | 1950 |
if (readSuccess()) {
|
| 1953 | 1951 |
line.putback(c); |
| 1954 | 1952 |
} |
| 1955 | 1953 |
for (typename Attributes::iterator it = _attributes.begin(); |
| 1956 | 1954 |
it != _attributes.end(); ++it) {
|
| 1957 | 1955 |
if (read_attr.find(it->first) == read_attr.end()) {
|
| 1958 | 1956 |
std::ostringstream msg; |
| 1959 | 1957 |
msg << "Attribute not found in file: " << it->first; |
| 1960 | 1958 |
throw DataFormatError(msg.str().c_str()); |
| 1961 | 1959 |
} |
| 1962 | 1960 |
} |
| 1963 | 1961 |
} |
| 1964 | 1962 |
|
| 1965 | 1963 |
public: |
| 1966 | 1964 |
|
| 1967 | 1965 |
/// \name Execution of the reader |
| 1968 | 1966 |
/// @{
|
| 1969 | 1967 |
|
| 1970 | 1968 |
/// \brief Start the batch processing |
| 1971 | 1969 |
/// |
| 1972 | 1970 |
/// This function starts the batch processing |
| 1973 | 1971 |
void run() {
|
| 1974 | 1972 |
|
| 1975 | 1973 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
| 1976 | 1974 |
|
| 1977 | 1975 |
bool nodes_done = false; |
| 1978 | 1976 |
bool edges_done = false; |
| 1979 | 1977 |
bool attributes_done = false; |
| 1980 | 1978 |
std::set<std::string> extra_sections; |
| 1981 | 1979 |
|
| 1982 | 1980 |
line_num = 0; |
| 1983 | 1981 |
readLine(); |
| 1982 |
skipSection(); |
|
| 1984 | 1983 |
|
| 1985 | 1984 |
while (readSuccess()) {
|
| 1986 |
skipSection(); |
|
| 1987 | 1985 |
try {
|
| 1988 | 1986 |
char c; |
| 1989 | 1987 |
std::string section, caption; |
| 1990 | 1988 |
line >> c; |
| 1991 | 1989 |
_reader_bits::readToken(line, section); |
| 1992 | 1990 |
_reader_bits::readToken(line, caption); |
| 1993 | 1991 |
|
| 1994 | 1992 |
if (line >> c) |
| 1995 | 1993 |
throw DataFormatError("Extra character on the end of line");
|
| 1996 | 1994 |
|
| 1997 | 1995 |
if (section == "nodes" && !nodes_done) {
|
| 1998 | 1996 |
if (_nodes_caption.empty() || _nodes_caption == caption) {
|
| 1999 | 1997 |
readNodes(); |
| 2000 | 1998 |
nodes_done = true; |
| 2001 | 1999 |
} |
| 2002 | 2000 |
} else if ((section == "edges" || section == "arcs") && |
| 2003 | 2001 |
!edges_done) {
|
| 2004 | 2002 |
if (_edges_caption.empty() || _edges_caption == caption) {
|
| 2005 | 2003 |
readEdges(); |
| 2006 | 2004 |
edges_done = true; |
| 2007 | 2005 |
} |
| 2008 | 2006 |
} else if (section == "attributes" && !attributes_done) {
|
| 2009 | 2007 |
if (_attributes_caption.empty() || _attributes_caption == caption) {
|
| 2010 | 2008 |
readAttributes(); |
| 2011 | 2009 |
attributes_done = true; |
| 2012 | 2010 |
} |
| 2013 | 2011 |
} else {
|
| 2014 | 2012 |
if (extra_sections.find(section) != extra_sections.end()) {
|
| 2015 | 2013 |
std::ostringstream msg; |
| 2016 | 2014 |
msg << "Multiple occurence of section " << section; |
| 2017 | 2015 |
throw DataFormatError(msg.str().c_str()); |
| 2018 | 2016 |
} |
| 2019 | 2017 |
Sections::iterator it = _sections.find(section); |
| 2020 | 2018 |
if (it != _sections.end()) {
|
| 2021 | 2019 |
extra_sections.insert(section); |
| 2022 | 2020 |
it->second->process(*_is, line_num); |
| 2023 |
readLine(); |
|
| 2024 |
} else {
|
|
| 2025 |
readLine(); |
|
| 2026 |
skipSection(); |
|
| 2027 | 2021 |
} |
| 2022 |
readLine(); |
|
| 2023 |
skipSection(); |
|
| 2028 | 2024 |
} |
| 2029 | 2025 |
} catch (DataFormatError& error) {
|
| 2030 | 2026 |
error.line(line_num); |
| 2031 | 2027 |
throw; |
| 2032 | 2028 |
} |
| 2033 | 2029 |
} |
| 2034 | 2030 |
|
| 2035 | 2031 |
if (!nodes_done) {
|
| 2036 | 2032 |
throw DataFormatError("Section @nodes not found");
|
| 2037 | 2033 |
} |
| 2038 | 2034 |
|
| 2039 | 2035 |
if (!edges_done) {
|
| 2040 | 2036 |
throw DataFormatError("Section @edges not found");
|
| 2041 | 2037 |
} |
| 2042 | 2038 |
|
| 2043 | 2039 |
if (!attributes_done && !_attributes.empty()) {
|
| 2044 | 2040 |
throw DataFormatError("Section @attributes not found");
|
| 2045 | 2041 |
} |
| 2046 | 2042 |
|
| 2047 | 2043 |
} |
| 2048 | 2044 |
|
| 2049 | 2045 |
/// @} |
| 2050 | 2046 |
|
| 2051 | 2047 |
}; |
| 2052 | 2048 |
|
| 2053 | 2049 |
/// \relates GraphReader |
| 2054 | 2050 |
template <typename Graph> |
| 2055 | 2051 |
GraphReader<Graph> graphReader(std::istream& is, Graph& graph) {
|
| 2056 | 2052 |
GraphReader<Graph> tmp(is, graph); |
| 2057 | 2053 |
return tmp; |
| 2058 | 2054 |
} |
| 2059 | 2055 |
|
| 2060 | 2056 |
/// \relates GraphReader |
| 2061 | 2057 |
template <typename Graph> |
| 2062 | 2058 |
GraphReader<Graph> graphReader(const std::string& fn, |
| 2063 | 2059 |
Graph& graph) {
|
| 2064 | 2060 |
GraphReader<Graph> tmp(fn, graph); |
| 2065 | 2061 |
return tmp; |
| 2066 | 2062 |
} |
| 2067 | 2063 |
|
| 2068 | 2064 |
/// \relates GraphReader |
| 2069 | 2065 |
template <typename Graph> |
| 2070 | 2066 |
GraphReader<Graph> graphReader(const char* fn, Graph& graph) {
|
| 2071 | 2067 |
GraphReader<Graph> tmp(fn, graph); |
| 2072 | 2068 |
return tmp; |
| 2073 | 2069 |
} |
| 2074 | 2070 |
} |
| 2075 | 2071 |
|
0 comments (0 inline)