x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
adjacency_list_io.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\graph\adjacency_list_io.hpp
旋转
特效
属性
历史版本
//======================================================================= // Copyright 2001 Universite Joseph Fourier, Grenoble. // Author: Fran�ois Faure // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= #ifndef BOOST_GRAPH_ADJACENCY_LIST_IO_HPP #define BOOST_GRAPH_ADJACENCY_LIST_IO_HPP #include
#include
#include
#include
// Method read to parse an adjacency list from an input stream. Examples: // cin >> read( G ); // cin >> read( G, NodePropertySubset(), EdgepropertySubset() ); // // Method write to print an adjacency list to an output stream. Examples: // cout << write( G ); // cout << write( G, NodePropertySubset(), EdgepropertySubset() ); namespace boost { /* outline - basic property input - get property subset - graph parser - property printer - graph printer - user methods */ //=========================================================================== // basic property input template
std::istream& operator >> ( std::istream& in, property
& p ) { in >> p.m_value >> *(static_cast
(&p)); // houpla !! return in; } template
std::istream& operator >> ( std::istream& in, property
& p ) { in >> p.m_value; return in; } inline std::istream& operator >> ( std::istream& in, no_property& ) { return in; } // basic property input //=========================================================================== // get property subsets // get a single property tagged Stag template
void get ( property
& p, const V& v, Stag s ) { get( *(static_cast
(&p)),v,s ); } template
void get ( property
& p, const V& v, Stag ) { p.m_value = v; } // get a subset of properties tagged Stag template
void getSubset ( property
& p, const property
& s ) { get( p, s.m_value, Stag() ); getSubset( p, Snext(s) ); } template
void getSubset ( property
& p, const property
& s) { get( p, s.m_value, Stag() ); } inline void getSubset ( no_property& p, const no_property& s ) { } #if !defined(BOOST_GRAPH_NO_BUNDLED_PROPERTIES) template
void getSubset(T& p, const U& s) { p = s; } template
void getSubset(T&, const no_property&) { } #endif // get property subset //=========================================================================== // graph parser typedef enum{ PARSE_NUM_NODES, PARSE_VERTEX, PARSE_EDGE } GraphParserState; template
struct GraphParser { typedef Graph_t Graph; GraphParser( Graph* g ): graph(g) {} GraphParser& operator () ( std::istream& in ) { typedef typename graph_traits
::vertex_descriptor Vertex; std::vector
nodes; GraphParserState state = PARSE_VERTEX; unsigned int numLine = 1; char c; while ( in.get(c) ) { if( c== '#' ) skip(in); else if( c== 'n' ) state = PARSE_NUM_NODES; else if( c== 'v' ) state = PARSE_VERTEX; else if( c== 'e' ) state = PARSE_EDGE; else if( c== '\n' ) numLine++; else if( !std::isspace(c) ){ in.putback(c); if( state == PARSE_VERTEX ){ VertexPropertySubset readProp; if( in >> readProp ) { VertexProperty vp; getSubset( vp, readProp ); nodes.push_back( add_vertex(vp, *graph) ); } else std::cerr<<"read vertex, parse error at line"<
> source >> target; if( in >> readProp ) { EdgeProperty ep; getSubset( ep, readProp ); add_edge(nodes[source], nodes[target], ep, *graph); } else std::cerr<<"read edge, parse error at line"<
> n ){ for( int i=0; i
struct PropertyPrinter { typedef typename Property::value_type Value; typedef typename Property::tag_type Tag; typedef typename Property::next_type Next; PropertyPrinter( const Graph& g ):graph(&g){} template
PropertyPrinter& operator () ( std::ostream& out, Iterator it ) { typename property_map
::type ps = get(Tag(), *graph); out << ps[ *it ] <<" "; PropertyPrinter
print(*graph); print(out, it); return (*this); } private: const Graph* graph; }; #else template
struct PropertyPrinter { PropertyPrinter( const Graph& g ):graph(&g){} template
PropertyPrinter& operator () ( std::ostream& out, Iterator it ) { out << (*graph)[ *it ] <<" "; return (*this); } private: const Graph* graph; }; template
struct PropertyPrinter
> { PropertyPrinter( const Graph& g ):graph(&g){} template
PropertyPrinter& operator () ( std::ostream& out, Iterator it ) { typename property_map
::type ps = get(Tag(), *graph); out << ps[ *it ] <<" "; PropertyPrinter
print(*graph); print(out, it); return (*this); } private: const Graph* graph; }; #endif template
struct PropertyPrinter
{ PropertyPrinter( const Graph& ){} template
PropertyPrinter& operator () ( std::ostream&, Iterator it ){ return *this; } }; // property printer //========================================================================= // graph printer template
struct EdgePrinter { typedef Graph_t Graph; typedef typename graph_traits
::vertex_descriptor Vertex; EdgePrinter( const Graph& g ) : graph(g) {} const EdgePrinter& operator () ( std::ostream& out ) const { // assign indices to vertices std::map
indices; int num = 0; typename graph_traits
::vertex_iterator vi; for (vi = vertices(graph).first; vi != vertices(graph).second; ++vi){ indices[*vi] = num++; } // write edges PropertyPrinter
print_Edge(graph); out << "e" << std::endl; typename graph_traits
::edge_iterator ei; for (ei = edges(graph).first; ei != edges(graph).second; ++ei){ out << indices[source(*ei,graph)] << " " << indices[target(*ei,graph)] << " "; print_Edge(out,ei); out << std::endl; } out << std::endl; return (*this); } protected: const Graph& graph; }; template
struct GraphPrinter: public EdgePrinter
{ GraphPrinter( const Graph& g ) : EdgePrinter
(g) {} const GraphPrinter& operator () ( std::ostream& out ) const { PropertyPrinter
printNode(this->graph); out << "v"<
::vertex_iterator vi; for (vi = vertices(this->graph).first; vi != vertices(this->graph).second; ++vi){ printNode(out,vi); out << std::endl; } EdgePrinter
::operator ()( out ); return (*this); } }; template
struct GraphPrinter
: public EdgePrinter
{ GraphPrinter( const Graph& g ) : EdgePrinter
(g) {} const GraphPrinter& operator () ( std::ostream& out ) const { out << "n "<< num_vertices(this->graph) << std::endl; EdgePrinter
::operator ()( out ); return (*this); } }; // graph printer //========================================================================= // user methods /// input stream for reading a graph template
std::istream& operator >> ( std::istream& in, GraphParser
gp ) { gp(in); return in; } /// graph parser for given subsets of internal vertex and edge properties template
GraphParser
,VP,EP,VPS,EPS> read( adjacency_list
& g, VPS vps, EPS eps ) { return GraphParser
,VP,EP,VPS,EPS>(&g); } /// graph parser for all internal vertex and edge properties template
GraphParser
,VP,EP,VP,EP> read( adjacency_list
& g ) { return GraphParser
,VP,EP,VP,EP>(&g); } /// output stream for writing a graph template
std::ostream& operator << ( std::ostream& out, const GraphPrinter
& gp ) { gp(out); return out; } /// write the graph with given property subsets template
GraphPrinter
,VPS,EPS> write( const adjacency_list
& g, VPS, EPS ) { return GraphPrinter
,VPS,EPS>(g); } /// write the graph with all internal vertex and edge properties template
GraphPrinter
,VP,EP> write( const adjacency_list
& g ) { return GraphPrinter
,VP,EP>(g); } // user methods //========================================================================= }// boost #endif
adjacency_list_io.hpp
网页地址
文件地址
上一页
4/95
下一页
下载
( 13 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.