zoukankan      html  css  js  c++  java
  • C++ streambuf用法

    class LogStreamBuf : public std::streambuf {
      public:
      // REQUIREMENTS: "len" must be >= 2 to account for the '
    ' and '
    '.
      LogStreamBuf(char *buf, int len) {
        setp(buf, buf + len - 2);
      }
      // This effectively ignores overflow.
      virtual int_type overflow(int_type ch) {
        return ch;
      }
    
      // Legacy public ostrstream method.
      size_t pcount() const { return pptr() - pbase(); }
      char* pbase() const { return std::streambuf::pbase(); }
    };
    class LogStream : public std::ostream {
       public:
          LogStream(char *buf, int len, int ctr)
              : std::ostream(NULL),
                streambuf_(buf, len),
                ctr_(ctr),
                self_(this) { rdbuf(&streambuf_);}
    
          int ctr() const { return ctr_; }
          void set_ctr(int ctr) { ctr_ = ctr; }
          LogStream* self() const { return self_; }
    
          // Legacy std::streambuf methods.
          size_t pcount() const { return streambuf_.pcount(); }
          char* pbase() const { return streambuf_.pbase(); }
          char* str() const { return pbase(); }
    
      private:
          base_logging::LogStreamBuf streambuf_;
          int ctr_;  // Counter hack (for the LOG_EVERY_X() macro)
          LogStream *self_;  // Consistency check hack
      };
  • 相关阅读:
    my15_ mysql binlog格式从mixed修改为row格式
    my14_mysql指定时间恢复之模拟从库
    my13_mysql xtrabackup备份的时间点
    必知必会的图论算法
    leetcde37. Sudoku Solver
    leetcode36. Valid Sudoku
    leetcode52. N-Queens II
    leetcode51. N-Queens
    First Missing Positive
    Maximum Gap
  • 原文地址:https://www.cnblogs.com/457220157-FTD/p/4208849.html
Copyright © 2011-2022 走看看