00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 00031 #if !defined(EDGE_H) 00032 #define EDGE_H 00033 00034 #include "boost/shared_ptr.hpp" 00035 #include "boost/weak_ptr.hpp" 00036 #include <set> 00037 #include "Annotatable.h" 00038 00039 namespace Dyninst { 00040 class Graph; 00041 class Node; 00042 00043 class COMMON_EXPORT Edge : public AnnotatableSparse { 00044 friend class Node; 00045 friend class Graph; 00046 friend class Creator; 00047 public: 00048 typedef boost::shared_ptr<Edge> Ptr; 00049 00050 private: 00051 typedef boost::shared_ptr<Node> NodeSharedPtr; 00052 typedef boost::weak_ptr<Node> NodePtr; 00053 00054 public: 00055 00056 static Ptr createEdge(const NodeSharedPtr source, const NodeSharedPtr target); 00057 00058 NodeSharedPtr source() const { return source_.lock(); } 00059 NodeSharedPtr target() const { return target_.lock(); } 00060 00061 void setSource(NodeSharedPtr source) { source_ = NodePtr(source); } 00062 void setTarget(NodeSharedPtr target) { target_ = NodePtr(target); } 00063 00064 virtual ~Edge() {}; 00065 00066 protected: 00067 Edge(const NodePtr source, const NodePtr target); 00068 Edge(); 00069 00070 00071 NodePtr source_; 00072 NodePtr target_; 00073 }; 00074 00075 class EdgeIteratorImpl; 00076 00077 class COMMON_EXPORT EdgeIterator { 00078 friend class Node; 00079 friend class Graph; 00080 friend class Edge; 00081 00082 public: 00083 00084 EdgeIterator &operator++(); 00085 EdgeIterator operator++(int); 00086 EdgeIterator &operator--(); 00087 EdgeIterator operator--(int); 00088 00089 bool operator==(const EdgeIterator &rhs) const; 00090 bool operator!=(const EdgeIterator &rhs) const; 00091 00092 EdgeIterator &operator=(const EdgeIterator &rhs); 00093 00094 Edge::Ptr operator*() const; 00095 00096 // Make sure this is explicitly _not_ allowed (no vectors of iterators) 00097 EdgeIterator() : iter_(NULL) {}; 00098 00099 EdgeIterator(const EdgeIterator &rhs); 00100 00101 virtual ~EdgeIterator(); 00102 00103 EdgeIterator(EdgeIteratorImpl *iter) : iter_(iter) {}; 00104 00105 protected: 00106 00107 // Main constructor 00108 // The iter parameter becomes owned by the iterator and will be destroyed 00109 // when the iterator is destroyed. 00110 00111 00112 // We hide the internal iteration behavior behind a pointer. 00113 // This allows us to override (yay for virtual functions). 00114 EdgeIteratorImpl *iter_; 00115 }; 00116 00117 // This is a pure virtual interface class 00118 class EdgeIteratorImpl { 00119 friend class EdgeIterator; 00120 00121 public: 00122 virtual void inc() = 0; 00123 virtual void dec() = 0; 00124 virtual Edge::Ptr get() = 0; 00125 virtual bool equals(EdgeIteratorImpl *) = 0; 00126 virtual EdgeIteratorImpl *copy() = 0; 00127 00128 virtual ~EdgeIteratorImpl() {}; 00129 }; 00130 00131 // Types of edge iteration: over a set of edges 00132 class EdgeIteratorSet : public EdgeIteratorImpl { 00133 friend class EdgeIterator; 00134 00135 public: 00136 virtual void inc() { ++internal_; } 00137 virtual void dec() { --internal_; } 00138 virtual Edge::Ptr get() { return *internal_; } 00139 virtual bool equals(EdgeIteratorImpl *rhs) { 00140 EdgeIteratorSet *tmp = dynamic_cast<EdgeIteratorSet *>(rhs); 00141 if (tmp == NULL) return false; 00142 return internal_ == tmp->internal_; 00143 } 00144 00145 virtual EdgeIteratorImpl *copy() { 00146 EdgeIteratorSet *tmp = new EdgeIteratorSet(internal_); 00147 return tmp; 00148 } 00149 00150 virtual ~EdgeIteratorSet() { 00151 // Nothing to do 00152 } 00153 00154 EdgeIteratorSet(const std::set<Edge::Ptr>::iterator iter) : internal_(iter) { 00155 }; 00156 00157 private: 00158 std::set<Edge::Ptr>::iterator internal_; 00159 }; 00160 00161 } 00162 #endif 00163
1.6.1