解析一个提升:元组成一个字符*(带有字节顺序)

时间:2013-04-23 15:26:21

标签: c++ templates c++11 boost-fusion boost-tuples

我有许多类,其私有成员boost::tuple<> structures的实现各不相同,即。 <std::string, int><short, short, float>。 我现在需要将该元组解析为私有const char* message(因为我想通过tcp发送它),但不能不改变那些需要更改其endianess的数据类型的endianess。

这就是我到目前为止所拥有的:

struct parseTuple{
    template<typename T>
    void operator()(T& t) const{
        std::cout << ntohl(t) << "\n";
    }
};

void Base::createMessageFromTuple(){
    boost::fusion::for_each(this->structure, parseTuple());
}

在我开始之前,我认为有一些事情我需要知道:

  1. 如何跟踪元组成员,以便根据数据类型为message分配空间(静态成员,可能?)

  2. 如何在适合ntohl要求的数据类型与需要不同处理的数据类型(即std::string

  3. 之间区分模板
  4. 这是否是正确的做法?

0 个答案:

没有答案
相关问题