1 | #ifndef FACT_DimDescriptionService
|
---|
2 | #define FACT_DimDescriptionService
|
---|
3 |
|
---|
4 | #include <array>
|
---|
5 | #include <string>
|
---|
6 | #include <vector>
|
---|
7 |
|
---|
8 | class Time;
|
---|
9 | class DimService;
|
---|
10 |
|
---|
11 | class 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 |
|
---|
19 | public:
|
---|
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 |
|
---|
28 | class DimDescribedService : public DimDescriptionService, public DimService
|
---|
29 | {
|
---|
30 | public:
|
---|
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 | }
|
---|
36 |
|
---|
37 | template<typename T>
|
---|
38 | DimDescribedService(const std::string &name, const char *format, const T &val, const char *desc)
|
---|
39 | : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, const_cast<T*>(&val), sizeof(T))
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | DimDescribedService(const std::string &name, const char *format, const char *desc)
|
---|
44 | : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, (void*)NULL, 0)
|
---|
45 | {
|
---|
46 | // FIXME: compare number of ; with number of |
|
---|
47 | }
|
---|
48 |
|
---|
49 | void setData(const void *ptr, size_t sz)
|
---|
50 | {
|
---|
51 | DimService::setData(const_cast<void*>(ptr), sz);
|
---|
52 | }
|
---|
53 |
|
---|
54 | template<typename T>
|
---|
55 | void setData(const std::vector<T> &data)
|
---|
56 | {
|
---|
57 | setData(data.data(), data.size()*sizeof(T));
|
---|
58 | }
|
---|
59 |
|
---|
60 | template<class T, size_t N>
|
---|
61 | void setData(const std::array<T, N> &data)
|
---|
62 | {
|
---|
63 | setData(data.data(), N*sizeof(T));
|
---|
64 | }
|
---|
65 |
|
---|
66 | void setTime(const Time &t);
|
---|
67 | void setTime();
|
---|
68 |
|
---|
69 | int Update();
|
---|
70 | int Update(const Time &t);
|
---|
71 | int Update(const std::string &data);
|
---|
72 | int Update(const char *data);
|
---|
73 |
|
---|
74 | template<class T>
|
---|
75 | int Update(const T &data)
|
---|
76 | {
|
---|
77 | setData(&data, sizeof(T));
|
---|
78 | return Update();
|
---|
79 | }
|
---|
80 |
|
---|
81 | template<typename T>
|
---|
82 | int Update(const std::vector<T> &data)
|
---|
83 | {
|
---|
84 | setData(data);
|
---|
85 | return Update();
|
---|
86 | }
|
---|
87 |
|
---|
88 | template<class T, size_t N>
|
---|
89 | int Update(const std::array<T, N> &data)
|
---|
90 | {
|
---|
91 | setData(data);
|
---|
92 | return Update();
|
---|
93 | }
|
---|
94 |
|
---|
95 | // FIXME: Implement callback with boost::function instead of Pointer to this
|
---|
96 | };
|
---|
97 |
|
---|
98 | #endif
|
---|