1 | #ifndef FACT_DimDescriptionService
|
---|
2 | #define FACT_DimDescriptionService
|
---|
3 |
|
---|
4 | #include <string>
|
---|
5 | #include <vector>
|
---|
6 |
|
---|
7 | class DimService;
|
---|
8 |
|
---|
9 | class DimDescriptionService
|
---|
10 | {
|
---|
11 | static int fCount; /// Counter to count the number of instatiations
|
---|
12 | static DimService *fService; /// Pointer to the DimService distributing the desscriptions
|
---|
13 | static std::string fData; /// Data to be distributed with the service
|
---|
14 |
|
---|
15 | std::string fDescription; /// Local storage for the applied description
|
---|
16 |
|
---|
17 | public:
|
---|
18 | DimDescriptionService(const std::string &name, const std::string &format);
|
---|
19 | virtual ~DimDescriptionService();
|
---|
20 |
|
---|
21 | std::string GetDescription() const { return fDescription; }
|
---|
22 | };
|
---|
23 |
|
---|
24 | #include "dis.hxx"
|
---|
25 |
|
---|
26 | class DimDescribedService : public DimDescriptionService, public DimService
|
---|
27 | {
|
---|
28 | public:
|
---|
29 | template<typename T>
|
---|
30 | DimDescribedService(const std::string &name, const T &val, const char *desc)
|
---|
31 | : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), const_cast<T&>(val))
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 | template<typename T>
|
---|
36 | DimDescribedService(const std::string &name, const char *format, const T &val, const char *desc)
|
---|
37 | : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, const_cast<T*>(&val), sizeof(T))
|
---|
38 | {
|
---|
39 | }
|
---|
40 |
|
---|
41 | DimDescribedService(const std::string &name, const char *format, const char *desc)
|
---|
42 | : DimDescriptionService(name.c_str(), desc), DimService(name.c_str(), format, (void*)NULL, 0)
|
---|
43 | {
|
---|
44 | // FIXME: compare number of ; with number of |
|
---|
45 | }
|
---|
46 |
|
---|
47 | template<class T>
|
---|
48 | void Update(const T &data)
|
---|
49 | {
|
---|
50 | //cout << "Update: " << svc.getName() << " (" << sizeof(T) << ")" << endl;
|
---|
51 | setData(const_cast<T*>(&data), sizeof(T));
|
---|
52 | updateService();
|
---|
53 | }
|
---|
54 |
|
---|
55 | template<typename T>
|
---|
56 | void Update(const std::vector<T> &data)
|
---|
57 | {
|
---|
58 | //std::cout << "Update: " << getName() << " " << data.size() << " " << sizeof(T) << std::endl;
|
---|
59 | setData(const_cast<T*>(data.data()), data.size()*sizeof(T));
|
---|
60 | updateService();
|
---|
61 | }
|
---|
62 |
|
---|
63 | // FIXME: Implement callback with boost::function instead of Pointer to this
|
---|
64 |
|
---|
65 | };
|
---|
66 |
|
---|
67 | #endif
|
---|