48 lines
1006 B
C++
48 lines
1006 B
C++
/*
|
|
* IDataLink.h
|
|
*
|
|
* Created on: 13 ñåíò. 2018 ã.
|
|
* Author: titov
|
|
*/
|
|
|
|
#ifndef SOURCE_DRIVER_IDATALINK_H_
|
|
#define SOURCE_DRIVER_IDATALINK_H_
|
|
|
|
#include <cstddef>
|
|
|
|
namespace driver {
|
|
|
|
//! Èíòåðôåéñ ïåðåäà÷è äàííûõ.
|
|
class ITxLink {
|
|
public:
|
|
virtual bool send( const char * data, std::size_t size ) = 0;
|
|
template<typename T>
|
|
bool operator <<( const T & );
|
|
virtual ~ITxLink() {}
|
|
};
|
|
|
|
//! Èíòåðôåéñ ïðèåìàõ äàííûõ.
|
|
class IRxLink {
|
|
public:
|
|
virtual bool receive( char * data, std::size_t size ) = 0;
|
|
template<typename T>
|
|
bool operator >>( T & );
|
|
virtual ~IRxLink() {}
|
|
};
|
|
|
|
class IDataLink : public ITxLink, public IRxLink {};
|
|
|
|
}
|
|
|
|
template<typename T>
|
|
inline bool driver::ITxLink::operator <<( const T & data ) {
|
|
return send( reinterpret_cast<const char *>(&data), sizeof(data) );
|
|
}
|
|
|
|
template<typename T>
|
|
inline bool driver::IRxLink::operator >>( T & data ) {
|
|
return receive( reinterpret_cast<char *>(&data), sizeof(data) );
|
|
}
|
|
|
|
#endif /* SOURCE_DRIVER_IDATALINK_H_ */
|