Back to index

unity  6.0.0
GLibWrapper-inl.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003 * Copyright (C) 2011 Canonical Ltd
00004 *
00005 * This program is free software: you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License version 3 as
00007 * published by the Free Software Foundation.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 *
00017 * Authored by: Tim Penhey <tim.penhey@canonical.com>
00018 *              Marco Trevisan (TreviƱo) <3v1n0@ubuntu.com>
00019 */
00020 
00021 #ifndef UNITY_GLIB_WRAPPER_INL_H
00022 #define UNITY_GLIB_WRAPPER_INL_H
00023 
00024 namespace unity
00025 {
00026 namespace glib
00027 {
00028 
00029 template <typename T>
00030 Object<T>::Object()
00031   : object_(0)
00032 {}
00033 
00034 template <typename T>
00035 Object<T>::Object(T* val)
00036   : object_(val)
00037 {}
00038 
00039 template <typename T>
00040 Object<T>::Object(T* val, AddRef const& ref)
00041   : object_(val)
00042 {
00043   if (object_)
00044     g_object_ref(object_);
00045 }
00046 
00047 template <typename T>
00048 Object<T>::Object(Object const& other)
00049   : object_(other.object_)
00050 {
00051   if (object_)
00052     g_object_ref(object_);
00053 }
00054 
00055 template <typename T>
00056 Object<T>::~Object()
00057 {
00058   if (object_)
00059     g_object_unref(object_);
00060 }
00061 
00062 template <typename T>
00063 void Object<T>::swap(Object<T>& other)
00064 {
00065   std::swap(this->object_, other.object_);
00066 }
00067 
00068 template <typename T>
00069 Object<T>& Object<T>::operator=(T* val)
00070 {
00071   Object<T> copy(val);
00072   swap(copy);
00073 
00074   return *this;
00075 }
00076 
00077 template <typename T>
00078 Object<T>& Object<T>::operator=(Object other)
00079 {
00080   swap(other);
00081   return *this;
00082 }
00083 
00084 template <typename T>
00085 Object<T>::operator T* () const
00086 {
00087   return object_;
00088 }
00089 
00090 template <typename T>
00091 T* Object<T>::operator->() const
00092 {
00093   return object_;
00094 }
00095 
00096 template <typename T>
00097 Object<T>::operator bool() const
00098 {
00099   return bool(object_);
00100 }
00101 
00102 template <typename T>
00103 T* Object<T>::RawPtr() const
00104 {
00105   return object_;
00106 }
00107 
00108 template <typename T>
00109 T* Object<T>::Release()
00110 {
00111   T* result = object_;
00112   object_ = 0;
00113   return result;
00114 }
00115 
00116 
00117 }
00118 }
00119 
00120 #endif