Introduce some utilities for C++

red::add_ref will be used to increment a reference counter
and return the object pointer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-03-10 02:52:40 +00:00 committed by Frediano Ziglio
parent 77af39d6b5
commit 3a05720eaa
3 changed files with 39 additions and 0 deletions

View File

@ -96,6 +96,7 @@ libserver_la_SOURCES = \
cursor-channel-client.cpp \
cursor-channel-client.h \
cursor-channel.h \
utils.hpp \
dcc.cpp \
dcc.h \
dcc-private.h \

View File

@ -56,6 +56,7 @@ spice_server_sources = [
'cursor-channel-client.cpp',
'cursor-channel-client.h',
'cursor-channel.h',
'utils.hpp',
'dcc.cpp',
'dcc.h',
'dcc-private.h',

37
server/utils.hpp Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright (C) 2019 Red Hat, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/* Generic utilities for C++
*/
#pragma once
#include <memory>
namespace red {
template <typename T>
inline T* add_ref(T* p)
{
if (p) {
p->ref();
}
return p;
}
} // namespace red