source: trunk/FACT++/src/Dim.h@ 12540

Last change on this file since 12540 was 11484, checked in by tbretz, 13 years ago
Added a specialized template of SendCommand, suitable to send a string
File size: 1.9 KB
Line 
1#ifndef FACT_Dim
2#define FACT_Dim
3
4#include "DimSetup.h"
5
6#include <string>
7
8#include "dic.hxx"
9
10namespace Dim
11{
12 // --------------------------------------------------------------------------
13 //
14 //! Simplification wrapper to send a command without data
15 //!
16 //! Example:
17 //! - Dim::SendCommand("SERVER/COMMAND");
18 //!
19 //! @param command
20 //! Dim command identifier
21 //!
22 //! @returns
23 //! the return value of DimClient::sendCommand
24 //!
25 inline bool SendCommand(const std::string &command)
26 {
27 return DimClient::sendCommand(command.c_str(), NULL, 0);
28 }
29
30 // --------------------------------------------------------------------------
31 //
32 //! Simplification wrapper to send a command with the given data
33 //!
34 //! Example:
35 //! - Dim::SendCommand("SERVER/COMMAND", uint16_t(42));
36 //! - struct tm t; Dim::SendCommand("SERVER/TIME", t);
37 //!
38 //! @param command
39 //! Dim command identifier
40 //!
41 //! @param t
42 //! object to be sent, the pointer to the data to be sent is
43 //! set to &t
44 //!
45 //! @tparam T
46 //! type of the data to be sent. The size of the data to be sent
47 //! is determined as sizeof(T)
48 //!
49 //! @returns
50 //! the return value of DimClient::sendCommand
51 //!
52 template<typename T>
53 inline bool SendCommand(const std::string &command, const T &t)
54 {
55 return DimClient::sendCommand(command.c_str(), const_cast<T*>(&t), sizeof(t));
56 }
57
58 template<>
59 inline bool SendCommand(const std::string &command, const std::string &t)
60 {
61 return DimClient::sendCommand(command.c_str(), const_cast<char*>(t.c_str()), t.length()+1);
62 }
63
64 inline bool SendCommand(const std::string &command, const void *d, size_t s)
65 {
66 return DimClient::sendCommand(command.c_str(), const_cast<void*>(d), s);
67 }
68}
69
70#endif
Note: See TracBrowser for help on using the repository browser.