class LogStreamBuf : public std::streambuf {
  public:
  // REQUIREMENTS: "len" must be >= 2 to account for the '\n' and '\n'.
  LogStreamBuf(char *buf, int len) {
    setp(buf, buf + len - );
  }
  // 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
};

C++ streambuf用法的更多相关文章

  1. C++中cin的用法汇总

    cin可以用于接收输入,最常见的是从控制台接收.在刚学习C++的时候经常会用cin来接收数据,这里想要系统的总结一下cin的用法,保证不灌水. C++中的cin是一个 istream对象,从标准输入中 ...

  2. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  3. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  4. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  5. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  6. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  7. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  8. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  9. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

随机推荐

  1. CentOS安装apache2(转载)

    From:http://www.onepx.com/centos-apache-246.html 之前服务器 Apache 版本一直是 2.2.x,鉴于 Centos 更新软件的惰性,我看直到 201 ...

  2. Yii2.0高级框架数据库增删改查的一些操作

    yii2.0框架是PHP开发的一个比较高效率的框架,集合了作者的大量心血,下面通过用户为例给大家详解yii2.0高级框架数据库增删改查的一些操作 --------------------------- ...

  3. label 行距

    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:te ...

  4. flask test_client设置cookies

    class TestCase(unittest.TestCase): session = None def setUp(self): self.app = create_app() self.app. ...

  5. (easy)LeetCode 237.Delete Node in a Linked List

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  6. Python访问私有变量

    代码: class Counter(object): __secount=0 publicfs=0 def getcount(self): self.__secount+=1 self.publicf ...

  7. 阿里RDS备份恢复

    未使用root用户操作: 数据库版本要一致 数据目录:/data/mysqlbak/ 先按阿里给的步骤操作,最后出现一步出现,无法找到back_xxx.conf,但该文件已经存在.解决方法: sudo ...

  8. PetaPoco修改

    else if (type == typeof(decimal)) return (decimal)pk == default(decimal); public override void PreEx ...

  9. [VB.NET]拖动操作的技术基础

    1.设置需要接受拖动事件的控件的AllowDrop属性为True,在开发界面时配置,不可通过代码配置 2.在DragEnter事件处理程序里,为e.Effet设置枚举值,否则拖动无效 Private ...

  10. <%%>与<%#%>与<%=%>

    在asp.net中经常出现包含这种形式<%%>的html代码,总的来说包含下面这样几种格式: 一. <%%> 这种格式实际上就是和asp的用法一样的,只是asp中里面是vbsc ...