项目作者: datcxx

项目描述 :
A push-stream implementation
高级语言: C++
项目地址: git://github.com/datcxx/push-stream.git
创建时间: 2019-08-16T11:36:06Z
项目社区:https://github.com/datcxx/push-stream

开源协议:

下载


SYNOPSIS

push-stream is a streams implementation based on this streams spec. There
is a minimal base-class that implements pipe and adds placeholders for typical
properties and methods that will be used in implementing the usual Source,
Sink, Through and Duplex streams.

The base class overloads the | operator to improve readability, ie you can do
this…

  1. int main () {
  2. // ...
  3. source | through | sink;
  4. return 0;
  5. }

USAGE

This module is designed to work with the datcxx build tool. To add this
module to your project us the following command…

  1. build add datcxx/push-stream

TEST

  1. build test

EXAMPLES

SOURCE EXAMPLE

  1. struct Source : Stream {
  2. Buffer buf { "paper", "clips", "for", "sale" };
  3. size_t i = 0;
  4. bool resume () override {
  5. if(!this->hasSink || this->ended) {
  6. return false;
  7. }
  8. while (!this->sink->paused && i < buf.size()) {
  9. auto s = buf[i++];
  10. this->sink->write(s);
  11. }
  12. if (i == buf.size()) {
  13. this->sink->end();
  14. }
  15. return true;
  16. }
  17. void pipe () override {
  18. this->resume();
  19. }
  20. };

SINK EXAMPLE

  1. struct Sink : Stream {
  2. bool end () override {
  3. this->ended = true;
  4. return true;
  5. }
  6. int write (const std::any& data) override {
  7. cout << std::any_cast<String>(data);
  8. return str.size();
  9. }
  10. };