BinaryControlOp.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __BINARYCONTROLOP__
00023 #define __BINARYCONTROLOP__
00024 
00025 #include "Processing.hxx"
00026 #include "InControl.hxx" // MRJ: For the TControlData definition :D
00027 #include "OutControl.hxx"
00028 #include <iosfwd>
00029 
00030 namespace CLAM {
00031 
00032         class BinaryControlOpConfig: public ProcessingConfig
00033         {
00034         public:
00035                 DYNAMIC_TYPE_USING_INTERFACE (BinaryControlOpConfig, 1,ProcessingConfig);
00036 
00037                 DYN_ATTRIBUTE (0, public, std::string, Name);
00038 
00039         protected:
00040 
00041                 void DefaultInit()
00042                 {
00043                         AddName();
00044                         UpdateData();
00045                 }
00046         };
00047 
00048         template < typename BinOp >
00049         class BinaryControlOp:public Processing
00050         {
00051         private:
00052                 TControlData mOutValue;
00053                 TControlData mFirstParmLastValue;
00054                 TControlData mSecondParmLastValue;
00055                 OutControl mOutput;
00056                 BinaryControlOpConfig mConfig;
00057                 BinOp mOperation;
00058 
00059                 inline const char *GetClassName() const;
00060 
00061                 int HandleFirst( TControlData incoming_parm )
00062                 {
00063                         mFirstParmLastValue = incoming_parm;
00064                         mOutValue = DoOperation();
00065                         Do();
00066                         return 1 ;
00067                 }
00068 
00069                 int HandleSecond( TControlData incoming_parm )
00070                 {
00071                         mSecondParmLastValue = incoming_parm;
00072                         mOutValue = DoOperation();
00073                         Do();
00074                         return 1;
00075                 }
00076 
00077         public:
00078                 InControlTmpl< BinaryControlOp > mFirst;
00079                 InControlTmpl< BinaryControlOp > mSecond;
00080                 
00081                 BinaryControlOp()
00082                         : mOutValue(0),
00083                           mFirstParmLastValue( BinOp::IdentityElement ),
00084                           mSecondParmLastValue(BinOp::IdentityElement),
00085                           mOutput( "output", this ),
00086                           mFirst( "first_parm", this, &BinaryControlOp::HandleFirst ),
00087                           mSecond( "second_parm", this, &BinaryControlOp::HandleSecond )
00088                 {
00089                         Configure( BinaryControlOpConfig() );
00090                 }
00091 
00092                 BinaryControlOp(const BinaryControlOpConfig& cfg)
00093                         : mOutValue(0),
00094                           mFirstParmLastValue( BinOp::IdentityElement ),
00095                           mSecondParmLastValue(BinOp::IdentityElement),
00096                           mOutput( "output", this ),
00097                           mFirst( "first_parm", this, &BinaryControlOp::HandleFirst ),
00098                           mSecond( "second_parm", this, &BinaryControlOp::HandleSecond )
00099                 {
00100                         Configure(cfg);
00101                 }
00102 
00103                 bool ConcreteConfigure(const ProcessingConfig& c)
00104                 {
00105                         CopyAsConcreteConfig(mConfig, c);
00106                         return true;
00107                 }
00108 
00109                 const ProcessingConfig &GetConfig() const { return mConfig;};
00110 
00111                 TControlData DoOperation()
00112                 {
00113                         return mOperation( mFirstParmLastValue, mSecondParmLastValue );
00114                 }
00115 
00116                 bool Do(void) 
00117                 {
00118                         mOutput.SendControl( mOutValue );       
00119                         return true ;
00120                 }
00121         };
00122 
00123         template < typename BinOp >
00124         inline const char *BinaryControlOp<BinOp>::GetClassName() const { return "BinaryControlOperation"; }
00125 
00126 }
00127 
00128 #endif // BinaryControlOp.hxx
00129 

Generated on Tue Aug 12 22:33:42 2008 for CLAM by  doxygen 1.5.5