... | ... |
@@ -1650,530 +1650,527 @@ |
1650 | 1650 |
/// The type of the adapted digraph. |
1651 | 1651 |
typedef DGR Digraph; |
1652 | 1652 |
/// The type of the arc filter map. |
1653 | 1653 |
typedef AF ArcFilterMap; |
1654 | 1654 |
|
1655 | 1655 |
typedef typename Parent::Arc Arc; |
1656 | 1656 |
|
1657 | 1657 |
protected: |
1658 | 1658 |
ConstMap<typename DGR::Node, Const<bool, true> > const_true_map; |
1659 | 1659 |
|
1660 | 1660 |
FilterArcs() : const_true_map() {} |
1661 | 1661 |
|
1662 | 1662 |
public: |
1663 | 1663 |
|
1664 | 1664 |
/// \brief Constructor |
1665 | 1665 |
/// |
1666 | 1666 |
/// Creates a subdigraph for the given digraph with the given arc |
1667 | 1667 |
/// filter map. |
1668 | 1668 |
FilterArcs(DGR& digraph, ArcFilterMap& arc_filter) |
1669 | 1669 |
: Parent(), const_true_map() { |
1670 | 1670 |
Parent::initialize(digraph, const_true_map, arc_filter); |
1671 | 1671 |
} |
1672 | 1672 |
|
1673 | 1673 |
/// \brief Sets the status of the given arc |
1674 | 1674 |
/// |
1675 | 1675 |
/// This function sets the status of the given arc. |
1676 | 1676 |
/// It is done by simply setting the assigned value of \c a |
1677 | 1677 |
/// to \c v in the arc filter map. |
1678 | 1678 |
void status(const Arc& a, bool v) const { Parent::status(a, v); } |
1679 | 1679 |
|
1680 | 1680 |
/// \brief Returns the status of the given arc |
1681 | 1681 |
/// |
1682 | 1682 |
/// This function returns the status of the given arc. |
1683 | 1683 |
/// It is \c true if the given arc is enabled (i.e. not hidden). |
1684 | 1684 |
bool status(const Arc& a) const { return Parent::status(a); } |
1685 | 1685 |
|
1686 | 1686 |
/// \brief Disables the given arc |
1687 | 1687 |
/// |
1688 | 1688 |
/// This function disables the given arc in the subdigraph, |
1689 | 1689 |
/// so the iteration jumps over it. |
1690 | 1690 |
/// It is the same as \ref status() "status(a, false)". |
1691 | 1691 |
void disable(const Arc& a) const { Parent::status(a, false); } |
1692 | 1692 |
|
1693 | 1693 |
/// \brief Enables the given arc |
1694 | 1694 |
/// |
1695 | 1695 |
/// This function enables the given arc in the subdigraph. |
1696 | 1696 |
/// It is the same as \ref status() "status(a, true)". |
1697 | 1697 |
void enable(const Arc& a) const { Parent::status(a, true); } |
1698 | 1698 |
|
1699 | 1699 |
}; |
1700 | 1700 |
|
1701 | 1701 |
/// \brief Returns a read-only FilterArcs adaptor |
1702 | 1702 |
/// |
1703 | 1703 |
/// This function just returns a read-only \ref FilterArcs adaptor. |
1704 | 1704 |
/// \ingroup graph_adaptors |
1705 | 1705 |
/// \relates FilterArcs |
1706 | 1706 |
template<typename DGR, typename AF> |
1707 | 1707 |
FilterArcs<const DGR, AF> |
1708 | 1708 |
filterArcs(const DGR& digraph, AF& arc_filter) { |
1709 | 1709 |
return FilterArcs<const DGR, AF>(digraph, arc_filter); |
1710 | 1710 |
} |
1711 | 1711 |
|
1712 | 1712 |
template<typename DGR, typename AF> |
1713 | 1713 |
FilterArcs<const DGR, const AF> |
1714 | 1714 |
filterArcs(const DGR& digraph, const AF& arc_filter) { |
1715 | 1715 |
return FilterArcs<const DGR, const AF>(digraph, arc_filter); |
1716 | 1716 |
} |
1717 | 1717 |
|
1718 | 1718 |
/// \ingroup graph_adaptors |
1719 | 1719 |
/// |
1720 | 1720 |
/// \brief Adaptor class for hiding edges in a graph. |
1721 | 1721 |
/// |
1722 | 1722 |
/// FilterEdges adaptor can be used for hiding edges in a graph. |
1723 | 1723 |
/// A \c bool edge map must be specified, which defines the filter for |
1724 | 1724 |
/// the edges. Only the edges with \c true filter value are shown in the |
1725 | 1725 |
/// subgraph. This adaptor conforms to the \ref concepts::Graph |
1726 | 1726 |
/// "Graph" concept. |
1727 | 1727 |
/// |
1728 | 1728 |
/// The adapted graph can also be modified through this adaptor |
1729 | 1729 |
/// by adding or removing nodes or edges, unless the \c GR template |
1730 | 1730 |
/// parameter is set to be \c const. |
1731 | 1731 |
/// |
1732 | 1732 |
/// \tparam GR The type of the adapted graph. |
1733 | 1733 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
1734 | 1734 |
/// It can also be specified to be \c const. |
1735 | 1735 |
/// \tparam EF The type of the edge filter map. |
1736 | 1736 |
/// It must be a \c bool (or convertible) edge map of the |
1737 | 1737 |
/// adapted graph. The default type is |
1738 | 1738 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
1739 | 1739 |
/// |
1740 | 1740 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the |
1741 | 1741 |
/// adapted graph are convertible to each other. |
1742 | 1742 |
#ifdef DOXYGEN |
1743 | 1743 |
template<typename GR, |
1744 | 1744 |
typename EF> |
1745 | 1745 |
class FilterEdges { |
1746 | 1746 |
#else |
1747 | 1747 |
template<typename GR, |
1748 | 1748 |
typename EF = typename GR::template EdgeMap<bool> > |
1749 | 1749 |
class FilterEdges : |
1750 | 1750 |
public GraphAdaptorExtender< |
1751 | 1751 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, |
1752 | 1752 |
EF, false> > { |
1753 | 1753 |
#endif |
1754 | 1754 |
typedef GraphAdaptorExtender< |
1755 | 1755 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, |
1756 | 1756 |
EF, false> > Parent; |
1757 | 1757 |
|
1758 | 1758 |
public: |
1759 | 1759 |
|
1760 | 1760 |
/// The type of the adapted graph. |
1761 | 1761 |
typedef GR Graph; |
1762 | 1762 |
/// The type of the edge filter map. |
1763 | 1763 |
typedef EF EdgeFilterMap; |
1764 | 1764 |
|
1765 | 1765 |
typedef typename Parent::Edge Edge; |
1766 | 1766 |
|
1767 | 1767 |
protected: |
1768 | 1768 |
ConstMap<typename GR::Node, Const<bool, true> > const_true_map; |
1769 | 1769 |
|
1770 | 1770 |
FilterEdges() : const_true_map(true) { |
1771 | 1771 |
Parent::setNodeFilterMap(const_true_map); |
1772 | 1772 |
} |
1773 | 1773 |
|
1774 | 1774 |
public: |
1775 | 1775 |
|
1776 | 1776 |
/// \brief Constructor |
1777 | 1777 |
/// |
1778 | 1778 |
/// Creates a subgraph for the given graph with the given edge |
1779 | 1779 |
/// filter map. |
1780 | 1780 |
FilterEdges(GR& graph, EF& edge_filter) |
1781 | 1781 |
: Parent(), const_true_map() { |
1782 | 1782 |
Parent::initialize(graph, const_true_map, edge_filter); |
1783 | 1783 |
} |
1784 | 1784 |
|
1785 | 1785 |
/// \brief Sets the status of the given edge |
1786 | 1786 |
/// |
1787 | 1787 |
/// This function sets the status of the given edge. |
1788 | 1788 |
/// It is done by simply setting the assigned value of \c e |
1789 | 1789 |
/// to \c v in the edge filter map. |
1790 | 1790 |
void status(const Edge& e, bool v) const { Parent::status(e, v); } |
1791 | 1791 |
|
1792 | 1792 |
/// \brief Returns the status of the given edge |
1793 | 1793 |
/// |
1794 | 1794 |
/// This function returns the status of the given edge. |
1795 | 1795 |
/// It is \c true if the given edge is enabled (i.e. not hidden). |
1796 | 1796 |
bool status(const Edge& e) const { return Parent::status(e); } |
1797 | 1797 |
|
1798 | 1798 |
/// \brief Disables the given edge |
1799 | 1799 |
/// |
1800 | 1800 |
/// This function disables the given edge in the subgraph, |
1801 | 1801 |
/// so the iteration jumps over it. |
1802 | 1802 |
/// It is the same as \ref status() "status(e, false)". |
1803 | 1803 |
void disable(const Edge& e) const { Parent::status(e, false); } |
1804 | 1804 |
|
1805 | 1805 |
/// \brief Enables the given edge |
1806 | 1806 |
/// |
1807 | 1807 |
/// This function enables the given edge in the subgraph. |
1808 | 1808 |
/// It is the same as \ref status() "status(e, true)". |
1809 | 1809 |
void enable(const Edge& e) const { Parent::status(e, true); } |
1810 | 1810 |
|
1811 | 1811 |
}; |
1812 | 1812 |
|
1813 | 1813 |
/// \brief Returns a read-only FilterEdges adaptor |
1814 | 1814 |
/// |
1815 | 1815 |
/// This function just returns a read-only \ref FilterEdges adaptor. |
1816 | 1816 |
/// \ingroup graph_adaptors |
1817 | 1817 |
/// \relates FilterEdges |
1818 | 1818 |
template<typename GR, typename EF> |
1819 | 1819 |
FilterEdges<const GR, EF> |
1820 | 1820 |
filterEdges(const GR& graph, EF& edge_filter) { |
1821 | 1821 |
return FilterEdges<const GR, EF>(graph, edge_filter); |
1822 | 1822 |
} |
1823 | 1823 |
|
1824 | 1824 |
template<typename GR, typename EF> |
1825 | 1825 |
FilterEdges<const GR, const EF> |
1826 | 1826 |
filterEdges(const GR& graph, const EF& edge_filter) { |
1827 | 1827 |
return FilterEdges<const GR, const EF>(graph, edge_filter); |
1828 | 1828 |
} |
1829 | 1829 |
|
1830 | 1830 |
|
1831 | 1831 |
template <typename DGR> |
1832 | 1832 |
class UndirectorBase { |
1833 | 1833 |
public: |
1834 | 1834 |
typedef DGR Digraph; |
1835 | 1835 |
typedef UndirectorBase Adaptor; |
1836 | 1836 |
|
1837 | 1837 |
typedef True UndirectedTag; |
1838 | 1838 |
|
1839 | 1839 |
typedef typename Digraph::Arc Edge; |
1840 | 1840 |
typedef typename Digraph::Node Node; |
1841 | 1841 |
|
1842 |
class Arc |
|
1842 |
class Arc { |
|
1843 | 1843 |
friend class UndirectorBase; |
1844 | 1844 |
protected: |
1845 |
Edge _edge; |
|
1845 | 1846 |
bool _forward; |
1846 | 1847 |
|
1847 |
Arc(const Edge& edge, bool forward) : |
|
1848 |
Edge(edge), _forward(forward) {} |
|
1848 |
Arc(const Edge& edge, bool forward) |
|
1849 |
: _edge(edge), _forward(forward) {} |
|
1849 | 1850 |
|
1850 | 1851 |
public: |
1851 | 1852 |
Arc() {} |
1852 | 1853 |
|
1853 |
Arc(Invalid) : |
|
1854 |
Arc(Invalid) : _edge(INVALID), _forward(true) {} |
|
1855 |
|
|
1856 |
operator const Edge&() const { return _edge; } |
|
1854 | 1857 |
|
1855 | 1858 |
bool operator==(const Arc &other) const { |
1856 |
return _forward == other._forward && |
|
1857 |
static_cast<const Edge&>(*this) == static_cast<const Edge&>(other); |
|
1859 |
return _forward == other._forward && _edge == other._edge; |
|
1858 | 1860 |
} |
1859 | 1861 |
bool operator!=(const Arc &other) const { |
1860 |
return _forward != other._forward || |
|
1861 |
static_cast<const Edge&>(*this) != static_cast<const Edge&>(other); |
|
1862 |
return _forward != other._forward || _edge != other._edge; |
|
1862 | 1863 |
} |
1863 | 1864 |
bool operator<(const Arc &other) const { |
1864 | 1865 |
return _forward < other._forward || |
1865 |
(_forward == other._forward && |
|
1866 |
static_cast<const Edge&>(*this) < static_cast<const Edge&>(other)); |
|
1866 |
(_forward == other._forward && _edge < other._edge); |
|
1867 | 1867 |
} |
1868 | 1868 |
}; |
1869 | 1869 |
|
1870 | 1870 |
void first(Node& n) const { |
1871 | 1871 |
_digraph->first(n); |
1872 | 1872 |
} |
1873 | 1873 |
|
1874 | 1874 |
void next(Node& n) const { |
1875 | 1875 |
_digraph->next(n); |
1876 | 1876 |
} |
1877 | 1877 |
|
1878 | 1878 |
void first(Arc& a) const { |
1879 |
_digraph->first(a); |
|
1879 |
_digraph->first(a._edge); |
|
1880 | 1880 |
a._forward = true; |
1881 | 1881 |
} |
1882 | 1882 |
|
1883 | 1883 |
void next(Arc& a) const { |
1884 | 1884 |
if (a._forward) { |
1885 | 1885 |
a._forward = false; |
1886 | 1886 |
} else { |
1887 |
_digraph->next(a); |
|
1887 |
_digraph->next(a._edge); |
|
1888 | 1888 |
a._forward = true; |
1889 | 1889 |
} |
1890 | 1890 |
} |
1891 | 1891 |
|
1892 | 1892 |
void first(Edge& e) const { |
1893 | 1893 |
_digraph->first(e); |
1894 | 1894 |
} |
1895 | 1895 |
|
1896 | 1896 |
void next(Edge& e) const { |
1897 | 1897 |
_digraph->next(e); |
1898 | 1898 |
} |
1899 | 1899 |
|
1900 | 1900 |
void firstOut(Arc& a, const Node& n) const { |
1901 |
_digraph->firstIn(a, n); |
|
1902 |
if( static_cast<const Edge&>(a) != INVALID ) { |
|
1901 |
_digraph->firstIn(a._edge, n); |
|
1902 |
if (a._edge != INVALID ) { |
|
1903 | 1903 |
a._forward = false; |
1904 | 1904 |
} else { |
1905 |
_digraph->firstOut(a, n); |
|
1905 |
_digraph->firstOut(a._edge, n); |
|
1906 | 1906 |
a._forward = true; |
1907 | 1907 |
} |
1908 | 1908 |
} |
1909 | 1909 |
void nextOut(Arc &a) const { |
1910 | 1910 |
if (!a._forward) { |
1911 |
Node n = _digraph->target(a); |
|
1912 |
_digraph->nextIn(a); |
|
1913 |
if (static_cast<const Edge&>(a) == INVALID ) { |
|
1914 |
_digraph->firstOut(a, n); |
|
1911 |
Node n = _digraph->target(a._edge); |
|
1912 |
_digraph->nextIn(a._edge); |
|
1913 |
if (a._edge == INVALID) { |
|
1914 |
_digraph->firstOut(a._edge, n); |
|
1915 | 1915 |
a._forward = true; |
1916 | 1916 |
} |
1917 | 1917 |
} |
1918 | 1918 |
else { |
1919 |
_digraph->nextOut(a); |
|
1919 |
_digraph->nextOut(a._edge); |
|
1920 | 1920 |
} |
1921 | 1921 |
} |
1922 | 1922 |
|
1923 | 1923 |
void firstIn(Arc &a, const Node &n) const { |
1924 |
_digraph->firstOut(a, n); |
|
1925 |
if (static_cast<const Edge&>(a) != INVALID ) { |
|
1924 |
_digraph->firstOut(a._edge, n); |
|
1925 |
if (a._edge != INVALID ) { |
|
1926 | 1926 |
a._forward = false; |
1927 | 1927 |
} else { |
1928 |
_digraph->firstIn(a, n); |
|
1928 |
_digraph->firstIn(a._edge, n); |
|
1929 | 1929 |
a._forward = true; |
1930 | 1930 |
} |
1931 | 1931 |
} |
1932 | 1932 |
void nextIn(Arc &a) const { |
1933 | 1933 |
if (!a._forward) { |
1934 |
Node n = _digraph->source(a); |
|
1935 |
_digraph->nextOut(a); |
|
1936 |
if( static_cast<const Edge&>(a) == INVALID ) { |
|
1937 |
_digraph->firstIn(a, n); |
|
1934 |
Node n = _digraph->source(a._edge); |
|
1935 |
_digraph->nextOut(a._edge); |
|
1936 |
if (a._edge == INVALID ) { |
|
1937 |
_digraph->firstIn(a._edge, n); |
|
1938 | 1938 |
a._forward = true; |
1939 | 1939 |
} |
1940 | 1940 |
} |
1941 | 1941 |
else { |
1942 |
_digraph->nextIn(a); |
|
1942 |
_digraph->nextIn(a._edge); |
|
1943 | 1943 |
} |
1944 | 1944 |
} |
1945 | 1945 |
|
1946 | 1946 |
void firstInc(Edge &e, bool &d, const Node &n) const { |
1947 | 1947 |
d = true; |
1948 | 1948 |
_digraph->firstOut(e, n); |
1949 | 1949 |
if (e != INVALID) return; |
1950 | 1950 |
d = false; |
1951 | 1951 |
_digraph->firstIn(e, n); |
1952 | 1952 |
} |
1953 | 1953 |
|
1954 | 1954 |
void nextInc(Edge &e, bool &d) const { |
1955 | 1955 |
if (d) { |
1956 | 1956 |
Node s = _digraph->source(e); |
1957 | 1957 |
_digraph->nextOut(e); |
1958 | 1958 |
if (e != INVALID) return; |
1959 | 1959 |
d = false; |
1960 | 1960 |
_digraph->firstIn(e, s); |
1961 | 1961 |
} else { |
1962 | 1962 |
_digraph->nextIn(e); |
1963 | 1963 |
} |
1964 | 1964 |
} |
1965 | 1965 |
|
1966 | 1966 |
Node u(const Edge& e) const { |
1967 | 1967 |
return _digraph->source(e); |
1968 | 1968 |
} |
1969 | 1969 |
|
1970 | 1970 |
Node v(const Edge& e) const { |
1971 | 1971 |
return _digraph->target(e); |
1972 | 1972 |
} |
1973 | 1973 |
|
1974 | 1974 |
Node source(const Arc &a) const { |
1975 |
return a._forward ? _digraph->source(a) : _digraph->target(a); |
|
1975 |
return a._forward ? _digraph->source(a._edge) : _digraph->target(a._edge); |
|
1976 | 1976 |
} |
1977 | 1977 |
|
1978 | 1978 |
Node target(const Arc &a) const { |
1979 |
return a._forward ? _digraph->target(a) : _digraph->source(a); |
|
1979 |
return a._forward ? _digraph->target(a._edge) : _digraph->source(a._edge); |
|
1980 | 1980 |
} |
1981 | 1981 |
|
1982 | 1982 |
static Arc direct(const Edge &e, bool d) { |
1983 | 1983 |
return Arc(e, d); |
1984 | 1984 |
} |
1985 |
Arc direct(const Edge &e, const Node& n) const { |
|
1986 |
return Arc(e, _digraph->source(e) == n); |
|
1987 |
} |
|
1988 | 1985 |
|
1989 | 1986 |
static bool direction(const Arc &a) { return a._forward; } |
1990 | 1987 |
|
1991 | 1988 |
Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); } |
1992 | 1989 |
Arc arcFromId(int ix) const { |
1993 | 1990 |
return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1)); |
1994 | 1991 |
} |
1995 | 1992 |
Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); } |
1996 | 1993 |
|
1997 | 1994 |
int id(const Node &n) const { return _digraph->id(n); } |
1998 | 1995 |
int id(const Arc &a) const { |
1999 | 1996 |
return (_digraph->id(a) << 1) | (a._forward ? 1 : 0); |
2000 | 1997 |
} |
2001 | 1998 |
int id(const Edge &e) const { return _digraph->id(e); } |
2002 | 1999 |
|
2003 | 2000 |
int maxNodeId() const { return _digraph->maxNodeId(); } |
2004 | 2001 |
int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; } |
2005 | 2002 |
int maxEdgeId() const { return _digraph->maxArcId(); } |
2006 | 2003 |
|
2007 | 2004 |
Node addNode() { return _digraph->addNode(); } |
2008 | 2005 |
Edge addEdge(const Node& u, const Node& v) { |
2009 | 2006 |
return _digraph->addArc(u, v); |
2010 | 2007 |
} |
2011 | 2008 |
|
2012 | 2009 |
void erase(const Node& i) { _digraph->erase(i); } |
2013 | 2010 |
void erase(const Edge& i) { _digraph->erase(i); } |
2014 | 2011 |
|
2015 | 2012 |
void clear() { _digraph->clear(); } |
2016 | 2013 |
|
2017 | 2014 |
typedef NodeNumTagIndicator<Digraph> NodeNumTag; |
2018 | 2015 |
int nodeNum() const { return _digraph->nodeNum(); } |
2019 | 2016 |
|
2020 | 2017 |
typedef ArcNumTagIndicator<Digraph> ArcNumTag; |
2021 | 2018 |
int arcNum() const { return 2 * _digraph->arcNum(); } |
2022 | 2019 |
|
2023 | 2020 |
typedef ArcNumTag EdgeNumTag; |
2024 | 2021 |
int edgeNum() const { return _digraph->arcNum(); } |
2025 | 2022 |
|
2026 | 2023 |
typedef FindArcTagIndicator<Digraph> FindArcTag; |
2027 | 2024 |
Arc findArc(Node s, Node t, Arc p = INVALID) const { |
2028 | 2025 |
if (p == INVALID) { |
2029 | 2026 |
Edge arc = _digraph->findArc(s, t); |
2030 | 2027 |
if (arc != INVALID) return direct(arc, true); |
2031 | 2028 |
arc = _digraph->findArc(t, s); |
2032 | 2029 |
if (arc != INVALID) return direct(arc, false); |
2033 | 2030 |
} else if (direction(p)) { |
2034 | 2031 |
Edge arc = _digraph->findArc(s, t, p); |
2035 | 2032 |
if (arc != INVALID) return direct(arc, true); |
2036 | 2033 |
arc = _digraph->findArc(t, s); |
2037 | 2034 |
if (arc != INVALID) return direct(arc, false); |
2038 | 2035 |
} else { |
2039 | 2036 |
Edge arc = _digraph->findArc(t, s, p); |
2040 | 2037 |
if (arc != INVALID) return direct(arc, false); |
2041 | 2038 |
} |
2042 | 2039 |
return INVALID; |
2043 | 2040 |
} |
2044 | 2041 |
|
2045 | 2042 |
typedef FindArcTag FindEdgeTag; |
2046 | 2043 |
Edge findEdge(Node s, Node t, Edge p = INVALID) const { |
2047 | 2044 |
if (s != t) { |
2048 | 2045 |
if (p == INVALID) { |
2049 | 2046 |
Edge arc = _digraph->findArc(s, t); |
2050 | 2047 |
if (arc != INVALID) return arc; |
2051 | 2048 |
arc = _digraph->findArc(t, s); |
2052 | 2049 |
if (arc != INVALID) return arc; |
2053 | 2050 |
} else if (_digraph->source(p) == s) { |
2054 | 2051 |
Edge arc = _digraph->findArc(s, t, p); |
2055 | 2052 |
if (arc != INVALID) return arc; |
2056 | 2053 |
arc = _digraph->findArc(t, s); |
2057 | 2054 |
if (arc != INVALID) return arc; |
2058 | 2055 |
} else { |
2059 | 2056 |
Edge arc = _digraph->findArc(t, s, p); |
2060 | 2057 |
if (arc != INVALID) return arc; |
2061 | 2058 |
} |
2062 | 2059 |
} else { |
2063 | 2060 |
return _digraph->findArc(s, t, p); |
2064 | 2061 |
} |
2065 | 2062 |
return INVALID; |
2066 | 2063 |
} |
2067 | 2064 |
|
2068 | 2065 |
private: |
2069 | 2066 |
|
2070 | 2067 |
template <typename V> |
2071 | 2068 |
class ArcMapBase { |
2072 | 2069 |
private: |
2073 | 2070 |
|
2074 | 2071 |
typedef typename DGR::template ArcMap<V> MapImpl; |
2075 | 2072 |
|
2076 | 2073 |
public: |
2077 | 2074 |
|
2078 | 2075 |
typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag; |
2079 | 2076 |
|
2080 | 2077 |
typedef V Value; |
2081 | 2078 |
typedef Arc Key; |
2082 | 2079 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReturnValue; |
2083 | 2080 |
typedef typename MapTraits<MapImpl>::ReturnValue ReturnValue; |
2084 | 2081 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReference; |
2085 | 2082 |
typedef typename MapTraits<MapImpl>::ReturnValue Reference; |
2086 | 2083 |
|
2087 | 2084 |
ArcMapBase(const UndirectorBase<DGR>& adaptor) : |
2088 | 2085 |
_forward(*adaptor._digraph), _backward(*adaptor._digraph) {} |
2089 | 2086 |
|
2090 | 2087 |
ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value) |
2091 | 2088 |
: _forward(*adaptor._digraph, value), |
2092 | 2089 |
_backward(*adaptor._digraph, value) {} |
2093 | 2090 |
|
2094 | 2091 |
void set(const Arc& a, const V& value) { |
2095 | 2092 |
if (direction(a)) { |
2096 | 2093 |
_forward.set(a, value); |
2097 | 2094 |
} else { |
2098 | 2095 |
_backward.set(a, value); |
2099 | 2096 |
} |
2100 | 2097 |
} |
2101 | 2098 |
|
2102 | 2099 |
ConstReturnValue operator[](const Arc& a) const { |
2103 | 2100 |
if (direction(a)) { |
2104 | 2101 |
return _forward[a]; |
2105 | 2102 |
} else { |
2106 | 2103 |
return _backward[a]; |
2107 | 2104 |
} |
2108 | 2105 |
} |
2109 | 2106 |
|
2110 | 2107 |
ReturnValue operator[](const Arc& a) { |
2111 | 2108 |
if (direction(a)) { |
2112 | 2109 |
return _forward[a]; |
2113 | 2110 |
} else { |
2114 | 2111 |
return _backward[a]; |
2115 | 2112 |
} |
2116 | 2113 |
} |
2117 | 2114 |
|
2118 | 2115 |
protected: |
2119 | 2116 |
|
2120 | 2117 |
MapImpl _forward, _backward; |
2121 | 2118 |
|
2122 | 2119 |
}; |
2123 | 2120 |
|
2124 | 2121 |
public: |
2125 | 2122 |
|
2126 | 2123 |
template <typename V> |
2127 | 2124 |
class NodeMap : public DGR::template NodeMap<V> { |
2128 | 2125 |
typedef typename DGR::template NodeMap<V> Parent; |
2129 | 2126 |
|
2130 | 2127 |
public: |
2131 | 2128 |
typedef V Value; |
2132 | 2129 |
|
2133 | 2130 |
explicit NodeMap(const UndirectorBase<DGR>& adaptor) |
2134 | 2131 |
: Parent(*adaptor._digraph) {} |
2135 | 2132 |
|
2136 | 2133 |
NodeMap(const UndirectorBase<DGR>& adaptor, const V& value) |
2137 | 2134 |
: Parent(*adaptor._digraph, value) { } |
2138 | 2135 |
|
2139 | 2136 |
private: |
2140 | 2137 |
NodeMap& operator=(const NodeMap& cmap) { |
2141 | 2138 |
return operator=<NodeMap>(cmap); |
2142 | 2139 |
} |
2143 | 2140 |
|
2144 | 2141 |
template <typename CMap> |
2145 | 2142 |
NodeMap& operator=(const CMap& cmap) { |
2146 | 2143 |
Parent::operator=(cmap); |
2147 | 2144 |
return *this; |
2148 | 2145 |
} |
2149 | 2146 |
|
2150 | 2147 |
}; |
2151 | 2148 |
|
2152 | 2149 |
template <typename V> |
2153 | 2150 |
class ArcMap |
2154 | 2151 |
: public SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > { |
2155 | 2152 |
typedef SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > Parent; |
2156 | 2153 |
|
2157 | 2154 |
public: |
2158 | 2155 |
typedef V Value; |
2159 | 2156 |
|
2160 | 2157 |
explicit ArcMap(const UndirectorBase<DGR>& adaptor) |
2161 | 2158 |
: Parent(adaptor) {} |
2162 | 2159 |
|
2163 | 2160 |
ArcMap(const UndirectorBase<DGR>& adaptor, const V& value) |
2164 | 2161 |
: Parent(adaptor, value) {} |
2165 | 2162 |
|
2166 | 2163 |
private: |
2167 | 2164 |
ArcMap& operator=(const ArcMap& cmap) { |
2168 | 2165 |
return operator=<ArcMap>(cmap); |
2169 | 2166 |
} |
2170 | 2167 |
|
2171 | 2168 |
template <typename CMap> |
2172 | 2169 |
ArcMap& operator=(const CMap& cmap) { |
2173 | 2170 |
Parent::operator=(cmap); |
2174 | 2171 |
return *this; |
2175 | 2172 |
} |
2176 | 2173 |
}; |
2177 | 2174 |
|
2178 | 2175 |
template <typename V> |
2179 | 2176 |
class EdgeMap : public Digraph::template ArcMap<V> { |
0 comments (0 inline)