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

Last change on this file since 16388 was 15168, checked in by tbretz, 12 years ago
Store a global set of all described services.
File size: 2.9 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<typename T>
71 void setData(const std::vector<T> &data)
72 {
73 setData(data.data(), data.size()*sizeof(T));
74 }
75
76 template<class T, size_t N>
77 void setData(const std::array<T, N> &data)
78 {
79 setData(data.data(), N*sizeof(T));
80 }
81
82 void setTime(const Time &t);
83 void setTime();
84
85 int Update();
86 int Update(const Time &t);
87 int Update(const std::string &data);
88 int Update(const char *data);
89
90 template<class T>
91 int Update(const T &data)
92 {
93 setData(&data, sizeof(T));
94 return Update();
95 }
96
97 template<typename T>
98 int Update(const std::vector<T> &data)
99 {
100 setData(data);
101 return Update();
102 }
103
104 template<class T, size_t N>
105 int Update(const std::array<T, N> &data)
106 {
107 setData(data);
108 return Update();
109 }
110
111 // FIXME: Implement callback with boost::function instead of Pointer to this
112};
113
114#endif
Note: See TracBrowser for help on using the repository browser.