binportable.h
来自「一个语言识别引擎」· C头文件 代码 · 共 60 行
H
60 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
/*
* Copyright (C) 2006 Paul Fitzpatrick
* CopyPolicy: Released under the terms of the GNU GPL v2.0.
*
*/
#ifndef _YARP2_BINPORTABLE_
#define _YARP2_BINPORTABLE_
#include <yarp/os/Portable.h>
namespace yarp {
namespace os {
template <class T> class BinPortable;
}
}
/**
* \ingroup comm_class
*
* Class for writing and reading simple binary structures.
* Can be used in conjunction with the Port class to send data
* across the network.
* Don't use this for anything containing a pointer,
* or which needs to be portable across different compilers,
* languages, operating systems, or processor architectures.
*/
template <class T>
class yarp::os::BinPortable : public Portable {
private:
T t;
public:
/**
* Get the internal structure that will be read or written.
* @return the internal structure that will be read or written.
*/
T& content() {
return t;
}
virtual bool read(ConnectionReader& connection) {
// An exception will get thrown upon error.
// Pending: translate this in expectBlock to a return value.
connection.expectBlock((char*)(&t),sizeof(T));
return true;
}
virtual bool write(ConnectionWriter& connection) {
connection.appendBlock((char*)(&t),sizeof(T));
return true;
}
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?