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.17 2013/02/18 23:42:56 wmtan Exp $
12 //
13 
14 // system include files
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 
83 void
85 {
86  if (m_frame != 0)
88 }
89 
90 //
91 // static member functions
92 //
93 
94 boost::shared_ptr<FWParameterSetterBase>
96 {
97  static std::map<edm::TypeID,edm::TypeWithDict> s_paramToSetterMap;
98  edm::TypeID paramType( typeid(*iParam) );
99  std::map<edm::TypeID,edm::TypeWithDict>::iterator itFind = s_paramToSetterMap.find(paramType);
100  if (itFind == s_paramToSetterMap.end())
101  {
102  edm::TypeWithDict paramClass(typeid(*iParam));
103  if (paramClass == edm::TypeWithDict())
104  {
105  fwLog(fwlog::kError) << " the type "<<typeid(*iParam).name()<< " is not known to Root" <<std::endl;
106  }
107  assert(paramClass != edm::TypeWithDict() );
108 
109  //the corresponding setter has the same name but with 'Setter' at the end
110  std::string name = paramClass.name();
111  // FIXME: there was a convention between parameter class names and associated
112  // setters. The following works around the problem introduced by
113  // the generic parameter class but it is clear that a better
114  // way of doing the binding is required. Notice that there are only 5
115  // different type of FW*Parameter.
116  if (name == "FWGenericParameter<bool>")
117  name = "FWBoolParameterSetter";
118  else if (name == "FWGenericParameter<std::string>")
119  name = "FWStringParameterSetter";
120  else if (name == "FWGenericParameter<std::basic_string<char> >")
121  name = "FWStringParameterSetter";
122  else if (name == "FWGenericParameterWithRange<double>")
123  name = "FWDoubleParameterSetter";
124  else if (name == "FWGenericParameterWithRange<long int>")
125  name = "FWLongParameterSetter";
126  else if (name == "FWGenericParameterWithRange<long>")
127  name = "FWLongParameterSetter";
128  else
129  name += "Setter";
130 
131  edm::TypeWithDict setterClass( edm::TypeWithDict::byName( name ) );
132  if (setterClass == edm::TypeWithDict())
133  {
134  fwLog(fwlog::kError) << " the type "<<name<< " has no dictionary" <<std::endl;
135  }
136  assert(setterClass != edm::TypeWithDict());
137 
138  s_paramToSetterMap[paramType]=setterClass;
139  itFind = s_paramToSetterMap.find(paramType);
140  }
141  //create the instance we want
142  //NOTE: 'construct' will use 'malloc' to allocate the memory if the object is not of class type.
143  // This means the object cannot be deleted using 'delete'! So we must call destruct on the object.
144  edm::ObjectWithDict setterObj = itFind->second.construct();
145 
146  //make it into the base class
147  FWParameterSetterBase* p = static_cast<FWParameterSetterBase*>(setterObj.address());
148  //Make a shared pointer to the base class that uses a destructor for the derived class, in order to match the above construct call.
149  boost::shared_ptr<FWParameterSetterBase> ptr(p, boost::bind(&edm::TypeWithDict::destruct,itFind->second,setterObj.address(),true));
150  return ptr;
151 }
152 
153 /* Virtual function which sets widgets enabled state.*/
154 void
156 {
157 }
static TypeWithDict byName(std::string const &className)
void * address() const
void attach(FWParameterBase *, FWParameterSetterEditorBase *)
static boost::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
virtual void setEnabled(bool)
std::string name() const
FWParameterSetterEditorBase * m_frame
#define fwLog(_level_)
Definition: fwLog.h:51
void destruct(void *address, bool dealloc=true) const