CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Record.cc
Go to the documentation of this file.
2 #include "AnyData.h"
3 #include "RecordDetails.h"
4 
5 #include<map>
6 
7 namespace {
8  ora::AllKnowTypeHandlers allKnowTypeHandlers;
9 }
10 
11 
12 namespace ora {
13  struct RecordSpecImpl {
14 
15  struct Item {
16  Item(std::string const & iname,
17  TypeHandler const * ih) : name(iname), handler(ih){}
18  std::string name;
20  };
21 
22 
23  std::vector<Item> items;
24 
25  typedef std::map<std::string, int> Lookup;
26 
28 
29 
30  };
31 
32 
34 
36 
37  size_t RecordSpec::add(std::string const & name, std::type_info const & type) {
38  // check if already exists
39  TypeHandler const * th = allKnowTypeHandlers(type);
40  // check if 0...
41  specs->items.push_back(RecordSpecImpl::Item(name,th));
42  specs->indexes.insert(std::make_pair(specs->items.back().name,(int)(specs->items.size())-1));
43  return specs->items.size()-1;
44  }
45 
46 
47 
49 
51  init(ispecs);
52  }
53 
54  void Record::init(RecordSpec ispecs) {
55  destroy();
56  specs = ispecs.specs;
57  size_t s = specs->items.size();
58  m_field.resize(s);
59  for (size_t i=0; i<s; ++i) {
60  RecordSpecImpl::Item const & item = specs->items[i];
61  item.handler->create(m_field[i]);
62  }
63  }
64 
66  destroy();
67  }
68 
69  void Record::destroy() {
70  if (m_field.empty()) return;
71  for (size_t i=0; i<m_field.size(); ++i) {
72  RecordSpecImpl::Item const & item = specs->items[i];
73  item.handler->destroy(m_field[i]);
74  }
75  m_field.clear();
76  }
77 
78 
80  specs.swap(lh.specs);
81  m_field.swap(lh.m_field);
82  }
83 
84 
85  size_t Record::size() const {
86  return m_field.size();
87  }
88 
89  int Record::index(std::string const & iname) const {
90  if (m_field.empty()) return -1;
91  RecordSpecImpl::Lookup::const_iterator p = specs->indexes.find(iname);
92  return (p==specs->indexes.end()) ? -1 : (*p).second;
93  }
94 
95 
96  std::type_info const * Record::type(int i) const {
97  return specs->items[i].handler->type;
98  }
99 
100  void const * Record::address(int i) const {
101  return specs->items[i].handler->address(m_field[i]);
102  }
103 
104  void const * Record::get(int i) const {
105  return specs->items[i].handler->get(m_field[i]);
106  }
107 
108  void Record::set(int i, void * p) {
109  specs->items[i].handler->set(m_field[i],p);
110  }
111 
112 
113  std::string const & Record::name(int i) const {
114  return specs->items[i].name;
115  }
116 
117 
118 
119 }
type
Definition: HCALResponse.h:22
void const * get(int i) const
Definition: Record.cc:104
int i
Definition: DBlmapReader.cc:9
Item(std::string const &iname, TypeHandler const *ih)
Definition: Record.cc:16
virtual void destroy(AnyData &ad) const =0
size_t size() const
Definition: Record.cc:85
void init(RecordSpec ispecs)
Definition: Record.cc:54
bool int lh
Definition: SSEVec.h:55
void swap(Record &lh)
Definition: Record.cc:79
void set(int i, void *p)
Definition: Record.cc:108
int index(std::string const &iname) const
Definition: Record.cc:89
std::string const & name(int i) const
Definition: Record.cc:113
void const * address(int i) const
Definition: Record.cc:100
void destroy()
Definition: Record.cc:69
TypeHandler const * handler
Definition: Record.cc:19
boost::shared_ptr< RecordSpecImpl > specs
Definition: Record.h:24
std::vector< AnyData > m_field
Definition: Record.h:65
size_t add(std::string const &name, std::type_info const &type)
Definition: Record.cc:37
std::vector< Item > items
Definition: Record.cc:23
std::type_info const * type(int i) const
Definition: Record.cc:96
std::map< std::string, int > Lookup
Definition: Record.cc:25
boost::shared_ptr< RecordSpecImpl > specs
Definition: Record.h:64
virtual void create(AnyData &ad) const =0