Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Link.hpp

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2004 Andrew Sutton 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to: 00016 * 00017 * The Free Software Foundation, Inc. 00018 * 59 Temple Place, Suite 330 00019 * Boston, MA 02111-1307 USA 00020 * 00021 * Contact: 00022 * Andrew Sutton asutton@cs.kent.edu 00023 */ 00024 00025 #ifndef OMF_LINK_HPP 00026 #define OMF_LINK_HPP 00027 00028 // std includes 00029 #include <set> 00030 00031 // OMF includes 00032 #include <OMF/Exception.hpp> 00033 #include <OMF/Object.hpp> 00034 00035 namespace OMF 00036 { 00037 // forward declarations 00038 class ModelObject; 00039 00046 struct Link 00047 { 00048 virtual ~Link() 00049 {} 00050 00051 virtual ModelObject *firstEnd() = 0; 00052 virtual void setFirstEnd(ModelObject *end) = 0; 00053 00054 virtual ModelObject *secondEnd() = 0; 00055 virtual void setSecondEnd(ModelObject *end) = 0; 00056 }; 00057 00061 typedef std::set<Link *> LinkSet; 00062 00069 template <class End1, class End2> 00070 struct BasicLink : public Link 00071 { 00072 typedef End1 FirstEndType; 00073 typedef End2 SecondEndType; 00074 00075 BasicLink(FirstEndType *first, SecondEndType *second) : 00076 _firstEnd(first), 00077 _secondEnd(second) 00078 {} 00079 00080 virtual ~BasicLink() 00081 {} 00082 00083 FirstEndType *_firstEnd; 00084 SecondEndType *_secondEnd; 00085 00086 virtual ModelObject *firstEnd() 00087 { return _firstEnd; } 00088 00089 virtual void setFirstEnd(ModelObject *end) 00090 { 00091 FirstEndType *first = dynamic_cast<FirstEndType *>(end); 00092 if(!first) { 00093 throw TypeMismatchError(); 00094 } 00095 _firstEnd = first; 00096 }; 00097 00098 virtual ModelObject *secondEnd() 00099 { return _secondEnd; } 00100 00101 virtual void setSecondEnd(ModelObject *end) 00102 { 00103 SecondEndType *second = dynamic_cast<SecondEndType *>(end); 00104 if(!second) { 00105 throw TypeMismatchError(); 00106 } 00107 _secondEnd = second; 00108 }; 00109 }; 00110 }; 00111 00112 #endif

Generated on Fri Sep 10 13:07:33 2004 for OpenModelingFramework by doxygen 1.3.8