|
STK++ 1.0
|
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: 19 oct. 2009 00028 * Purpose: implement the GProgram class. 00029 * Author: iovleff, serge.iovleff@stkpp.org 00030 **/ 00031 00036 #include <list> 00037 #include "../include/STK_GProgram.h" 00038 #include "../include/STK_IStep.h" 00039 #include "../include/STK_Connection.h" 00040 00041 namespace STK 00042 { 00043 /* Property ID to use when the name of the program is modified. */ 00044 const String GProgram::ID_GPROGAM_NAME = "GProgram.name"; 00045 00046 /* Descriptor of the source connections property */ 00047 const PropertyDescriptor GProgram::nameDescriptor_( GProgram::ID_GPROGAM_NAME 00048 , "Name"); 00049 00050 00051 GProgram::GProgram(String const& name) : IPropertySource() 00052 , name_(name) 00053 { } 00054 00055 GProgram::~GProgram() 00056 { 00057 std::list<IStep*>::iterator it; 00058 // remove steps in the program 00059 for (it=steps_.begin(); it!=steps_.end(); it++) 00060 { 00061 delete *it; 00062 } 00063 } 00064 00066 void GProgram::run() 00067 {;} 00068 00069 /* Add a step to the Program. 00070 * @param step The step to add 00071 **/ 00072 void GProgram::addStep(IStep* step) 00073 { 00074 std::list<IStep*>::iterator it; 00075 // check if the step is already present 00076 for (it=steps_.begin(); it!=steps_.end(); it++) 00077 { 00078 if (*it == step) return; 00079 } 00080 steps_.push_back(step); 00081 } 00082 00089 void GProgram::removeStep(IStep* step) 00090 { 00091 std::list<Connection*>& incomingConnection = step->getIncomingConnections(); 00092 std::list<Connection*>::iterator it; 00093 // remove the incoming Connections 00094 for (it=incomingConnection.begin(); it!=incomingConnection.end(); it++) 00095 { 00096 Connection* arc = *it; 00097 arc->getSource()->removeConnection(arc); 00098 } 00099 // remove the IStep 00100 steps_.remove(step); 00101 delete step; 00102 } 00103 00119 bool GProgram::addConnection(IStep* source, IStep* target) 00120 { 00121 // TODO Check for an infinite loop in the program 00122 // no loop we create the connection and add it 00123 Connection* arc = new Connection(source, target); 00124 source->addConnection(arc); 00125 target->addConnection(arc); 00126 return true; 00127 } 00128 00129 /* @brief Implementation of the pure virtual method 00130 * <code> isPropertySet</code> defined in <code> IPropertySource</code> 00131 * @see IPropertySource#isPropertySet 00132 * @return <code>true</code> if id is a valid IStep id property. 00133 */ 00134 bool GProgram::isPropertySet(String const& id) const 00135 { 00136 if (id==ID_GPROGAM_NAME) 00137 { return true;} 00138 return false; 00139 } 00140 00141 /* @brief Implementation of the pure virtual method 00142 * <code> getPropertyValue</code> defined in <code> IPropertySource</code> 00143 * @see IPropertySource#getPropertValue 00144 * 00145 * @param id 00146 * the id of the property being set 00147 * @return the value of the property, or <code>NULL</code> 00148 */ 00149 const String* GProgram::getPropertyValue(String const& id) const 00150 { 00151 return &name_; 00152 } 00153 00154 00155 }// STK namespace 00156