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

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