File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -45,18 +45,22 @@ class cbuf {
4545 return _begin - _end - 1 ;
4646 }
4747
48- bool empty () const {
48+ inline bool empty () const {
4949 return _begin == _end;
5050 }
5151
52+ inline bool full () const {
53+ return wrap_if_bufend (_end + 1 ) == _begin;
54+ }
55+
5256 int peek () {
53- if (_end == _begin ) return -1 ;
57+ if (empty () ) return -1 ;
5458
5559 return static_cast <int >(*_begin);
5660 }
5761
5862 int read () {
59- if (getSize () == 0 ) return -1 ;
63+ if (empty () ) return -1 ;
6064
6165 char result = *_begin;
6266 _begin = wrap_if_bufend (_begin + 1 );
@@ -80,7 +84,7 @@ class cbuf {
8084 }
8185
8286 size_t write (char c) {
83- if (room () == 0 ) return 0 ;
87+ if (full () ) return 0 ;
8488
8589 *_end = c;
8690 _end = wrap_if_bufend (_end + 1 );
@@ -109,7 +113,7 @@ class cbuf {
109113 }
110114
111115 private:
112- inline char * wrap_if_bufend (char * ptr) {
116+ inline char * wrap_if_bufend (char * ptr) const {
113117 return (ptr == _bufend) ? _buf : ptr;
114118 }
115119
You can’t perform that action at this time.
0 commit comments