src/lemon/graph_wrapper.h
changeset 998 89969b303727
parent 997 665ffade9aca
child 1004 b94037830dc8
equal deleted inserted replaced
9:4fafa6ab954a 10:02dca0df6df6
  1797 
  1797 
  1798     //    KEEP_MAPS(Parent, ResGraphWrapper);
  1798     //    KEEP_MAPS(Parent, ResGraphWrapper);
  1799   };
  1799   };
  1800 
  1800 
  1801 
  1801 
       
  1802 
       
  1803   template <typename _Graph, typename FirstOutEdgesMap>
       
  1804   class ErasingFirstGraphWrapperBase : public GraphWrapperBase<_Graph> {
       
  1805   public:
       
  1806     typedef _Graph Graph;
       
  1807     typedef GraphWrapperBase<_Graph> Parent;
       
  1808   protected:
       
  1809     FirstOutEdgesMap* first_out_edges;
       
  1810     ErasingFirstGraphWrapperBase() : Parent(), 
       
  1811 				     first_out_edges(0) { }
       
  1812 
       
  1813     void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
       
  1814       first_out_edges=&_first_out_edges;
       
  1815     }
       
  1816 
       
  1817   public:
       
  1818 
       
  1819     typedef typename Parent::Node Node;
       
  1820     typedef typename Parent::Edge Edge;
       
  1821 
       
  1822 //     using Parent::first;
       
  1823 //     void first(Node& i) const { 
       
  1824 //       Parent::first(i); 
       
  1825 //       while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
       
  1826 //     }
       
  1827 //     void first(Edge& i) const { 
       
  1828 //       Parent::first(i); 
       
  1829 //       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
       
  1830 //     }
       
  1831 //     void firstIn(Edge& i, const Node& n) const { 
       
  1832 //       Parent::firstIn(i, n); 
       
  1833 //       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
       
  1834 //     }
       
  1835     void firstOut(Edge& i, const Node& n) const { 
       
  1836       i=(*first_out_edges)[n];
       
  1837     }
       
  1838 
       
  1839     void erase(const Edge& e) const {
       
  1840       Node n=source(e);
       
  1841       Edge f=e;
       
  1842       Parent::nextOut(f);
       
  1843       first_out_edges->set(n, f);
       
  1844     }    
       
  1845 //     void next(Node& i) const { 
       
  1846 //       Parent::next(i); 
       
  1847 //       while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
       
  1848 //     }
       
  1849 //     void next(Edge& i) const { 
       
  1850 //       Parent::next(i); 
       
  1851 //       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
       
  1852 //     }
       
  1853 //     void nextIn(Edge& i) const { 
       
  1854 //       Parent::nextIn(i); 
       
  1855 //       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
       
  1856 //     }
       
  1857 //     void nextOut(Edge& i) const { 
       
  1858 //       Parent::nextOut(i); 
       
  1859 //       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
       
  1860 //     }
       
  1861   };
       
  1862 
       
  1863 
  1802   /// For blocking flows.
  1864   /// For blocking flows.
  1803 
  1865 
  1804   ///\warning Graph wrappers are in even more experimental state than the other
  1866   ///\warning Graph wrappers are in even more experimental state than the other
  1805   ///parts of the lib. Use them at you own risk.
  1867   ///parts of the lib. Use them at you own risk.
  1806   ///
  1868   ///
  1811   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  1873   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  1812   /// \endcode
  1874   /// \endcode
  1813   /// is called. 
  1875   /// is called. 
  1814   ///
  1876   ///
  1815   /// \author Marton Makai
  1877   /// \author Marton Makai
  1816   template<typename Graph, typename FirstOutEdgesMap>
  1878   template <typename _Graph, typename FirstOutEdgesMap>
  1817   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
  1879   class ErasingFirstGraphWrapper : 
  1818   public:
  1880     public IterableGraphExtender<
  1819     typedef GraphWrapper<Graph> Parent; 
  1881     ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > {
  1820   protected:
  1882   public:
  1821     FirstOutEdgesMap* first_out_edges;
  1883     typedef _Graph Graph;
  1822   public:
  1884     typedef IterableGraphExtender<
       
  1885       ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > Parent;
  1823     ErasingFirstGraphWrapper(Graph& _graph, 
  1886     ErasingFirstGraphWrapper(Graph& _graph, 
  1824 			     FirstOutEdgesMap& _first_out_edges) : 
  1887 			     FirstOutEdgesMap& _first_out_edges) { 
  1825       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
  1888       setGraph(_graph);
  1826 
  1889       setFirstOutEdgesMap(_first_out_edges);
  1827     typedef typename GraphWrapper<Graph>::Node Node;
  1890     } 
  1828     typedef typename GraphWrapper<Graph>::Edge Edge;
       
  1829     class OutEdgeIt : public Edge { 
       
  1830       friend class GraphWrapper<Graph>;
       
  1831       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
       
  1832       const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
       
  1833     public:
       
  1834       OutEdgeIt() { }
       
  1835       OutEdgeIt(Invalid i) : Edge(i) { }
       
  1836       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
       
  1837 		const Node& n) : 
       
  1838 	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
       
  1839       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
       
  1840 		const Edge& e) : 
       
  1841 	Edge(e), gw(&_gw) { }
       
  1842       OutEdgeIt& operator++() { 
       
  1843 	*(static_cast<Edge*>(this))=
       
  1844 	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
       
  1845 	return *this; 
       
  1846       }
       
  1847     };
       
  1848 
       
  1849 //     using GraphWrapper<Graph>::first;
  1891 //     using GraphWrapper<Graph>::first;
  1850 //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  1892 //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  1851 //       i=OutEdgeIt(*this, p); return i;
  1893 //       i=OutEdgeIt(*this, p); return i;
  1852 //     }
  1894 //     }
  1853     void erase(const Edge& e) const {
       
  1854       Node n=source(e);
       
  1855       typename Graph::OutEdgeIt f(*Parent::graph, n);
       
  1856       ++f;
       
  1857       first_out_edges->set(n, f);
       
  1858     }
       
  1859 
       
  1860     //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
       
  1861   };
  1895   };
       
  1896 //   template<typename Graph, typename FirstOutEdgesMap>
       
  1897 //   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
       
  1898 //   public:
       
  1899 //     typedef GraphWrapper<Graph> Parent; 
       
  1900 //   protected:
       
  1901 //     FirstOutEdgesMap* first_out_edges;
       
  1902 //   public:
       
  1903 //     ErasingFirstGraphWrapper(Graph& _graph, 
       
  1904 // 			     FirstOutEdgesMap& _first_out_edges) : 
       
  1905 //       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
       
  1906 
       
  1907 //     typedef typename GraphWrapper<Graph>::Node Node;
       
  1908 //     typedef typename GraphWrapper<Graph>::Edge Edge;
       
  1909 //     class OutEdgeIt : public Edge { 
       
  1910 //       friend class GraphWrapper<Graph>;
       
  1911 //       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
       
  1912 //       const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
       
  1913 //     public:
       
  1914 //       OutEdgeIt() { }
       
  1915 //       OutEdgeIt(Invalid i) : Edge(i) { }
       
  1916 //       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
       
  1917 // 		const Node& n) : 
       
  1918 // 	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
       
  1919 //       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
       
  1920 // 		const Edge& e) : 
       
  1921 // 	Edge(e), gw(&_gw) { }
       
  1922 //       OutEdgeIt& operator++() { 
       
  1923 // 	*(static_cast<Edge*>(this))=
       
  1924 // 	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
       
  1925 // 	return *this; 
       
  1926 //       }
       
  1927 //     };
       
  1928 
       
  1929 // //     using GraphWrapper<Graph>::first;
       
  1930 // //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
       
  1931 // //       i=OutEdgeIt(*this, p); return i;
       
  1932 // //     }
       
  1933 //     void erase(const Edge& e) const {
       
  1934 //       Node n=source(e);
       
  1935 //       typename Graph::OutEdgeIt f(*Parent::graph, n);
       
  1936 //       ++f;
       
  1937 //       first_out_edges->set(n, f);
       
  1938 //     }
       
  1939 
       
  1940 //     //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
       
  1941 //   };
  1862 
  1942 
  1863   ///@}
  1943   ///@}
  1864 
  1944 
  1865 } //namespace lemon
  1945 } //namespace lemon
  1866 
  1946