CMS 3D CMS Logo

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 //
12 
13 // system include files
16 
17 #include <assert.h>
18 #include <iostream>
19 #include <boost/bind.hpp>
20 
21 // user include files
23 
28 
29 //
30 // constants, enums and typedefs
31 //
32 
33 //
34 // static data member definitions
35 //
36 
37 //
38 // constructors and destructor
39 //
41  m_frame(0)
42 {
43 }
44 
45 // FWParameterSetterBase::FWParameterSetterBase(const FWParameterSetterBase& rhs)
46 // {
47 // // do actual copying here;
48 // }
49 
51 {
52 }
53 
54 //
55 // assignment operators
56 //
57 // const FWParameterSetterBase& FWParameterSetterBase::operator=(const FWParameterSetterBase& rhs)
58 // {
59 // //An exception safe implementation is
60 // FWParameterSetterBase temp(rhs);
61 // swap(rhs);
62 //
63 // return *this;
64 // }
65 
66 //
67 // member functions
68 //
69 
70 void
72 {
73  m_frame=iFrame;
74  attach(iBase);
75 }
76 
77 
78 //
79 // const member functions
80 //
81 
82 void
84 {
85  if (m_frame != 0)
87 }
88 
89 //
90 // static member functions
91 //
92 
93 std::shared_ptr<FWParameterSetterBase>
95 {
96  static std::map<edm::TypeID,edm::TypeWithDict> s_paramToSetterMap;
97  edm::TypeID paramType( typeid(*iParam) );
98  std::map<edm::TypeID,edm::TypeWithDict>::iterator itFind = s_paramToSetterMap.find(paramType);
99  if (itFind == s_paramToSetterMap.end())
100  {
101  edm::TypeWithDict paramClass(typeid(*iParam));
102  if (paramClass == edm::TypeWithDict())
103  {
104  fwLog(fwlog::kError) << " the type "<<typeid(*iParam).name()<< " is not known to Root" <<std::endl;
105  }
106  assert(paramClass != edm::TypeWithDict() );
107 
108  //the corresponding setter has the same name but with 'Setter' at the end
109  std::string name = paramClass.name();
110  // FIXME: there was a convention between parameter class names and associated
111  // setters. The following works around the problem introduced by
112  // the generic parameter class but it is clear that a better
113  // way of doing the binding is required. Notice that there are only 5
114  // different type of FW*Parameter.
115  if (name == "FWGenericParameter<bool>")
116  name = "FWBoolParameterSetter";
117  else if (name == "FWGenericParameter<std::string>")
118  name = "FWStringParameterSetter";
119  else if (name == "FWGenericParameter<std::basic_string<char> >")
120  name = "FWStringParameterSetter";
121  else if (name == "FWGenericParameterWithRange<double>")
122  name = "FWDoubleParameterSetter";
123  else if (name == "FWGenericParameterWithRange<long int>")
124  name = "FWLongParameterSetter";
125  else if (name == "FWGenericParameterWithRange<long>")
126  name = "FWLongParameterSetter";
127  else
128  name += "Setter";
129 
130  edm::TypeWithDict setterClass( edm::TypeWithDict::byName( name ) );
131  if (setterClass == edm::TypeWithDict())
132  {
133  fwLog(fwlog::kError) << " the type "<<name<< " has no dictionary" <<std::endl;
134  }
135  assert(setterClass != edm::TypeWithDict());
136 
137  s_paramToSetterMap[paramType]=setterClass;
138  itFind = s_paramToSetterMap.find(paramType);
139  }
140  //create the instance we want
141  //NOTE: 'construct' will use 'malloc' to allocate the memory if the object is not of class type.
142  // This means the object cannot be deleted using 'delete'! So we must call destruct on the object.
143  edm::ObjectWithDict setterObj = itFind->second.construct();
144 
145  //make it into the base class
146  FWParameterSetterBase* p = static_cast<FWParameterSetterBase*>(setterObj.address());
147  //Make a shared pointer to the base class that uses a destructor for the derived class, in order to match the above construct call.
148  std::shared_ptr<FWParameterSetterBase> ptr(p, boost::bind(&edm::TypeWithDict::destruct,itFind->second,setterObj.address(),true));
149  return ptr;
150 }
151 
152 /* Virtual function which sets widgets enabled state.*/
153 void
155 {
156 }
void * address() const
void attach(FWParameterBase *, FWParameterSetterEditorBase *)
virtual void setEnabled(bool)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
std::string name() const
FWParameterSetterEditorBase * m_frame
#define fwLog(_level_)
Definition: fwLog.h:50
void destruct(void *address, bool dealloc=true) const
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)