1 /* 2 * EdgeSet.cpp 3 * 4 * Created on: 12 Nov 2013 5 * Author: s0965328 6 */ 7 8 #include "EdgeSet.h" 9 #include "Edge.h" 10 #include <sstream> 11 12 using namespace std; 13 namespace AutoDiff { 14 EdgeSet()15EdgeSet::EdgeSet() { 16 // TODO Auto-generated constructor stub 17 18 } 19 ~EdgeSet()20EdgeSet::~EdgeSet() { 21 edges.clear(); 22 } 23 containsEdge(Edge & e)24bool EdgeSet::containsEdge(Edge& e) 25 { 26 list<Edge>::iterator it = edges.begin(); 27 for(;it!= edges.end();it++){ 28 Edge eit = *it; 29 if(eit.isEqual(e)) 30 { 31 return true; 32 } 33 } 34 return false; 35 } 36 insertEdge(Edge & e)37void EdgeSet::insertEdge(Edge& e) { 38 if(!containsEdge(e)){ 39 edges.push_front(e); 40 } 41 } 42 clear()43void EdgeSet::clear() { 44 edges.clear(); 45 } 46 size()47unsigned int EdgeSet::size(){ 48 return edges.size(); 49 } 50 numSelfEdges()51unsigned int EdgeSet::numSelfEdges(){ 52 unsigned int diag = 0; 53 list<Edge>::iterator it = edges.begin(); 54 for(;it!=edges.end();it++) 55 { 56 Edge eit = *it; 57 if(eit.a == eit.b) 58 { 59 diag++; 60 } 61 } 62 return diag; 63 } 64 toString()65string EdgeSet::toString() 66 { 67 ostringstream oss; 68 list<Edge>::iterator it = edges.begin(); 69 for(;it!=edges.end();it++) 70 { 71 oss<<(*it).toString()<<endl; 72 } 73 return oss.str(); 74 } 75 76 } /* namespace AutoDiff */ 77