#ifndef ucoo_utils_buffer_tcc #define ucoo_utils_buffer_tcc // buffer.tcc // {{{ // // Copyright (C) 2016 Nicolas Schodet // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // Contact : // Web: http://ni.fr.eu.org/ // Email: // }}} #include namespace ucoo { template Buffer::Buffer () : begin_ (data_), end_ (data_) { } template bool Buffer::empty () const { return begin_ == end_; } template bool Buffer::full () const { return end_ == &data_[max_size]; } template int Buffer::size () const { return end_ - begin_; } template int Buffer::room () const { return &data_[max_size] - end_; } template const T * Buffer::read () const { return begin_; } template void Buffer::drop (int n) { begin_ += n; if (empty ()) begin_ = end_ = &data_[0]; } template const T * Buffer::read (int n) { drop (n); return read (); } template T * Buffer::write () { return end_; } template void Buffer::written (int n) { end_ += n; } template T * Buffer::write (int n) { T *r = write (); written (n); return r; } template void Buffer::rewind () { if (begin_ != &data_[0]) { std::copy (begin_, end_, &data_[0]); end_ -= begin_ - &data_[0]; begin_ = &data_[0]; } } } // namespace ucoo #endif // ucoo_utils_buffer_tcc