Line data Source code
1 :
2 : /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
3 : * 2012-2014, Stefan.Eilemann@epfl.ch
4 : *
5 : * This file is part of Collage <https://github.com/Eyescale/Collage>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #include "buffer.h"
22 : #include "bufferListener.h"
23 :
24 : namespace co
25 : {
26 : namespace detail
27 : {
28 : class Buffer
29 : {
30 : public:
31 558 : Buffer( BufferListener* listener_ )
32 : : listener( listener_ )
33 558 : , free( true )
34 558 : {}
35 :
36 : BufferListener* const listener;
37 : bool free;
38 : };
39 : }
40 :
41 558 : Buffer::Buffer( BufferListener* listener )
42 : : lunchbox::Bufferb()
43 : , lunchbox::Referenced()
44 558 : , _impl( new detail::Buffer( listener ))
45 : {
46 558 : }
47 :
48 1581 : Buffer::~Buffer()
49 : {
50 549 : delete _impl;
51 1032 : }
52 :
53 167695 : void Buffer::notifyFree()
54 : {
55 167695 : if( _impl->listener )
56 154064 : _impl->listener->notifyFree( this );
57 167695 : _impl->free = true;
58 167695 : }
59 :
60 183698 : bool Buffer::isFree() const
61 : {
62 183698 : return _impl->free;
63 : }
64 :
65 154065 : void Buffer::setUsed()
66 : {
67 154065 : _impl->free = false;
68 154065 : }
69 :
70 0 : std::ostream& operator << ( std::ostream& os, const Buffer& buffer )
71 : {
72 0 : os << lunchbox::disableFlush << "Buffer[" << buffer.getRefCount() << "@"
73 0 : << &buffer << "]";
74 0 : buffer.printHolders( os );
75 0 : return os << lunchbox::enableFlush;
76 : }
77 60 : }
|