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

Last change on this file since 13212 was 11837, checked in by tbretz, 13 years ago
Changed Dim services to ensure they send the time.
File size: 2.5 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 }
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
Note: See TracBrowser for help on using the repository browser.