00001 /* 00002 FSF: Flow Scheduling Framework library 00003 00004 Version 1.0 Copyright (C) 2010 Alexandre R.J. Francois 00005 00006 Previous versions Copyright (C) 2001-2005 University of Southern California 00007 00008 Author: Alexandre R.J. Francois - alexandrefrancois@yahoo.com 00009 www.alexandrefrancois.org 00010 00011 Modular Flow Scheduling Middleware 00012 mfsm.sourceForge.net 00013 00014 This library is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU Lesser General Public 00016 License as published by the Free Software Foundation; either 00017 version 2.1 of the License, or (at your option) any later version. 00018 00019 This library is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 Lesser General Public License for more details. 00023 00024 You should have received a copy of the GNU Lesser General Public 00025 License along with this library; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00027 */ 00028 00029 #ifndef FSF_TYPE_CELL_H 00030 #define FSF_TYPE_CELL_H 00031 00032 #include "FsfTypeCellBase.h" 00033 00034 namespace fsf { 00035 00036 00039 template <typename Type> class CTypeCell : public CTypeCellBase { 00040 public: 00042 00043 00045 CTypeCell() : CTypeCellBase() { 00046 typedef CTypeNode<Type> NodeType; 00047 // default output name 00048 setOutputName("Output"); 00049 // set the filters 00050 setPassiveFilter(new fsf::CPassiveFilter<NodeType>(std::string("*"))); 00051 setActiveFilter(new fsf::CActiveFilter<NodeType>(std::string("*"),-1,true)); 00052 } 00053 00055 00056 00057 // Gets this cell type's factory mapping key 00058 virtual void getTypeID(std::string &str) const { str.assign("FSF_TYPE_CELL"); } 00059 00061 00063 00064 00065 // Specialized processing function 00066 // Process function has special semantics for this cell type: 00067 // active handle can be null (=get value) or non null (=set value) 00068 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse) { 00069 typedef CTypeNode<Type> NodeType; 00070 00071 NodeType *pValueNode=static_cast<NodeType*>(pPassiveHandle->getNode()); 00072 00073 if(pActiveHandle){ 00074 // input present: SET value 00075 NodeType *pInputNode=static_cast<NodeType*>(pActiveHandle->getNode()); 00076 pValueNode->setData(pInputNode->getData()); 00077 } 00078 else{ 00079 // not input present: GET value 00080 lockOutputName(); 00081 NodeType *pOutputNode=new NodeType(getOutputName(),pActivePulse,CSystem::getInstance()->getTime()); 00082 unlockOutputName(); 00083 pOutputNode->setData(pValueNode->getData()); 00084 pActivePulse->addComponent(pOutputNode); 00085 } 00086 } 00087 00089 00090 }; 00091 00092 00102 00103 00106 typedef CTypeCell<long int> Int32Cell; 00108 template<> inline void Int32Cell::getTypeID(std::string &str) const { str.assign("FSF_INT32_CELL"); } 00109 00112 typedef CTypeCell<long long int> Int64Cell; 00114 template<> inline void Int64Cell::getTypeID(std::string &str) const { str.assign("FSF_INT64_CELL"); } 00115 00118 typedef CTypeCell<float> Float32Cell; 00120 template<> inline void Float32Cell::getTypeID(std::string &str) const { str.assign("FSF_FLOAT32_CELL"); } 00121 00124 typedef CTypeCell<double> Float64Cell; 00126 template<> inline void Float64Cell::getTypeID(std::string &str) const { str.assign("FSF_FLOAT64_CELL"); } 00127 00130 typedef CTypeCell<bool> BoolCell; 00132 template<> inline void BoolCell::getTypeID(std::string &str) const { str.assign("FSF_BOOL_CELL"); } 00133 00136 typedef CTypeCell<std::string> StringCell; 00138 template<> inline void StringCell::getTypeID(std::string &str) const { str.assign("FSF_STRING_CELL"); } 00139 00141 00142 } // namespace fsf 00143 00144 #endif // FSF_TYPE_CELL_H 00145