Moving definitions from class body which only fit to the next line outside of the class

for/release
Denes Matetelki 12 years ago
parent eb638d6f6a
commit 183081c17f

@ -30,18 +30,15 @@ public:
struct Edge {
Edge() : m_source(0), m_destination(0), m_weight(0) {}
Edge(pointer source, pointer destination, float weight)
: m_source(source), m_destination(destination), m_weight(weight) {}
Edge(const Edge& o)
: m_source(o.m_source), m_destination(o.m_destination), m_weight(o.m_weight) {}
Edge(pointer source, pointer destination, float weight);
Edge(const Edge& o);
Edge& operator=(Edge o) { swap(o); return *this; }
void swap(Edge& o);
pointer getSource() const { return m_source; }
pointer getDestination() const { return m_destination; }
float getWeight() const { return m_weight; }
void swap(Edge& o);
pointer m_source;
pointer m_destination;
float m_weight;
@ -92,10 +89,10 @@ public:
~vertex_iterator() {}
vertex_iterator(const_reference_self_type o) : m_it(o.m_it) {}
reference_self_type operator=(self_type o) { swap(o); return *this; }
void swap(reference_self_type o) { std::swap(m_it, o.m_it); }
pointer operator*() { return (*m_it).m_data; }
pointer operator->() { return (*m_it).m_data; }
self_type &operator++() { ++m_it; return *this; }
self_type operator++(int) { self_type tmp(*this); ++(*this); return tmp; }
self_type operator+(difference_type n) { self_type tmp(*this); tmp.pos_ += n; return tmp; }
@ -103,8 +100,6 @@ public:
bool operator==(const_reference_self_type o) const { return m_it == o.m_it; }
bool operator!=(const_reference_self_type o) const { return !(*this == o); }
void swap(reference_self_type o) { std::swap(m_it, o.m_it); }
private:
vertex_iterator(typename std::vector<Vertex>::iterator it) : m_it(it) {}
@ -129,15 +124,12 @@ public:
edge_iterator() : m_vertices(), m_vertex_it(), m_edge_it(), m_edge(0) {}
~edge_iterator() { if (m_edge) delete m_edge; }
edge_iterator(const_reference_self_type o)
: m_vertices(o.m_vertices), m_vertex_it(o.m_vertex_it), m_edge_it(o.m_edge_it), m_edge(0) {}
edge_iterator(const_reference_self_type o);
reference_self_type operator=(self_type o) { swap(o); return *this; }
void swap(reference_self_type other);
edge_reference operator*() { resetEdge(); return *m_edge; }
edge_pointer operator->() { resetEdge(); return m_edge; }
self_type &operator++() { advance(1); return *this; }
self_type operator++(int) { self_type tmp(*this); advance(1); return tmp; }
self_type operator+(difference_type n) { self_type tmp(*this); tmp.pos_ += n; return tmp; }
@ -145,8 +137,6 @@ public:
bool operator==(const_reference_self_type o) const;
bool operator!=(const_reference_self_type o) const { return !(*this == o); }
void swap(reference_self_type other);
private:
edge_iterator(std::vector<Vertex> vertices, bool begin = true);
@ -167,15 +157,12 @@ private:
struct EdgeTo {
EdgeTo(const_reference destination, float weight = 0)
: m_destination(const_cast<pointer>(&destination)), m_weight(weight) {}
EdgeTo(const_reference destination, float weight = 0);
EdgeTo(const EdgeTo& o) : m_destination(o.m_destination), m_weight(o.m_weight) {}
EdgeTo& operator=(EdgeTo o) { swap(o); return *this; }
bool operator==(const EdgeTo& other) const
{ return m_destination == other.m_destination && m_weight == other.m_weight; }
void swap(EdgeTo& o);
void swap(EdgeTo& o)
{ std::swap(m_destination, o.m_destination); std::swap(m_vertices, o.m_weight); }
bool operator==(const EdgeTo& other) const;
pointer m_destination;
float m_weight;
@ -186,16 +173,15 @@ private:
Vertex(const_reference data) : m_data(const_cast<pointer>(&data)) , m_edges() {}
Vertex(const Vertex& o) : m_data(o.m_data), m_edges(o.m_edges) {}
Vertex& operator=(Vertex o) { swap(o); return *this; }
void swap(Vertex& o) { std::swap(m_data, o.m_data); std::swap (m_edges, o.m_edges); }
bool operator==(const Vertex& other) const;
void addEdge(const_reference destination, float weight = 0)
{ m_edges.push_back(EdgeTo(destination, weight)); }
void addEdge(const_reference destination, float weight = 0);
void removeEdge(const_reference destination, float weight = 0);
void removeAllEdgesTo(const_reference destination);
std::vector<Edge> edges() const;
void swap(Vertex& o)
{ std::swap(m_data, o.m_data); std::swap (m_edges, o.m_edges); }
pointer m_data;
std::list<EdgeTo> m_edges;
};
@ -212,6 +198,20 @@ private:
// Edge
template <typename T>
Graph<T>::Edge::Edge(pointer source, pointer destination, float weight)
: m_source(source)
, m_destination(destination)
, m_weight(weight)
{}
template <typename T>
Graph<T>::Edge::Edge(const Edge& o)
: m_source(o.m_source)
, m_destination(o.m_destination)
, m_weight(o.m_weight)
{}
template <typename T>
void Graph<T>::Edge::swap(Edge& o)
{
@ -223,6 +223,14 @@ void Graph<T>::Edge::swap(Edge& o)
// edge iterator
template <typename T>
Graph<T>::edge_iterator::edge_iterator(const_reference_self_type o)
: m_vertices(o.m_vertices)
, m_vertex_it(o.m_vertex_it)
, m_edge_it(o.m_edge_it)
, m_edge(0)
{}
template <typename T>
bool Graph<T>::edge_iterator::operator==(const_reference_self_type o) const
{
@ -285,8 +293,8 @@ void Graph<T>::edge_iterator::advance(int n)
}
if (edgesAhead > 0) n -= edgesAhead;
++m_vertex_it;
if (m_vertex_it != m_vertices.end()) {
m_edge_it = (*m_vertex_it).m_edges.begin();
if (m_edge_it != (*m_vertex_it).m_edges.end())
@ -295,6 +303,28 @@ void Graph<T>::edge_iterator::advance(int n)
}
}
// EdgeTo
template <typename T>
Graph<T>::EdgeTo::EdgeTo(const_reference destination, float weight)
: m_destination(const_cast<pointer>(&destination))
, m_weight(weight)
{}
template <typename T>
void Graph<T>::EdgeTo::swap(EdgeTo& o)
{
std::swap(m_destination, o.m_destination);
std::swap(m_vertices, o.m_weight);
}
template <typename T>
bool Graph<T>::EdgeTo::operator==(const EdgeTo& other) const
{
return m_destination == other.m_destination &&
m_weight == other.m_weight;
}
// Vertex
@ -306,6 +336,12 @@ bool Graph<T>::Vertex::operator==(const Vertex& other) const
m_edges == other.m_edges;
}
template <typename T>
void Graph<T>::Vertex::addEdge(const_reference destination, float weight)
{
m_edges.push_back(EdgeTo(destination, weight));
}
template <typename T>
void Graph<T>::Vertex::removeEdge(const_reference destination, float weight)
{

Loading…
Cancel
Save