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

Last change on this file since 19353 was 16482, checked in by tbretz, 12 years ago
Added setData for const char* and for string
File size: 3.2 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 void setData(const char *str)
71 {
72 DimService::setData(const_cast<char*>(str));
73 }
74
75 void setData(const std::string &str)
76 {
77 setData(str.data());
78 }
79
80 template<class T>
81 void setData(const T &data)
82 {
83 setData(&data, sizeof(T));
84 }
85
86 template<typename T>
87 void setData(const std::vector<T> &data)
88 {
89 setData(data.data(), data.size()*sizeof(T));
90 }
91
92 template<class T, size_t N>
93 void setData(const std::array<T, N> &data)
94 {
95 setData(data.data(), N*sizeof(T));
96 }
97
98 void setTime(const Time &t);
99 void setTime();
100
101 int Update();
102 int Update(const Time &t);
103 int Update(const std::string &data);
104 int Update(const char *data);
105
106 template<class T>
107 int Update(const T &data)
108 {
109 setData(&data, sizeof(T));
110 return Update();
111 }
112
113 template<typename T>
114 int Update(const std::vector<T> &data)
115 {
116 setData(data);
117 return Update();
118 }
119
120 template<class T, size_t N>
121 int Update(const std::array<T, N> &data)
122 {
123 setData(data);
124 return Update();
125 }
126
127 // FIXME: Implement callback with boost::function instead of Pointer to this
128};
129
130#endif
Note: See TracBrowser for help on using the repository browser.