STK++ 1.0
STK_IStep.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  Serge Iovleff
00003 
00004  This program is free software; you can redistribute it and/or modify
00005  it under the terms of the GNU Lesser General Public License as
00006  published by the Free Software Foundation; either version 2 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,
00010  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  GNU 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 program; if not, write to the
00016  Free Software Foundation, Inc.,
00017  59 Temple Place,
00018  Suite 330,
00019  Boston, MA 02111-1307
00020  USA
00021 
00022  Contact : Serge.Iovleff@stkpp.org
00023  */
00024 
00025 /*
00026  * Project:  stkpp::gui::model
00027  * created on: 5 oct. 2009
00028  * Purpose:  implement the non virtual part of the Interface IStep.
00029  * Author:   iovleff, serge.iovleff@stkpp.org
00030  **/
00031 
00036 #include "../include/STK_IStep.h"
00037 #include "../include/STK_Connection.h"
00038 
00039 namespace STK
00040 {
00041 
00042 /* Property ID to use when the list of outgoing connections is modified. */
00043 const String IStep::ID_STEP_SOURCE_CONNECTIONS = "Step.SourceConnection";
00044 
00045 /* Property ID to use when the list of incoming connections is modified. */
00046 const String IStep::ID_STEP_TARGET_CONNECTIONS = "Step.TargetConnection";
00047 
00048 /* Property ID for the X property value.  */
00049 const String IStep::ID_STEP_XLOCATION = "Step.xLocation";
00050 
00051 /* Property ID for the Y property value.  */
00052 const String IStep::ID_STEP_YLOCATION = "Step.yLocation";
00053 
00054 /* Descriptor of the source connections property */
00055 const PropertyDescriptor IStep::sourceConnectionsDescriptor_( IStep::ID_STEP_SOURCE_CONNECTIONS
00056                                                             , "Incoming connections");
00057 
00058 /* Descriptor of the target connections property */
00059 const PropertyDescriptor IStep::targetConnectionsDescriptor_( IStep::ID_STEP_SOURCE_CONNECTIONS
00060                                                             , "Outgoing connections");
00061 
00062 /* Descriptor of the x location property */
00063 const PropertyDescriptor IStep::xLocationDescriptor_( IStep::ID_STEP_XLOCATION
00064                                                     , "X");
00065 
00066 /* Descriptor of the y location property */
00067 const PropertyDescriptor IStep::yLocationDescriptor_( IStep::ID_STEP_YLOCATION
00068                                                     , "Y");
00069 
00070 
00071 IStep::IStep( String const& name, Real const& x, Real const& y)
00072             : name_(name)
00073             , xLocation_(x)
00074             , yLocation_(y)
00075             , incomingConnections_()
00076             , outgoingConnections_()
00077 { ;}
00078 
00079 
00080 IStep::~IStep()
00081 {
00082   std::list<Connection*>::iterator it;
00083   // remove outgoing connections
00084   for (it=outgoingConnections_.begin(); it!=outgoingConnections_.end(); it++)
00085   {
00086     delete *it;
00087   }
00088   outgoingConnections_.clear();
00089   // incoming connections will be released by the sources
00090   incomingConnections_.clear();
00091 }
00092 
00093 /*  remove a connection to this Step. return false if
00094  *  the connection was not in the list incomingConnections_
00095  *  or outgoingConnections_
00096  *
00097  *  @param Connection The connection to remove
00098  */
00099 void IStep::removeConnection(Connection* connection)
00100 {
00101   // check if it is an outgoing connection
00102   if (connection->getSource() == this)
00103   {
00104     // remove Connection from the outgoing list of connection
00105     outgoingConnections_.remove(connection);
00106     // release memory
00107     delete connection;
00108     connection = (Connection*)NULL;
00109     return;
00110   }
00111   // check if it is an incoming connection
00112   if (connection->getTarget() == this)
00113   {
00114     incomingConnections_.remove(connection);
00115   }
00116   return;
00117 }
00118 
00119 /* Add a connection to this Step.
00120  *
00121  * @param Connection The connection to add
00122  */
00123 void IStep::addConnection(Connection* connection)
00124 {
00125   std::list<Connection*>::iterator it;
00126   // check if it is an outgoing connection
00127   if (connection->getSource() == this)
00128   {
00129     // check if the connection is already present
00130     for (it=outgoingConnections_.begin(); it!=outgoingConnections_.end(); it++)
00131     {
00132       if (*it == connection) return;
00133     }
00134     // add connection
00135     outgoingConnections_.push_back(connection);
00136     return;
00137   }
00138 
00139   // check if it is an incoming connection
00140   if (connection->getTarget() == this)
00141   {
00142     // check if the connection is already present
00143     for (it=incomingConnections_.begin(); it!=incomingConnections_.end(); it++)
00144     {
00145       if (*it == connection) return;
00146     }
00147     incomingConnections_.push_back(connection);
00148   }
00149 }
00150 
00151 /* @brief Implementation of the pure virtual method
00152  *  <code> isPropertySet</code> defined in <code> IPropertySource</code>
00153  * @see IPropertySource#isPropertySet
00154  * @return <code>true</code> if id is a valid IStep id property.
00155  */
00156 bool IStep::isPropertySet(String const& id) const
00157 {
00158   if (  (id==ID_STEP_SOURCE_CONNECTIONS)
00159       ||(id==ID_STEP_TARGET_CONNECTIONS)
00160       ||(id==ID_STEP_XLOCATION)
00161       ||(id==ID_STEP_YLOCATION)
00162      )
00163   { return true;}
00164   return false;
00165 }
00166 
00167 /* @brief Implementation of the pure virtual method
00168  *  <code> getPropertyValue</code> defined in <code> IPropertySource</code>
00169  * @see IPropertySource#getPropertValue
00170  *
00171  * @param id
00172  *            the id of the property being set
00173  * @return the value of the property, or <code>NULL</code>
00174  */
00175 const String* IStep::getPropertyValue(String const& id) const
00176 {
00177   return NULL;
00178 }
00179 
00180 
00181 } // namespace STK