Ticket #35: digraph_reader_doc.2.patch
File digraph_reader_doc.2.patch, 12.6 KB (added by , 17 years ago) |
---|
-
lemon/lgf_reader.h
# HG changeset patch # User Balazs Dezso <deba@inf.elte.hu> # Date 1210585936 -7200 # Node ID ca6187a8a44be3b44e0292fc39c515c1ea5cd58e # Parent 5c3604513ed0256e35e5fd50c54cd0e37362397e Documentation for DigraphReader diff -r 5c3604513ed0 -r ca6187a8a44b lemon/lgf_reader.h
a b 295 295 } 296 296 297 297 } 298 299 /// \e 298 299 /// \ingroup lemon_io 300 /// 301 /// \brief LGF reader for directed graphs 302 /// 303 /// The \e LGF (LEMON graph file) format is the default file format 304 /// of the LEMON library. It is a text based, section oriented 305 /// format, which defines some standard sections for storing graphs 306 /// in text files. Each line with \c '#' first non-whitespace 307 /// character is considered as a comment line. Each section starts with 308 /// a header line, these lines starts with \c '@' character and the 309 /// name of section type. The standard sections are \c \@nodes, \c 310 /// \@arcs and \c \@edges (these two names are completely equivalent) 311 /// and \@attributes. Each header line may also have an optional 312 /// name, which can be use to distinguish the sections of the same 313 /// type. 314 /// 315 /// The \@nodes section describes a set of nodes and associated 316 /// maps. The first is a header line consisting of the names of the 317 /// maps, each of them is a sequence of underscore, letter and digit 318 /// characters. One of the maps must be called \c "label", which 319 /// plays special role in the file. Each following non-empty line 320 /// until the next section describes a node in the graph. These 321 /// lines contain the values of the node maps associated to the 322 /// current node. The values are plain or quoted tokens, a plain 323 /// token is a sequence of non-whitespace characters. A quoted 324 /// token is a character sequence surrounded by double quotes, and 325 /// the sequence may contain escape sequences. 326 /// 327 /// The \c \@arcs section is very similar to the \c \@nodes section, 328 /// it starts with a header line consists from the names of the arc 329 /// maps, the \c "label" map is also necessary. The following lines 330 /// contain the description of the arcs. The first two tokens are 331 /// the source and the target node of the edge, then comes the map 332 /// values. The source and target tokens must be node labels. 333 /// 334 /// The \c \@attrbiutes section contains key-value pairs, each line 335 /// starts with an attribute name, and then an attribute value. The 336 /// name is a sequence of underscore, letter and digit characters, 337 /// while the value is plain or quoted string literal. The value 338 /// could be a node or an arc label. 339 /// 340 ///\code 341 /// @nodes 342 /// label coordinates size title 343 /// 1 (10,20) 10 "First node" 344 /// 2 (80,80) 8 "Second node" 345 /// 3 (40,10) 10 "Third node" 346 /// @arcs 347 /// capacity 348 /// 1 2 16 349 /// 1 3 12 350 /// 2 3 18 351 /// @attributes 352 /// source 1 353 /// target 3 354 /// caption "LEMON test digraph" 355 ///\endcode 356 /// 357 /// The reading method does a batch processing. The user creates a 358 /// reader object, then several reading rules can be added to the 359 /// reader, and eventually the reading is executed with the \c run() 360 /// member function. A map reading rule can be added to the reader 361 /// with the \c nodeMap() or \c arcMap() members. The optional 362 /// converter parameter can be a standard functor, which converts an 363 /// std::string to the value type of the map, if it is set, it 364 /// determines how the read string literal is converted to the map's 365 /// value type. If the functor is not set, then a default conversion 366 /// will be used. One map can be read in multiple map objects at the 367 /// same time. The \c attribute(), \c node() and \c arc() functions 368 /// are used to add attribute reading rules. 369 /// 370 ///\code 371 /// DigraphReader<Digraph>(std::cin, digraph). 372 /// nodeMap("coordinates", coord_map). 373 /// arcMap("capacity", cap_map). 374 /// node("source", src). 375 /// node("target", trg). 376 /// attribute("caption", caption). 377 /// run(); 378 ///\endcode 379 /// 380 /// By default the reader uses the first section in the file of the 381 /// proper type. If a section has an optional name, then it can be 382 /// selected to read with the \c nodes(), \c arcs() or \c attributes() 383 /// functions. 384 /// 385 /// The \c useNodes() and \c useArcs() functions are used to specify 386 /// that the nodes or arcs should not be constructed(added to the 387 /// graph) during the reading, the argument of these functions is a 388 /// node map or arc map determining the label map for the items. An 389 /// application of these function is the multipass reading, which is 390 /// important if two \e \@arcs section should be read from the 391 /// file. In this example the first phase reads the node set and one 392 /// of the arc set, while the second phase will read the second arc 393 /// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet), 394 /// the previously read label node map should be given to the \c 395 /// useNodes() functions. An other multipass application is reading 396 /// paths into a node map or an arc map. It is impossible in 397 /// single pass, because the arcs are not constructed when the node 398 /// maps are read. 300 399 template <typename _Digraph> 301 400 class DigraphReader { 302 401 public: … … 341 440 342 441 public: 343 442 344 /// \e 443 /// \brief Constructor 444 /// 445 /// Construct a directed graph reader, which reads from the given 446 /// input stream. 345 447 DigraphReader(std::istream& is, Digraph& digraph) 346 448 : _is(&is), local_is(false), _digraph(digraph), 347 449 _use_nodes(false), _use_arcs(false) {} 348 450 349 /// \e 451 /// \brief Constructor 452 /// 453 /// Construct a directed graph reader, which reads from the given 454 /// file. 350 455 DigraphReader(const std::string& fn, Digraph& digraph) 351 456 : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph), 352 457 _use_nodes(false), _use_arcs(false) {} 353 354 355 /// \e 458 459 /// \brief Constructor 460 /// 461 /// Construct a directed graph reader, which reads from the given 462 /// file. 356 463 DigraphReader(const char* fn, Digraph& digraph) 357 464 : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph), 358 465 _use_nodes(false), _use_arcs(false) {} 359 466 360 /// \e 467 /// \brief Copy constructor 468 /// 469 /// The copy constructor transfers all data from the other reader, 470 /// therefore the copied reader will not be useable more. 361 471 DigraphReader(DigraphReader& other) 362 472 : _is(other._is), local_is(other.local_is), _digraph(other._digraph), 363 473 _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) { … … 377 487 _attributes_caption = other._attributes_caption; 378 488 } 379 489 380 /// \ e490 /// \brief Destructor 381 491 ~DigraphReader() { 382 492 for (typename NodeMaps::iterator it = _node_maps.begin(); 383 493 it != _node_maps.end(); ++it) { … … 406 516 407 517 public: 408 518 409 /// \e 519 /// \name Reading rules 520 /// @{ 521 522 /// \brief Node map reading rule 523 /// 524 /// Add a node map reading rule to the reader. 410 525 template <typename Map> 411 526 DigraphReader& nodeMap(const std::string& caption, Map& map) { 412 527 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); … … 416 531 return *this; 417 532 } 418 533 419 /// \e 534 /// \brief Node map reading rule 535 /// 536 /// Add a node map reading rule with specialized converter to the 537 /// reader. 420 538 template <typename Map, typename Converter> 421 539 DigraphReader& nodeMap(const std::string& caption, Map& map, 422 540 const Converter& converter = Converter()) { … … 427 545 return *this; 428 546 } 429 547 430 /// \e 548 /// \brief Arc map reading rule 549 /// 550 /// Add an arc map reading rule to the reader. 431 551 template <typename Map> 432 552 DigraphReader& arcMap(const std::string& caption, Map& map) { 433 553 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); … … 437 557 return *this; 438 558 } 439 559 440 /// \e 560 /// \brief Arc map reading rule 561 /// 562 /// Add an arc map reading rule with specialized converter to the 563 /// reader. 441 564 template <typename Map, typename Converter> 442 565 DigraphReader& arcMap(const std::string& caption, Map& map, 443 566 const Converter& converter = Converter()) { … … 448 571 return *this; 449 572 } 450 573 451 /// \e 574 /// \brief Attribute reading rule 575 /// 576 /// Add an attribute reading rule to the reader. 452 577 template <typename Value> 453 578 DigraphReader& attribute(const std::string& caption, Value& value) { 454 579 _reader_bits::ValueStorageBase* storage = … … 457 582 return *this; 458 583 } 459 584 460 /// \e 585 /// \brief Attribute reading rule 586 /// 587 /// Add an attribute reading rule with specialized converter to the 588 /// reader. 461 589 template <typename Value, typename Converter> 462 590 DigraphReader& attribute(const std::string& caption, Value& value, 463 591 const Converter& converter = Converter()) { … … 467 595 return *this; 468 596 } 469 597 470 /// \e 598 /// \brief Node reading rule 599 /// 600 /// Add a node reading rule with specialized converter to the 601 /// reader. 471 602 DigraphReader& node(const std::string& caption, Node& node) { 472 603 typedef _reader_bits::MapLookUpConverter<Node> Converter; 473 604 Converter converter(_node_index); … … 477 608 return *this; 478 609 } 479 610 480 /// \e 611 /// \brief Arc reading rule 612 /// 613 /// Add an arc reading rule with specialized converter to the 614 /// reader. 481 615 DigraphReader& arc(const std::string& caption, Arc& arc) { 482 616 typedef _reader_bits::MapLookUpConverter<Arc> Converter; 483 617 Converter converter(_arc_index); … … 487 621 return *this; 488 622 } 489 623 490 /// \e 624 /// @} 625 626 /// \name Select section by name 627 /// @{ 628 629 /// \brief Set \c \@nodes section to be read 630 /// 631 /// Set \c \@nodes section to be read 491 632 DigraphReader& nodes(const std::string& caption) { 492 633 _nodes_caption = caption; 493 634 return *this; 494 635 } 495 636 496 /// \e 637 /// \brief Set \c \@arcs section to be read 638 /// 639 /// Set \c \@arcs section to be read 497 640 DigraphReader& arcs(const std::string& caption) { 498 641 _arcs_caption = caption; 499 642 return *this; 500 643 } 501 644 502 /// \e 645 /// \brief Set \c \@attributes section to be read 646 /// 647 /// Set \c \@attributes section to be read 503 648 DigraphReader& attributes(const std::string& caption) { 504 649 _attributes_caption = caption; 505 650 return *this; 506 651 } 507 652 508 /// \e 653 /// @} 654 655 /// \name Using previously constructed node or arc set 656 /// @{ 657 658 /// \brief Use previously constructed node set 659 /// 660 /// Use previously constructed node set, and specify the node 661 /// label map. 509 662 template <typename Map> 510 663 DigraphReader& useNodes(const Map& map) { 511 664 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); … … 518 671 return *this; 519 672 } 520 673 521 /// \e 674 /// \brief Use previously constructed node set 675 /// 676 /// Use previously constructed node set, and specify the node 677 /// label map and a functor which converts the label map values to 678 /// std::string. 522 679 template <typename Map, typename Converter> 523 680 DigraphReader& useNodes(const Map& map, 524 681 const Converter& converter = Converter()) { … … 531 688 return *this; 532 689 } 533 690 534 /// \e 691 /// \brief Use previously constructed arc set 692 /// 693 /// Use previously constructed arc set, and specify the arc 694 /// label map. 535 695 template <typename Map> 536 696 DigraphReader& useArcs(const Map& map) { 537 697 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); … … 544 704 return *this; 545 705 } 546 706 547 /// \e 707 /// \brief Use previously constructed arc set 708 /// 709 /// Use previously constructed arc set, and specify the arc 710 /// label map and a functor which converts the label map values to 711 /// std::string. 548 712 template <typename Map, typename Converter> 549 713 DigraphReader& useArcs(const Map& map, 550 714 const Converter& converter = Converter()) { … … 556 720 } 557 721 return *this; 558 722 } 723 724 /// @} 559 725 560 726 private: 561 727 … … 827 993 } 828 994 829 995 public: 830 831 /// \e 996 997 /// \name Execution of the reader 998 /// @{ 999 1000 /// \brief Start the batch processing 1001 /// 1002 /// This function starts the batch processing 832 1003 void run() { 833 1004 834 1005 LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); … … 891 1062 } 892 1063 893 1064 } 1065 1066 /// @} 894 1067 895 1068 }; 896 1069