Nemiver  0.3
nmv-safe-ptr-utils.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4-*- */
2 
3 /*Copyright (c) 2005-2014 Dodji Seketeli
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS",
17  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE
19  * WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE
21  * AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23  * HOLDERS BE LIABLE FOR ANY CLAIM,
24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25  * CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
27  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29  */
30 #ifndef __NMV_SAFE_PTR_UTILS_H__
31 #define __NMV_SAFE_PTR_UTILS_H__
32 
33 #include <glib-object.h>
34 #include "nmv-object.h"
35 #include "nmv-safe-ptr.h"
36 #include "nmv-namespace.h"
37 
38 NEMIVER_BEGIN_NAMESPACE (nemiver)
39 NEMIVER_BEGIN_NAMESPACE (common)
40 
41 //*******************************
42 //misc functors
43 //*******************************
44 
45 struct ObjectRef {
46 
47  void
48  operator () (nemiver::common::Object* a_ptr)
49  {
50  if (a_ptr)
51  a_ptr->ref ();
52  }
53 };//end ObjectRef
54 
55 struct ObjectUnref {
56 
57  void
58  operator () (nemiver::common::Object* a_ptr)
59  {
60  if (a_ptr) {a_ptr->unref ();}
61  }
62 };//end ObjectUnRef
63 
64 struct GCharRef {
65  void
66  operator () (gchar* a_ptr) {if (a_ptr){}}
67 };
68 
69 struct GCharUnref {
70  bool
71  operator () (gchar* a_ptr)
72  {
73  if (a_ptr) {
74  g_free (a_ptr);
75  return true;
76  }
77  return true;
78  }
79 };
80 
81 struct CharsRef {
82  void operator () (gchar *a_tab) {if (a_tab){}}
83 };//end struct CharTabRef
84 
85 struct DelCharsUnref {
86  void operator () (gchar *a_tab)
87  {
88  delete [] a_tab;
89  }
90 };//end struct CharTabUnref
91 
92 struct UnicharsRef {
93  void operator () (gunichar *a_tab) {if (a_tab) {}}
94 };
96  void operator () (gunichar *a_tab)
97  {
98  delete [] a_tab;
99  }
100 };
101 
102 struct GErrorRef {
103  void
104  operator () (GError *)
105  {}
106 };
107 
108 struct GErrorUnref {
109  void
110  operator () (GError *a_error)
111  {
112  if (a_error) {
113  g_error_free (a_error);
114  }
115  }
116 };
117 
119  void operator () (void *a_object)
120  {
121  if (a_object && G_IS_OBJECT (a_object)) {
122  g_object_ref (G_OBJECT (a_object));
123  }
124  }
125 };
126 
128  void operator () (void *a_object)
129  {
130  if (a_object && G_IS_OBJECT (a_object)) {
131  g_object_unref (G_OBJECT (a_object));
132  }
133  }
134 };
135 
141 typedef SafePtr<void*,
144 
145 NEMIVER_END_NAMESPACE(common)
146 NEMIVER_END_NAMESPACE(nemiver)
147 
148 #endif
nemiver::common::GErrorSafePtr
SafePtr< GError, GErrorRef, GErrorUnref > GErrorSafePtr
Definition: nmv-safe-ptr-utils.h:140
nemiver::common::Object
Definition: nmv-object.h:43
nemiver::common::DelUnicharsUnref
Definition: nmv-safe-ptr-utils.h:95
nemiver
Definition: nmv-address.h:31
nemiver::common::ObjectRef
Definition: nmv-safe-ptr-utils.h:45
nmv-safe-ptr.h
nemiver::common::CharSafePtr
SafePtr< gchar, CharsRef, DelCharsUnref > CharSafePtr
Definition: nmv-safe-ptr-utils.h:138
nemiver::common::Object::unref
void unref()
nemiver::common::NativeGObjectSafePtr
SafePtr< void *, RefGObjectNative, UnrefGObjectNative > NativeGObjectSafePtr
Definition: nmv-safe-ptr-utils.h:143
nemiver::common::CharsRef
Definition: nmv-safe-ptr-utils.h:81
nemiver::common::GCharRef
Definition: nmv-safe-ptr-utils.h:64
nemiver::common::GErrorUnref
Definition: nmv-safe-ptr-utils.h:108
nemiver::common::UnicharSafePtr
SafePtr< gunichar, UnicharsRef, DelUnicharsUnref > UnicharSafePtr
Definition: nmv-safe-ptr-utils.h:139
nemiver::common::ObjectSafePtr
SafePtr< Object, ObjectRef, ObjectUnref > ObjectSafePtr
Definition: nmv-safe-ptr-utils.h:137
nemiver::common::UnicharsRef
Definition: nmv-safe-ptr-utils.h:92
nemiver::common::DelCharsUnref
Definition: nmv-safe-ptr-utils.h:85
nemiver::common::RefGObjectNative
Definition: nmv-safe-ptr-utils.h:118
nemiver::common::GErrorRef
Definition: nmv-safe-ptr-utils.h:102
nemiver::common::GCharUnref
Definition: nmv-safe-ptr-utils.h:69
nemiver::common::ObjectUnref
Definition: nmv-safe-ptr-utils.h:55
nmv-object.h
nmv-namespace.h
nemiver::common::SafePtr
Definition: nmv-safe-ptr.h:71
nemiver::common::GCharSafePtr
SafePtr< gchar, CharsRef, GCharUnref > GCharSafePtr
Definition: nmv-safe-ptr-utils.h:136
common
Definition: nmv-proc-list-dialog.h:32
nemiver::common::UnrefGObjectNative
Definition: nmv-safe-ptr-utils.h:127
nemiver::common::Object::ref
void ref()