2013-07-11 30 views
0

是否有可能爲更復雜/結構化的類型使用boost :: iostreams?使用boost :: stream更復雜/結構化類型,然後字符?

我想要做的就是流式傳輸的圖像,但他們應該有一些註解像寬度,高度,色彩深度,...我的第一個想法是使用結構,而不是一個字符或WCHAR的

namespace io = boost::iostreams; 

struct SingleImageStream{ 
    unsigned int width; 
    unsigned int height; 
    unsigned char colordepth; 
    unsigned char* frame; 
}; 


class SingleImageSource { 
public: 
    typedef struct SingleImageStream   char_type; 
    typedef io::source_tag category; 

    std::streamsize read(struct SingleImageStream* s, std::streamsize n) 
    { 
     char* frame = new char[640*480]; 
     std::fill(frame, frame + sizeof(frame), 0); 

     s->width = 640; 
     s->height = 480; 

     std::copy(frame, frame + sizeof(frame), s->frame); 

     return -1; 
    }  
}; 


class SingleImageSink { 
public: 
    typedef struct SingleImageStream  char_type; 
    typedef io::sink_tag     category; 

    std::streamsize write(const struct SingleImageStream* s, std::streamsize n) 
    { 
      std::cout << "Frame width : " << s->width << " frame height : " << s->height << std::endl; 
      return n; 
    }  
}; 

我現在的問題是如何連接源和接收器?

THX

回答

1

了Boost.Iostreams似乎是這裏的工作錯誤的工具。

源和匯機制的目標是允許您指定,其中數據被序列化爲 - 例如,您是要寫入文件,內存中的位置還是寫入I/O端口。

你想指定的是某種數據如何被序列化。 Boost中正確的工具是Boost.Serialization