source: branches/fscctrl_safety_limits/src/Dim.h@ 19166

Last change on this file since 19166 was 16777, checked in by tbretz, 11 years ago
Added the long awaited customized template for vector<T>
File size: 3.1 KB
Line 
1#ifndef FACT_Dim
2#define FACT_Dim
3
4#include "DimSetup.h"
5
6#include <string>
7#include <vector>
8
9#include "dic.hxx"
10
11namespace Dim
12{
13 // --------------------------------------------------------------------------
14 //
15 //! Simplification wrapper to send a command without data
16 //!
17 //! Example:
18 //! - Dim::SendCommand("SERVER/COMMAND");
19 //!
20 //! @param command
21 //! Dim command identifier
22 //!
23 //! @returns
24 //! the return value of DimClient::sendCommand
25 //!
26 inline bool SendCommand(const std::string &command)
27 {
28 return DimClient::sendCommand(command.c_str(), NULL, 0);
29 }
30 inline void SendCommandNB(const std::string &command)
31 {
32 DimClient::sendCommandNB(command.c_str(), NULL, 0);
33 }
34
35 // --------------------------------------------------------------------------
36 //
37 //! Simplification wrapper to send a command with the given data
38 //!
39 //! Example:
40 //! - Dim::SendCommand("SERVER/COMMAND", uint16_t(42));
41 //! - struct tm t; Dim::SendCommand("SERVER/TIME", t);
42 //!
43 //! @param command
44 //! Dim command identifier
45 //!
46 //! @param t
47 //! object to be sent, the pointer to the data to be sent is
48 //! set to &t
49 //!
50 //! @tparam T
51 //! type of the data to be sent. The size of the data to be sent
52 //! is determined as sizeof(T)
53 //!
54 //! @returns
55 //! the return value of DimClient::sendCommand
56 //!
57 template<typename T>
58 inline bool SendCommand(const std::string &command, const T &t)
59 {
60 return DimClient::sendCommand(command.c_str(), const_cast<T*>(&t), sizeof(t));
61 }
62
63 template<>
64 inline bool SendCommand(const std::string &command, const std::string &t)
65 {
66 return DimClient::sendCommand(command.c_str(), const_cast<char*>(t.c_str()), t.length()+1);
67 }
68
69 template<typename T>
70 inline bool SendCommand(const std::string &command, const std::vector<T> &v)
71 {
72 return DimClient::sendCommand(command.c_str(), const_cast<char*>(v.data()), v.size()*sizeof(T));
73 }
74
75 inline bool SendCommand(const std::string &command, const void *d, size_t s)
76 {
77 return DimClient::sendCommand(command.c_str(), const_cast<void*>(d), s);
78 }
79
80 // -------------------------------------------------------------------------
81
82 template<typename T>
83 inline void SendCommandNB(const std::string &command, const T &t)
84 {
85 DimClient::sendCommandNB(command.c_str(), const_cast<T*>(&t), sizeof(t));
86 }
87
88 template<>
89 inline void SendCommandNB(const std::string &command, const std::string &t)
90 {
91 DimClient::sendCommandNB(command.c_str(), const_cast<char*>(t.c_str()), t.length()+1);
92 }
93
94 template<typename T>
95 inline void SendCommandNB(const std::string &command, const std::vector<T> &v)
96 {
97 DimClient::sendCommandNB(command.c_str(), const_cast<T*>(v.data()), v.size()*sizeof(T));
98 }
99
100 inline void SendCommandNB(const std::string &command, const void *d, size_t s)
101 {
102 DimClient::sendCommandNB(command.c_str(), const_cast<void*>(d), s);
103 }
104}
105
106#endif
Note: See TracBrowser for help on using the repository browser.