CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWParameterSetterBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWParameterSetterBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Mar 7 14:16:20 EST 2008
11 // $Id: FWParameterSetterBase.cc,v 1.12 2010/06/18 10:17:16 yana Exp $
12 //
13 
14 // system include files
15 #include "Reflex/Type.h"
16 #include "Reflex/Object.h"
17 
18 #include <assert.h>
19 #include <iostream>
20 #include <boost/bind.hpp>
21 
22 // user include files
24 
29 
30 //
31 // constants, enums and typedefs
32 //
33 
34 //
35 // static data member definitions
36 //
37 
38 //
39 // constructors and destructor
40 //
42  m_frame(0)
43 {
44 }
45 
46 // FWParameterSetterBase::FWParameterSetterBase(const FWParameterSetterBase& rhs)
47 // {
48 // // do actual copying here;
49 // }
50 
52 {
53 }
54 
55 //
56 // assignment operators
57 //
58 // const FWParameterSetterBase& FWParameterSetterBase::operator=(const FWParameterSetterBase& rhs)
59 // {
60 // //An exception safe implementation is
61 // FWParameterSetterBase temp(rhs);
62 // swap(rhs);
63 //
64 // return *this;
65 // }
66 
67 //
68 // member functions
69 //
70 
71 void
73 {
74  m_frame=iFrame;
75  attach(iBase);
76 }
77 
78 
79 //
80 // const member functions
81 //
82 void
84 {
85  if (m_frame != 0)
87 }
88 
89 //
90 // static member functions
91 //
92 boost::shared_ptr<FWParameterSetterBase>
94 {
95  static std::map<edm::TypeID,ROOT::Reflex::Type> s_paramToSetterMap;
96  edm::TypeID paramType( typeid(*iParam) );
97  std::map<edm::TypeID,ROOT::Reflex::Type>::iterator itFind = s_paramToSetterMap.find(paramType);
98  if( itFind == s_paramToSetterMap.end() ) {
99  ROOT::Reflex::Type paramClass( ROOT::Reflex::Type::ByTypeInfo(typeid(*iParam)) );
100  if(paramClass == ROOT::Reflex::Type() ) {
101  fwLog(fwlog::kError) << " the type "<<typeid(*iParam).name()<< " is not known to REFLEX" <<std::endl;
102  }
103  assert(paramClass != ROOT::Reflex::Type() );
104 
105  //the corresponding setter has the same name but with 'Setter' at the end
106  std::string name = paramClass.Name();
107  // FIXME: there was a convention between parameter class names and associated
108  // setters. The following works around the problem introduced by
109  // the generic parameter class but it is clear that a better
110  // way of doing the binding is required. Notice that there are only 5
111  // different type of FW*Parameter.
112  if (name == "FWGenericParameter<bool>")
113  name = "FWBoolParameterSetter";
114  else if (name == "FWGenericParameter<std::string>")
115  name = "FWStringParameterSetter";
116  else if (name == "FWGenericParameter<std::basic_string<char> >")
117  name = "FWStringParameterSetter";
118  else if (name == "FWGenericParameterWithRange<double>")
119  name = "FWDoubleParameterSetter";
120  else if (name == "FWGenericParameterWithRange<long int>")
121  name = "FWLongParameterSetter";
122  else if (name == "FWGenericParameterWithRange<long>")
123  name = "FWLongParameterSetter";
124  else
125  name += "Setter";
126 
127  ROOT::Reflex::Type setterClass( ROOT::Reflex::Type::ByName( name ) );
128  if(setterClass == ROOT::Reflex::Type() ) {
129  fwLog(fwlog::kError) << " the type "<<name<< " is not known to REFLEX" <<std::endl;
130  }
131  assert(setterClass != ROOT::Reflex::Type());
132 
133  s_paramToSetterMap[paramType]=setterClass;
134  itFind = s_paramToSetterMap.find(paramType);
135  }
136  //create the instance we want
137  //NOTE: for some odd reason Reflex 'Construct' uses 'malloc' to allocate the memory. This means the object
138  // can not be deleted using 'delete'! So we must call Type::Destruct on the object
139  ROOT::Reflex::Object setterObj = itFind->second.Construct();
140 
141  //make it into the base class
142  ROOT::Reflex::Type s_setterBaseType( ROOT::Reflex::Type::ByTypeInfo( typeid(FWParameterSetterBase) ) );
143  assert(s_setterBaseType != ROOT::Reflex::Type());
144  ROOT::Reflex::Object castSetterObj = setterObj.CastObject(s_setterBaseType);
145  boost::shared_ptr<FWParameterSetterBase> ptr(reinterpret_cast<FWParameterSetterBase*>( castSetterObj.Address() ),
146  boost::bind(&ROOT::Reflex::Type::Destruct,itFind->second,setterObj.Address(),true));
147  return ptr;
148 }
149 
150 /* Virtual function which sets widgets enabled state.*/
151 void
153 {
154 }
void attach(FWParameterBase *, FWParameterSetterEditorBase *)
static boost::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
virtual void setEnabled(bool)
FWParameterSetterEditorBase * m_frame
#define fwLog(_level_)
Definition: fwLog.h:51