00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Math Library 00005 * Module : Vertice 00006 * Package : Zeus.ZeusMath.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef VerticeH 00033 #define VerticeH 00034 00035 #include <zeusmath/Config/PlatformDefines.hpp> 00036 #include <zeusbase/System/ZObject.h> 00037 #include <zeusbase/System/SingleLinkedList.hpp> 00038 00039 00040 BEGIN_NAMESPACE_Zeus 00041 00042 /****************************************************************************/ 00045 /****************************************************************************/ 00046 zeusmath_class TEdge : public TZObject 00047 { 00048 public: 00049 /************************************************************************/ 00052 /************************************************************************/ 00053 inline TEdge() 00054 { 00055 m_uiVertice1 = 0; 00056 m_uiVertice2 = 0; 00057 m_fWeight = 0; 00058 } 00059 00060 /************************************************************************/ 00063 /************************************************************************/ 00064 inline TEdge(Uint uiVertice1, Uint uiVertice2, Float fWeight) 00065 { 00066 m_uiVertice1 = uiVertice1; 00067 m_uiVertice2 = uiVertice2; 00068 m_fWeight = fWeight; 00069 } 00070 00071 /************************************************************************/ 00074 /************************************************************************/ 00075 inline virtual ~TEdge() {} 00076 00077 /************************************************************************/ 00080 /************************************************************************/ 00081 inline void assign(const TEdge& rInPar) 00082 { 00083 m_uiVertice1 = rInPar.m_uiVertice1; 00084 m_uiVertice2 = rInPar.m_uiVertice2; 00085 m_fWeight = rInPar.m_fWeight; 00086 } 00087 00088 /************************************************************************/ 00093 /************************************************************************/ 00094 inline bool equals(const TEdge& rInPar, bool bIgnoreWeight = false) const 00095 { 00096 return (m_uiVertice1 == rInPar.m_uiVertice1 && 00097 m_uiVertice2 == rInPar.m_uiVertice2 && 00098 (bIgnoreWeight || m_fWeight == rInPar.m_fWeight)); 00099 } 00100 00101 inline Uint getVertice1() const { return m_uiVertice1; } 00102 inline Uint getVertice2() const { return m_uiVertice2; } 00103 inline Float getWeight() const { return m_fWeight; } 00104 00105 /************************************************************************/ 00108 /************************************************************************/ 00109 inline TEdge inverse() const 00110 { 00111 return TEdge(m_uiVertice2, m_uiVertice1, m_fWeight); 00112 } 00113 00114 inline void setWeight(Float fValue) { m_fWeight = fValue; } 00115 00116 /************************************************************************/ 00119 /************************************************************************/ 00120 inline TEdge& operator=(const TEdge& rInPar) 00121 { 00122 this->assign(rInPar); 00123 return *this; 00124 } 00125 00126 /************************************************************************/ 00129 /************************************************************************/ 00130 inline bool operator==(const TEdge& rInPar) const 00131 { 00132 return equals(rInPar); 00133 } 00134 00135 /************************************************************************/ 00138 /************************************************************************/ 00139 inline bool operator!=(const TEdge& rInPar) const 00140 { 00141 return !equals(rInPar); 00142 } 00143 00144 protected: 00145 00146 private: 00148 Uint m_uiVertice1; 00150 Uint m_uiVertice2; 00152 Float m_fWeight; 00153 }; 00154 00155 00156 /****************************************************************************/ 00159 /****************************************************************************/ 00160 zeusmath_class TVertice : public TZObject 00161 { 00162 public: 00163 TVertice(Uint uiID, const IZUnknown* pObject); 00164 00165 virtual Retval clone(TVertice*& rpVertice) const; 00166 virtual bool equals(const TVertice& rVertice, bool bIgnoreID = false) const; 00167 virtual Int getEdgeCount() const; 00168 virtual void getEdgeList(IList<TEdge>& rList) const; 00169 virtual void getEdgeList(Uint uiNeighbourVertice, IList<TEdge>& rList) const; 00170 virtual void getNextVertices(IList<Uint>& rList) const; 00171 virtual void getNextVertices(IList<Uint>& rList, IList<Float>& rWeights) const; 00172 virtual Retval getObject(IZUnknown*& rpObject) const; 00173 Float getWeightSum(Uint uiToID) const; 00174 00175 bool hasEdge(Uint uiNextVertice) const; 00176 00177 /************************************************************************/ 00180 /************************************************************************/ 00181 inline Uint getID() const 00182 { 00183 return m_uiID; 00184 } 00185 00186 protected: 00187 virtual ~TVertice(); 00188 00189 virtual Retval addEdge(TEdge& rEdge); 00190 virtual void clearEdges(); 00191 virtual void removeEdge(TEdge& rEdge); 00192 00193 private: 00195 Uint m_uiID; 00197 IZUnknown* m_pObject; 00199 TSingleLinkedList<TEdge> m_lstEdges; 00200 00201 //Must be used because some methods has to be accessed by graph class only 00202 friend class TGraph; 00203 }; 00204 00205 /****************************************************************************/ 00208 /****************************************************************************/ 00209 inline void TVertice::clearEdges() 00210 { 00211 m_lstEdges.clear(); 00212 } 00213 00214 /****************************************************************************/ 00218 /****************************************************************************/ 00219 inline Int TVertice::getEdgeCount() const 00220 { 00221 return m_lstEdges.getCount(); 00222 } 00223 00224 00225 /****************************************************************************/ 00228 /****************************************************************************/ 00229 inline void TVertice::getEdgeList(IList<TEdge>& rList) const 00230 { 00231 m_lstEdges.copyToList(rList); 00232 } 00233 00234 /****************************************************************************/ 00237 /****************************************************************************/ 00238 inline void TVertice::removeEdge(TEdge& rEdge) 00239 { 00240 m_lstEdges.remove(rEdge); 00241 } 00242 00243 END_NAMESPACE_Zeus 00244 //--------------------------------------------------------------------------- 00245 #endif