source: trunk/FACT++/src/DimDescriptionService.h@ 16479

Last change on this file since 16479 was 16475, checked in by tbretz, 12 years ago
Added the missing setData with a typename template.
File size: 3.0 KB
Line 
1#ifndef FACT_DimDescriptionService
2#define FACT_DimDescriptionService
3
4#include <set>
5#include <array>
6#include <string>
7#include <vector>
8
9class Time;
10class DimService;
11
12class DimDescriptionService
13{
14 static int fCount; /// Counter to count the number of instatiations
15 static DimService *fService; /// Pointer to the DimService distributing the desscriptions
16 static std::string fData; /// Data to be distributed with the service
17
18 std::string fDescription; /// Local storage for the applied description
19
20public:
21 DimDescriptionService(const std::string &name, const std::string &format);
22 virtual ~DimDescriptionService();
23
24 std::string GetDescription() const { return fDescription; }
25};
26
27#include "dis.hxx"
28
29class DimDescribedService : public DimDescriptionService, public DimService
30{
31 static std::set<std::string> fServices;
32
33public:
34 template<typename T>
35 DimDescribedService(const std::string &name, const T &val, const char *desc)
36 : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), const_cast<T&>(val))
37 {
38 fServices.insert(getName());
39 setQuality(0);
40 }
41
42 template<typename T>
43 DimDescribedService(const std::string &name, const char *format, const T &val, const char *desc)
44 : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, const_cast<T*>(&val), sizeof(T))
45 {
46 fServices.insert(getName());
47 setQuality(0);
48 }
49
50 DimDescribedService(const std::string &name, const char *format, const char *desc)
51 : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, (void*)NULL, 0)
52 {
53 fServices.insert(getName());
54 setQuality(0);
55 // FIXME: compare number of ; with number of |
56 }
57
58 ~DimDescribedService()
59 {
60 fServices.erase(getName());
61 }
62
63 static const std::set<std::string> &GetServices() { return fServices; }
64
65 void setData(const void *ptr, size_t sz)
66 {
67 DimService::setData(const_cast<void*>(ptr), sz);
68 }
69
70 template<class T>
71 void setData(const T &data)
72 {
73 setData(&data, sizeof(T));
74 }
75
76 template<typename T>
77 void setData(const std::vector<T> &data)
78 {
79 setData(data.data(), data.size()*sizeof(T));
80 }
81
82 template<class T, size_t N>
83 void setData(const std::array<T, N> &data)
84 {
85 setData(data.data(), N*sizeof(T));
86 }
87
88 void setTime(const Time &t);
89 void setTime();
90
91 int Update();
92 int Update(const Time &t);
93 int Update(const std::string &data);
94 int Update(const char *data);
95
96 template<class T>
97 int Update(const T &data)
98 {
99 setData(&data, sizeof(T));
100 return Update();
101 }
102
103 template<typename T>
104 int Update(const std::vector<T> &data)
105 {
106 setData(data);
107 return Update();
108 }
109
110 template<class T, size_t N>
111 int Update(const std::array<T, N> &data)
112 {
113 setData(data);
114 return Update();
115 }
116
117 // FIXME: Implement callback with boost::function instead of Pointer to this
118};
119
120#endif
Note: See TracBrowser for help on using the repository browser.