FACT++  1.0
DimDescriptionService.h
Go to the documentation of this file.
1 #ifndef FACT_DimDescriptionService
2 #define FACT_DimDescriptionService
3 
4 #include <set>
5 #include <array>
6 #include <string>
7 #include <vector>
8 
9 class Time;
10 class DimService;
11 
13 {
14  static int fCount;
15  static DimService *fService;
16  static std::string fData;
17 
18  std::string fDescription;
19 
20 public:
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 
30 {
31  static std::set<std::string> fServices;
32 
33 public:
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 
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  void setData(const char *str)
71  {
72  DimService::setData(const_cast<char*>(str));
73  }
74 
75  void setData(const std::string &str)
76  {
77  setData(str.data());
78  }
79 
80  template<class T>
81  void setData(const T &data)
82  {
83  setData(&data, sizeof(T));
84  }
85 
86  template<typename T>
87  void setData(const std::vector<T> &data)
88  {
89  setData(data.data(), data.size()*sizeof(T));
90  }
91 
92  template<class T, size_t N>
93  void setData(const std::array<T, N> &data)
94  {
95  setData(data.data(), N*sizeof(T));
96  }
97 
98  void setTime(const Time &t);
99  void setTime();
100 
101  int Update();
102  int Update(const Time &t);
103  int Update(const std::string &data);
104  int Update(const char *data);
105 
106  template<class T>
107  int Update(const T &data)
108  {
109  setData(&data, sizeof(T));
110  return Update();
111  }
112 
113  template<typename T>
114  int Update(const std::vector<T> &data)
115  {
116  setData(data);
117  return Update();
118  }
119 
120  template<class T, size_t N>
121  int Update(const std::array<T, N> &data)
122  {
123  setData(data);
124  return Update();
125  }
126 
127  // FIXME: Implement callback with boost::function instead of Pointer to this
128 };
129 
130 #endif
int Update(const std::array< T, N > &data)
DimDescribedService(const std::string &name, const char *format, const T &val, const char *desc)
static const std::set< std::string > & GetServices()
DimDescribedService(const std::string &name, const T &val, const char *desc)
void setData(const std::string &str)
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
static DimService * fService
Counter to count the number of instatiations.
void setData(const std::vector< T > &data)
int Update(const T &data)
void setData(const std::array< T, N > &data)
void setData(const char *str)
A DimService which broadcasts descriptions for services and commands.
void setData(const T &data)
int Update(const std::vector< T > &data)
DimDescriptionService(const std::string &name, const std::string &format)
Local storage for the applied description.
void setData(const void *ptr, size_t sz)
std::string fDescription
Data to be distributed with the service.
void setData(void *data, int size)
Definition: discpp.cxx:1270
float data[4 *1440]
TT t
Definition: test_client.c:26
static std::set< std::string > fServices
static std::string fData
Pointer to the DimService distributing the desscriptions.
DimDescribedService(const std::string &name, const char *format, const char *desc)
std::string GetDescription() const