Ardour  9.2-70-g6916ee188f
private.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 The gtkmm Development Team
3  * Copyright (C) 2026 Robin Gareus <robin@gareus.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 
20 #pragma once
21 
22 #include <glib.h>
23 
24 #include "pbd/libpbd_visibility.h"
25 
26 namespace PBD
27 {
28 
29 template <class T>
31 {
32 public:
33  typedef void (*DestructorFunc) (void*);
34 
36  static void delete_ptr (void* data)
37  {
38  delete static_cast<T*> (data);
39  }
40 
47  explicit inline Private (DestructorFunc destructor_func = &Private<T>::delete_ptr)
48  {
49  const GPrivate temp = G_PRIVATE_INIT (destructor_func);
50  _gobjext = temp;
51  }
52 
57  inline T* get ()
58  {
59  return static_cast<T*> (g_private_get (&_gobjext));
60  }
61 
64  inline void set (T* data)
65  {
66  g_private_set (&_gobjext, data);
67  }
68 
76  inline void replace (T* data)
77  {
78  g_private_replace (&_gobjext, data);
79  }
80 
81 private:
82  Private (Private<T> const&) = delete;
83  Private<T>& operator= (Private<T> const&) = delete;
84 
85  GPrivate _gobjext;
86 };
87 
88 } // namespace PBD
static void delete_ptr(void *data)
Definition: private.h:36
void replace(T *data)
Definition: private.h:76
GPrivate _gobjext
Definition: private.h:85
Private(DestructorFunc destructor_func=&Private< T >::delete_ptr)
Definition: private.h:47
Private(Private< T > const &)=delete
T * get()
Definition: private.h:57
void set(T *data)
Definition: private.h:64
#define LIBPBD_API
Definition: axis_view.h:42