| ... | ... |
@@ -2049,142 +2049,142 @@ |
| 2049 | 2049 |
/// \relates GraphReader |
| 2050 | 2050 |
template <typename Graph> |
| 2051 | 2051 |
GraphReader<Graph> graphReader(std::istream& is, Graph& graph) {
|
| 2052 | 2052 |
GraphReader<Graph> tmp(is, graph); |
| 2053 | 2053 |
return tmp; |
| 2054 | 2054 |
} |
| 2055 | 2055 |
|
| 2056 | 2056 |
/// \relates GraphReader |
| 2057 | 2057 |
template <typename Graph> |
| 2058 | 2058 |
GraphReader<Graph> graphReader(const std::string& fn, |
| 2059 | 2059 |
Graph& graph) {
|
| 2060 | 2060 |
GraphReader<Graph> tmp(fn, graph); |
| 2061 | 2061 |
return tmp; |
| 2062 | 2062 |
} |
| 2063 | 2063 |
|
| 2064 | 2064 |
/// \relates GraphReader |
| 2065 | 2065 |
template <typename Graph> |
| 2066 | 2066 |
GraphReader<Graph> graphReader(const char* fn, Graph& graph) {
|
| 2067 | 2067 |
GraphReader<Graph> tmp(fn, graph); |
| 2068 | 2068 |
return tmp; |
| 2069 | 2069 |
} |
| 2070 | 2070 |
|
| 2071 | 2071 |
/// \ingroup lemon_io |
| 2072 | 2072 |
/// |
| 2073 |
/// \brief Reader for the |
|
| 2073 |
/// \brief Reader for the contents of the \ref lgf-format "LGF" file |
|
| 2074 | 2074 |
/// |
| 2075 | 2075 |
/// This class can be used to read the sections, the map names and |
| 2076 | 2076 |
/// the attributes from a file. Usually, the Lemon programs know |
| 2077 | 2077 |
/// that, which type of graph, which maps and which attributes |
| 2078 | 2078 |
/// should be read from a file, but in general tools (like glemon) |
| 2079 |
/// the |
|
| 2079 |
/// the contents of an LGF file should be guessed somehow. This class |
|
| 2080 | 2080 |
/// reads the graph and stores the appropriate information for |
| 2081 | 2081 |
/// reading the graph. |
| 2082 | 2082 |
/// |
| 2083 |
///\code LgfContent content("graph.lgf");
|
|
| 2084 |
/// content.run(); |
|
| 2083 |
///\code LgfContents contents("graph.lgf");
|
|
| 2084 |
/// contents.run(); |
|
| 2085 | 2085 |
/// |
| 2086 | 2086 |
/// // does it contain any node section and arc section |
| 2087 |
/// if ( |
|
| 2087 |
/// if (contents.nodeSectionNum() == 0 || contents.arcSectionNum()) {
|
|
| 2088 | 2088 |
/// std::cerr << "Failure, cannot find graph" << std::endl; |
| 2089 | 2089 |
/// return -1; |
| 2090 | 2090 |
/// } |
| 2091 | 2091 |
/// std::cout << "The name of the default node section : " |
| 2092 |
/// << |
|
| 2092 |
/// << contents.nodeSection(0) << std::endl; |
|
| 2093 | 2093 |
/// std::cout << "The number of the arc maps : " |
| 2094 |
/// << |
|
| 2094 |
/// << contents.arcMaps(0).size() << std::endl; |
|
| 2095 | 2095 |
/// std::cout << "The name of second arc map : " |
| 2096 |
/// << |
|
| 2096 |
/// << contents.arcMaps(0)[1] << std::endl; |
|
| 2097 | 2097 |
///\endcode |
| 2098 |
class |
|
| 2098 |
class LgfContents {
|
|
| 2099 | 2099 |
private: |
| 2100 | 2100 |
|
| 2101 | 2101 |
std::istream* _is; |
| 2102 | 2102 |
bool local_is; |
| 2103 | 2103 |
|
| 2104 | 2104 |
std::vector<std::string> _node_sections; |
| 2105 | 2105 |
std::vector<std::string> _edge_sections; |
| 2106 | 2106 |
std::vector<std::string> _attribute_sections; |
| 2107 | 2107 |
std::vector<std::string> _extra_sections; |
| 2108 | 2108 |
|
| 2109 | 2109 |
std::vector<bool> _arc_sections; |
| 2110 | 2110 |
|
| 2111 | 2111 |
std::vector<std::vector<std::string> > _node_maps; |
| 2112 | 2112 |
std::vector<std::vector<std::string> > _edge_maps; |
| 2113 | 2113 |
|
| 2114 | 2114 |
std::vector<std::vector<std::string> > _attributes; |
| 2115 | 2115 |
|
| 2116 | 2116 |
|
| 2117 | 2117 |
int line_num; |
| 2118 | 2118 |
std::istringstream line; |
| 2119 | 2119 |
|
| 2120 | 2120 |
public: |
| 2121 | 2121 |
|
| 2122 | 2122 |
/// \brief Constructor |
| 2123 | 2123 |
/// |
| 2124 |
/// Construct an \e LGF |
|
| 2124 |
/// Construct an \e LGF contents reader, which reads from the given |
|
| 2125 | 2125 |
/// input stream. |
| 2126 |
|
|
| 2126 |
LgfContents(std::istream& is) |
|
| 2127 | 2127 |
: _is(&is), local_is(false) {}
|
| 2128 | 2128 |
|
| 2129 | 2129 |
/// \brief Constructor |
| 2130 | 2130 |
/// |
| 2131 |
/// Construct an \e LGF |
|
| 2131 |
/// Construct an \e LGF contents reader, which reads from the given |
|
| 2132 | 2132 |
/// file. |
| 2133 |
|
|
| 2133 |
LgfContents(const std::string& fn) |
|
| 2134 | 2134 |
: _is(new std::ifstream(fn.c_str())), local_is(true) {}
|
| 2135 | 2135 |
|
| 2136 | 2136 |
/// \brief Constructor |
| 2137 | 2137 |
/// |
| 2138 |
/// Construct an \e LGF |
|
| 2138 |
/// Construct an \e LGF contents reader, which reads from the given |
|
| 2139 | 2139 |
/// file. |
| 2140 |
|
|
| 2140 |
LgfContents(const char* fn) |
|
| 2141 | 2141 |
: _is(new std::ifstream(fn)), local_is(true) {}
|
| 2142 | 2142 |
|
| 2143 | 2143 |
/// \brief Copy constructor |
| 2144 | 2144 |
/// |
| 2145 | 2145 |
/// The copy constructor transfers all data from the other reader, |
| 2146 | 2146 |
/// therefore the copied reader will not be usable more. |
| 2147 |
|
|
| 2147 |
LgfContents(LgfContents& other) |
|
| 2148 | 2148 |
: _is(other._is), local_is(other.local_is) {
|
| 2149 | 2149 |
|
| 2150 | 2150 |
other._is = 0; |
| 2151 | 2151 |
other.local_is = false; |
| 2152 | 2152 |
|
| 2153 | 2153 |
_node_sections.swap(other._node_sections); |
| 2154 | 2154 |
_edge_sections.swap(other._edge_sections); |
| 2155 | 2155 |
_attribute_sections.swap(other._attribute_sections); |
| 2156 | 2156 |
_extra_sections.swap(other._extra_sections); |
| 2157 | 2157 |
|
| 2158 | 2158 |
_arc_sections.swap(other._arc_sections); |
| 2159 | 2159 |
|
| 2160 | 2160 |
_node_maps.swap(other._node_maps); |
| 2161 | 2161 |
_edge_maps.swap(other._edge_maps); |
| 2162 | 2162 |
_attributes.swap(other._attributes); |
| 2163 | 2163 |
} |
| 2164 | 2164 |
|
| 2165 | 2165 |
/// \brief Destructor |
| 2166 |
~ |
|
| 2166 |
~LgfContents() {
|
|
| 2167 | 2167 |
if (local_is) delete _is; |
| 2168 | 2168 |
} |
| 2169 | 2169 |
|
| 2170 | 2170 |
|
| 2171 | 2171 |
/// \name Node sections |
| 2172 | 2172 |
/// @{
|
| 2173 | 2173 |
|
| 2174 | 2174 |
/// \brief Gives back the number of node sections in the file. |
| 2175 | 2175 |
/// |
| 2176 | 2176 |
/// Gives back the number of node sections in the file. |
| 2177 | 2177 |
int nodeSectionNum() const {
|
| 2178 | 2178 |
return _node_sections.size(); |
| 2179 | 2179 |
} |
| 2180 | 2180 |
|
| 2181 | 2181 |
/// \brief Returns the section name at the given position. |
| 2182 | 2182 |
/// |
| 2183 | 2183 |
/// Returns the section name at the given position. |
| 2184 | 2184 |
const std::string& nodeSection(int i) const {
|
| 2185 | 2185 |
return _node_sections[i]; |
| 2186 | 2186 |
} |
| 2187 | 2187 |
|
| 2188 | 2188 |
/// \brief Gives back the node maps for the given section. |
| 2189 | 2189 |
/// |
| 2190 | 2190 |
/// Gives back the node maps for the given section. |
| ... | ... |
@@ -2338,49 +2338,49 @@ |
| 2338 | 2338 |
void readMaps(std::vector<std::string>& maps) {
|
| 2339 | 2339 |
if (!readLine()) |
| 2340 | 2340 |
throw DataFormatError("Cannot find map captions");
|
| 2341 | 2341 |
std::string map; |
| 2342 | 2342 |
while (_reader_bits::readToken(line, map)) {
|
| 2343 | 2343 |
maps.push_back(map); |
| 2344 | 2344 |
} |
| 2345 | 2345 |
} |
| 2346 | 2346 |
|
| 2347 | 2347 |
void readAttributes(std::vector<std::string>& attrs) {
|
| 2348 | 2348 |
readLine(); |
| 2349 | 2349 |
char c; |
| 2350 | 2350 |
while (readSuccess() && line >> c && c != '@') {
|
| 2351 | 2351 |
line.putback(c); |
| 2352 | 2352 |
std::string attr; |
| 2353 | 2353 |
_reader_bits::readToken(line, attr); |
| 2354 | 2354 |
attrs.push_back(attr); |
| 2355 | 2355 |
readLine(); |
| 2356 | 2356 |
} |
| 2357 | 2357 |
line.putback(c); |
| 2358 | 2358 |
} |
| 2359 | 2359 |
|
| 2360 | 2360 |
public: |
| 2361 | 2361 |
|
| 2362 |
/// \name Execution of the |
|
| 2362 |
/// \name Execution of the contents reader |
|
| 2363 | 2363 |
/// @{
|
| 2364 | 2364 |
|
| 2365 | 2365 |
/// \brief Start the reading |
| 2366 | 2366 |
/// |
| 2367 | 2367 |
/// This function starts the reading |
| 2368 | 2368 |
void run() {
|
| 2369 | 2369 |
|
| 2370 | 2370 |
readLine(); |
| 2371 | 2371 |
skipSection(); |
| 2372 | 2372 |
|
| 2373 | 2373 |
while (readSuccess()) {
|
| 2374 | 2374 |
|
| 2375 | 2375 |
char c; |
| 2376 | 2376 |
line >> c; |
| 2377 | 2377 |
|
| 2378 | 2378 |
std::string section, caption; |
| 2379 | 2379 |
_reader_bits::readToken(line, section); |
| 2380 | 2380 |
_reader_bits::readToken(line, caption); |
| 2381 | 2381 |
|
| 2382 | 2382 |
if (section == "nodes") {
|
| 2383 | 2383 |
_node_sections.push_back(caption); |
| 2384 | 2384 |
_node_maps.push_back(std::vector<std::string>()); |
| 2385 | 2385 |
readMaps(_node_maps.back()); |
| 2386 | 2386 |
readLine(); skipSection(); |
0 comments (0 inline)