Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / internal / steinertree / EdgeWeightedGraphCopy.h
blobb849844e26d44bade15aa4d5615e8cd11459c317
1 /*
2 * $Revision: 2523 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Extends the GraphCopy concept to weighted graphs
12 * \author Matthias Woste
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
26 * for details.
28 * \par
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * \par
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #ifdef _MSC_VER
44 #pragma once
45 #endif
47 #ifndef OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_
48 #define OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_
50 #include <ogdf/basic/GraphCopy.h>
51 #include <ogdf/internal/steinertree/EdgeWeightedGraph.h>
53 namespace ogdf {
55 template<typename T>
56 class EdgeWeightedGraphCopy: public GraphCopy {
57 public:
58 EdgeWeightedGraphCopy() :
59 GraphCopy() {
61 EdgeWeightedGraphCopy(const EdgeWeightedGraph<T> &wC);
62 EdgeWeightedGraphCopy(const EdgeWeightedGraphCopy &wGC);
63 EdgeWeightedGraphCopy &operator=(const EdgeWeightedGraphCopy &wGC);
64 virtual ~EdgeWeightedGraphCopy() {
67 void createEmpty(const EdgeWeightedGraph<T> &wG);
68 edge newEdge(node u, node v, T weight);
69 T weight(edge e) const {
70 return m_edgeWeight[e];
72 void setWeight(edge e, T v) {
73 m_edgeWeight[e] = v;
75 EdgeArray<T> edgeWeights() const {
76 return m_edgeWeight;
79 protected:
80 EdgeArray<T> m_edgeWeight;
82 private:
83 void initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray<node> &vCopy, EdgeArray<edge> &eCopy);
88 // Implementation
90 namespace ogdf {
92 template<typename T>
93 void EdgeWeightedGraphCopy<T>::initWGC(const EdgeWeightedGraphCopy &wGC, NodeArray<node> &vCopy, EdgeArray<edge> &eCopy) {
94 m_pGraph = wGC.m_pGraph;
96 m_vOrig.init(*this, 0);
97 m_eOrig.init(*this, 0);
98 m_vCopy.init(*m_pGraph, 0);
99 m_eCopy.init(*m_pGraph);
100 m_eIterator.init(*this, 0);
102 node v, w;
103 forall_nodes(v, wGC)
104 m_vOrig[vCopy[v]] = wGC.original(v);
106 edge e;
107 forall_edges(e, wGC)
108 m_eOrig[eCopy[e]] = wGC.original(e);
110 forall_nodes(v, *this)
111 if ((w = m_vOrig[v]) != 0)
112 m_vCopy[w] = v;
114 forall_edges(e, *m_pGraph)
116 ListConstIterator<edge> it;
117 for (it = wGC.m_eCopy[e].begin(); it.valid(); ++it)
118 m_eIterator[eCopy[*it]] = m_eCopy[e].pushBack(eCopy[*it]);
121 m_edgeWeight = EdgeArray<T>((*this));
123 forall_edges(e, wGC)
125 m_edgeWeight[eCopy[e]] = wGC.weight(e);
129 template<typename T>
130 EdgeWeightedGraphCopy<T> &EdgeWeightedGraphCopy<T>::operator=(const EdgeWeightedGraphCopy<T> &wGC) {
132 GraphCopy::operator =(wGC);
134 m_edgeWeight = EdgeArray<T>((*this));
136 edge e, f;
137 forall_edges(e, wGC)
139 f = wGC.original(e);
140 m_edgeWeight[copy(f)] = wGC.weight(e);
145 template<typename T>
146 EdgeWeightedGraphCopy<T>::EdgeWeightedGraphCopy(const EdgeWeightedGraphCopy<T> &wGC) :
147 GraphCopy(wGC) {
148 m_edgeWeight = EdgeArray<T>((*this));
150 edge e, f;
151 forall_edges(e, wGC)
153 f = wGC.original(e);
154 m_edgeWeight[copy(f)] = wGC.weight(e);
158 template<typename T>
159 EdgeWeightedGraphCopy<T>::EdgeWeightedGraphCopy(const EdgeWeightedGraph<T> &wG) :
160 GraphCopy(wG) {
161 m_edgeWeight = EdgeArray<T>((*this));
163 edge e;
164 forall_edges(e, (*this))
166 m_edgeWeight[e] = wG.weight(original(e));
170 template<typename T>
171 void EdgeWeightedGraphCopy<T>::createEmpty(const EdgeWeightedGraph<T> &wG) {
172 GraphCopy::createEmpty(wG);
173 m_pGraph = &wG;
174 m_edgeWeight = EdgeArray<T>(*this);
177 template<typename T>
178 edge EdgeWeightedGraphCopy<T>::newEdge(node u, node v, T weight) {
179 edge e = GraphCopy::newEdge(u, v);
180 m_edgeWeight[e] = weight;
181 return e;
186 #endif /* OGDF_EDGE_WEIGHTED_GRAPH_COPY_H_ */