MPD  0.20.15
Page.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
25 #ifndef MPD_PAGE_HXX
26 #define MPD_PAGE_HXX
27 
28 #include "util/RefCount.hxx"
29 
30 #include <stddef.h>
31 
37 class Page {
44  RefCount ref;
45 
46 public:
50  const size_t size;
51 
55  unsigned char data[sizeof(long)];
56 
57 protected:
58  Page(size_t _size):size(_size) {}
59  ~Page() = default;
60 
65  static Page *Create(size_t size);
66 
67 public:
76  static Page *Copy(const void *data, size_t size);
77 
84  static Page *Concat(const Page &a, const Page &b);
85 
89  void Ref() {
90  ref.Increment();
91  }
92 
99  bool Unref();
100 };
101 
102 #endif
void Increment()
Definition: RefCount.hxx:52
Page(size_t _size)
Definition: Page.hxx:58
unsigned char data[sizeof(long)]
Dynamic array containing the buffer data.
Definition: Page.hxx:55
static Page * Copy(const void *data, size_t size)
Creates a new #page object, and copies data from the specified buffer.
A very simple reference counting library.
~Page()=default
bool Unref()
Decreases the reference counter.
void Ref()
Increases the reference counter.
Definition: Page.hxx:89
static Page * Create(size_t size)
Allocates a new Page object, without filling the data element.
const size_t size
The size of this buffer in bytes.
Definition: Page.hxx:50
static Page * Concat(const Page &a, const Page &b)
Concatenates two pages to a new page.
A dynamically allocated buffer which keeps track of its reference count.
Definition: Page.hxx:37