00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/generic/om/PortBundle.hpp $ 00003 // $Id: PortBundle.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 #ifndef TORC_GENERIC_OM_PORTBUNDLE_HPP 00017 #define TORC_GENERIC_OM_PORTBUNDLE_HPP 00018 00019 #include "torc/generic/om/PointerTypes.hpp" 00020 #include "torc/generic/om/DumpRestoreConfig.hpp" 00021 00022 //BOOST 00023 #ifdef GENOM_SERIALIZATION 00024 #include <boost/serialization/access.hpp> 00025 #endif //GENOM_SERIALIZATION 00026 00027 #include "torc/generic/om/Bundle.hpp" 00028 #include "torc/generic/om/BundleFlattener.hpp" 00029 #include "torc/generic/om/Connectable.hpp" 00030 #include "torc/generic/util/Error.hpp" 00031 #include "torc/generic/om/FactoryType.hpp" 00032 #include "torc/generic/om/Port.hpp" 00033 #include "torc/generic/om/VisitorType.hpp" 00034 00035 namespace torc { namespace generic { class Net; } } 00036 namespace torc { namespace generic { class BaseVisitor; } } 00037 00038 namespace torc { 00039 00040 namespace generic { 00041 00042 /** 00043 * @brief Represents a bundle of ports. 00044 * 00045 * The PortBundle class represents an EDIF port bundle. PortBundles are ordered collection of scalar and vector ports and can be created using the (portBundle ...) syntax. 00046 */ 00047 class PortBundle 00048 : public Port, 00049 public Bundle<Port> { 00050 #ifdef GENOM_SERIALIZATION 00051 friend class boost::serialization::access; 00052 #endif //GENOM_SERIALIZATION 00053 00054 friend class FactoryType<PortBundle>; 00055 00056 public: 00057 typedef VisitorType<PortBundle> Visitor; 00058 00059 /** 00060 * Convenience class to create a port bundle. 00061 */ 00062 class Factory: public FactoryType<PortBundle> 00063 { 00064 public: 00065 using FactoryType<PortBundle>::create; 00066 /** 00067 * Create a port bundle. 00068 * 00069 * @param[in] inName Name of the port bundle to be created. 00070 * @param[in] inViewPtr Pointer to parented(View) object. 00071 * @param[in] inParentCollection Pointer to parent bundle. 00072 * @param[in] inOriginalName Original name of the port bundle [optional]. 00073 * 00074 * @return Pointer to created port bundle. 00075 **/ 00076 virtual PortBundleSharedPtr 00077 newPortBundlePtr( const std::string &inName, 00078 const ViewSharedPtr &inViewPtr, 00079 const PortBundleSharedPtr &inParentCollection = PortBundleSharedPtr(), 00080 const std::string &inOriginalName = std::string()) throw(Error); 00081 }; 00082 00083 virtual void 00084 setParent( const ViewSharedPtr &inParent ) throw(); 00085 00086 /** 00087 * Connect a Net to this object. 00088 * 00089 * @note This metod can be overridden by derived classes. However, the method must call the on_connected() method after this. The sigConnected_ signal must also be invoked in the overriding method. 00090 * 00091 * @param[in] inNet A pointer to the Net object that needs to be connected 00092 * @return A connection that has been established. This can be used later for disconnection. 00093 * 00094 * @exception Error Pointer to the Net object does not exists 00095 * <ul> 00096 * <li> 00097 * Id : eMessageIdErrorPointerToItemDoesNotExist 00098 * </li> 00099 * <li> Context Data 00100 * <ul> 00101 * <li>Pointe to Net object - <i>boost::shared_ptr</i></li> 00102 * </ul> 00103 * </li> 00104 * </ul> 00105 * 00106 * @exception Error Net size does not match with port bundle size 00107 * <ul> 00108 * <li> 00109 * Id : eMessageIdErrorItemSizeMismatch 00110 * </li> 00111 * <li> Context Data 00112 * <ul> 00113 * <li>Net Size - <i>SizeType</i></li> 00114 * <li>Port Size - <i>SizeType</i></li> 00115 * </ul> 00116 * </li> 00117 * </ul> 00118 * 00119 */ 00120 virtual Connectable::Connection 00121 connect(const NetSharedPtr &inNet) throw(Error); 00122 00123 /** 00124 * Disconnect a Net from this object. 00125 * @note This metod can be overridden by derived classes. However, the method must call the on_connected() method after this. The sigConnected_ signal must also be invoked in the overriding method. 00126 00127 * @param[in] inConnection A connection as returned by the connect() method 00128 * @exception Error Provided connection is invalid, because pointer to the Net does not exist 00129 * <ul> 00130 * <li> 00131 * Id : eMessageIdErrorPointerToItemDoesNotExist 00132 * </li> 00133 * <li> Context Data 00134 * <ul> 00135 * <li>Pointer to Net - <i>boost::shared_ptr</i></li> 00136 * </ul> 00137 * </li> 00138 * </ul> 00139 * 00140 */ 00141 void 00142 disconnect(const Connectable::Connection &inConnection) throw(Error); 00143 00144 using Connectable::disconnect; 00145 00146 virtual void 00147 accept(BaseVisitor & inoutVisitor) throw(Error); 00148 00149 virtual 00150 ~PortBundle() throw(); 00151 00152 protected: 00153 PortBundle(); 00154 00155 private: 00156 #ifdef GENOM_SERIALIZATION 00157 template<class Archive> void 00158 serialize( Archive &ar, unsigned int ); 00159 #endif //GENOM_SERIALIZATION 00160 00161 00162 }; 00163 00164 } // namespace torc::generic 00165 00166 } // namespace torc 00167 #endif // TORC_GENERIC_OM_PORTBUNDLE_HPP