Edge.C

Go to the documentation of this file.
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 // Edge class implementation
00032 
00033 #include "Graph.h"
00034 #include "Edge.h"
00035 #include "Node.h"
00036 #include <assert.h>
00037 
00038 // Edges are quite simple. The only things we need to implement are:
00039 // * Factory method
00040 // * Constructors
00041 
00042 using namespace Dyninst;
00043 
00044 Edge::Ptr Edge::createEdge(const NodeSharedPtr source,
00045                            const NodeSharedPtr target) {
00046     // We take shared_ptrs as inputs and pull out a weak_ptr
00047     // to use internally.
00048 
00049     NodePtr s(source);
00050     NodePtr t(target);
00051 
00052     return Edge::Ptr(new Edge(s, t));
00053 }
00054 
00055 // Default constructor; DON'T USE THIS
00056 
00057 Edge::Edge() {
00058     // Impossible to use
00059     assert(0);
00060 }
00061 
00062 // Constructor
00063 Edge::Edge(const NodePtr source, const NodePtr target) :
00064     source_(source), target_(target) {}
00065 
00066 ///////////////////////////////////////////////////////////////
00067 // Edge iterator "implementation". The iterator just wraps an
00068 // internal implementation, so this code is pretty much 
00069 // boilerplate...
00070 ///////////////////////////////////////////////////////////////
00071 
00072 // Prefix...
00073 EdgeIterator &EdgeIterator::operator++() {
00074     if (!iter_) return *this;
00075     
00076     iter_->inc();
00077     return *this;
00078 }
00079 
00080 // Postfix...
00081 EdgeIterator EdgeIterator::operator++(int) {
00082     EdgeIterator ret = *this;
00083     ++(*this);
00084     return ret;    
00085 }
00086 
00087 
00088 Edge::Ptr EdgeIterator::operator*() const {
00089     if (!iter_) return Edge::Ptr();
00090 
00091     return iter_->get();
00092 }
00093 
00094 bool EdgeIterator::operator!=(const EdgeIterator &rhs) const {
00095     if (!iter_) {
00096         return (rhs.iter_ != NULL);
00097     }
00098     return !iter_->equals(rhs.iter_);
00099 }
00100 
00101 bool EdgeIterator::operator==(const EdgeIterator &rhs) const {
00102     if (!iter_) {
00103         return (rhs.iter_ == NULL);
00104     }
00105     return iter_->equals(rhs.iter_);
00106 }
00107 
00108 EdgeIterator &EdgeIterator::operator=(const EdgeIterator &rhs) {
00109     if (rhs.iter_ == NULL) {
00110         if (iter_) delete iter_; // No leaking!
00111         iter_ = rhs.iter_; 
00112         return *this;
00113     }
00114     else {
00115         // We don't want just the pointer, as that would really
00116         // make the two iterators work the same. That's bad. 
00117         iter_ = rhs.iter_->copy();
00118         return *this;
00119     }
00120 }
00121 
00122 EdgeIterator::~EdgeIterator() {
00123     if (iter_) delete iter_;
00124 }
00125 
00126 EdgeIterator::EdgeIterator(const EdgeIterator &rhs) {
00127     if (rhs.iter_ == NULL) {
00128         iter_ = NULL;
00129     }
00130     else
00131         iter_ = rhs.iter_->copy();
00132 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1