CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Fireworks/Core/src/FWParameterSetterBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWParameterSetterBase
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Mar  7 14:16:20 EST 2008
00011 // $Id: FWParameterSetterBase.cc,v 1.13 2010/09/24 18:51:18 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include "Reflex/Type.h"
00016 #include "Reflex/Object.h"
00017 
00018 #include <assert.h>
00019 #include <iostream>
00020 #include <boost/bind.hpp>
00021 
00022 // user include files
00023 #include "FWCore/Utilities/interface/TypeID.h"
00024 
00025 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00026 #include "Fireworks/Core/interface/FWParameterBase.h"
00027 #include "Fireworks/Core/interface/FWParameterSetterEditorBase.h"
00028 #include "Fireworks/Core/interface/fwLog.h"
00029 
00030 //
00031 // constants, enums and typedefs
00032 //
00033 
00034 //
00035 // static data member definitions
00036 //
00037 
00038 //
00039 // constructors and destructor
00040 //
00041 FWParameterSetterBase::FWParameterSetterBase() :
00042    m_frame(0)
00043 {
00044 }
00045 
00046 // FWParameterSetterBase::FWParameterSetterBase(const FWParameterSetterBase& rhs)
00047 // {
00048 //    // do actual copying here;
00049 // }
00050 
00051 FWParameterSetterBase::~FWParameterSetterBase()
00052 {
00053 }
00054 
00055 //
00056 // assignment operators
00057 //
00058 // const FWParameterSetterBase& FWParameterSetterBase::operator=(const FWParameterSetterBase& rhs)
00059 // {
00060 //   //An exception safe implementation is
00061 //   FWParameterSetterBase temp(rhs);
00062 //   swap(rhs);
00063 //
00064 //   return *this;
00065 // }
00066 
00067 //
00068 // member functions
00069 //
00070 
00071 void
00072 FWParameterSetterBase::attach(FWParameterBase* iBase, FWParameterSetterEditorBase* iFrame)
00073 {
00074    m_frame=iFrame;
00075    attach(iBase);
00076 }
00077 
00078 
00079 //
00080 // const member functions
00081 //
00082 void
00083 FWParameterSetterBase::update() const
00084 {
00085    if (m_frame != 0)
00086       m_frame->updateEditor();
00087 }
00088 
00089 //
00090 // static member functions
00091 //
00092 boost::shared_ptr<FWParameterSetterBase>
00093 FWParameterSetterBase::makeSetterFor(FWParameterBase* iParam)
00094 {
00095    static std::map<edm::TypeID,ROOT::Reflex::Type> s_paramToSetterMap;
00096    edm::TypeID paramType( typeid(*iParam) );
00097    std::map<edm::TypeID,ROOT::Reflex::Type>::iterator itFind = s_paramToSetterMap.find(paramType);
00098    if( itFind == s_paramToSetterMap.end() ) {
00099       ROOT::Reflex::Type paramClass( ROOT::Reflex::Type::ByTypeInfo(typeid(*iParam)) );
00100       if(paramClass == ROOT::Reflex::Type() ) {
00101          fwLog(fwlog::kError) << " the type "<<typeid(*iParam).name()<< " is not known to REFLEX" <<std::endl;
00102       }
00103       assert(paramClass != ROOT::Reflex::Type() );
00104 
00105       //the corresponding setter has the same name but with 'Setter' at the end
00106       std::string name = paramClass.Name();
00107       // FIXME: there was a convention between parameter class names and associated
00108       //        setters. The following works around the problem introduced by
00109       //        the generic parameter class but it is clear that a better 
00110       //        way of doing the binding is required. Notice that there are only 5 
00111       //        different type of FW*Parameter.
00112       if (name == "FWGenericParameter<bool>")
00113          name = "FWBoolParameterSetter";
00114       else if (name == "FWGenericParameter<std::string>")
00115          name = "FWStringParameterSetter";
00116       else if (name == "FWGenericParameter<std::basic_string<char> >")
00117          name = "FWStringParameterSetter"; 
00118       else if (name == "FWGenericParameterWithRange<double>")
00119          name = "FWDoubleParameterSetter";
00120       else if (name == "FWGenericParameterWithRange<long int>")
00121          name = "FWLongParameterSetter";
00122       else if (name == "FWGenericParameterWithRange<long>")
00123          name = "FWLongParameterSetter";
00124       else
00125          name += "Setter";
00126 
00127       ROOT::Reflex::Type setterClass( ROOT::Reflex::Type::ByName( name ) );
00128       if(setterClass == ROOT::Reflex::Type() ) {
00129          fwLog(fwlog::kError) << " the type "<<name<< " is not known to REFLEX" <<std::endl;
00130       }
00131       assert(setterClass != ROOT::Reflex::Type());
00132 
00133       s_paramToSetterMap[paramType]=setterClass;
00134       itFind = s_paramToSetterMap.find(paramType);
00135    }
00136    //create the instance we want
00137    //NOTE: for some odd reason Reflex 'Construct' uses 'malloc' to allocate the memory.  This means the object
00138    // can not be deleted using 'delete'!  So we must call Type::Destruct on the object
00139    ROOT::Reflex::Object setterObj = itFind->second.Construct();
00140 
00141    //make it into the base class
00142    ROOT::Reflex::Type s_setterBaseType( ROOT::Reflex::Type::ByTypeInfo( typeid(FWParameterSetterBase) ) );
00143    assert(s_setterBaseType != ROOT::Reflex::Type());
00144    ROOT::Reflex::Object castSetterObj = setterObj.CastObject(s_setterBaseType);
00145    boost::shared_ptr<FWParameterSetterBase> ptr(reinterpret_cast<FWParameterSetterBase*>( castSetterObj.Address() ),
00146                                                 boost::bind(&ROOT::Reflex::Type::Destruct,itFind->second,setterObj.Address(),true));
00147    return ptr;
00148 }
00149 
00150 /* Virtual function which sets widgets enabled state.*/
00151 void
00152 FWParameterSetterBase::setEnabled(bool)
00153 {
00154 }