// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2011 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Tim Penhey
* Marco Trevisan (TreviƱo) <3v1n0@ubuntu.com>
*/
#ifndef UNITY_GLIB_WRAPPER_H
#define UNITY_GLIB_WRAPPER_H
#include
#include
#include
#include
#include
namespace unity
{
namespace glib
{
struct AddRef{};
template
class Object
{
public:
Object();
explicit Object(T* val);
Object(T* val, AddRef const& ref);
Object(Object const&);
~Object();
void swap(Object& other);
Object& operator=(T* val);
Object& operator=(Object other);
operator T* () const;
operator bool() const;
T* operator->() const;
T* RawPtr() const;
// Release ownership of the object. No unref will occur.
T* Release();
bool IsType(GType type) const;
private:
T* object_;
};
template
bool operator==(Object const& lhs, Object const& rhs)
{
return (lhs.RawPtr() == rhs.RawPtr());
}
template
bool operator!=(Object const& lhs, Object const& rhs)
{
return !(lhs == rhs);
}
template
bool operator!=(T* lhs, Object const& rhs)
{
return !(lhs == rhs.RawPtr());
}
template
Object object_cast(Object const& obj)
{
return Object(reinterpret_cast(obj.RawPtr()), AddRef());
}
class Error : boost::noncopyable
{
public:
Error();
~Error();
GError** AsOutParam();
GError** operator&();
operator GError*();
operator bool() const;
std::string Message() const;
private:
GError* error_;
};
class String : boost::noncopyable
{
public:
String();
explicit String(gchar* str);
~String();
gchar** AsOutParam();
gchar** operator&();
operator bool() const;
operator char*();
operator std::string();
gchar* Value();
std::string Str() const;
private:
gchar* string_;
};
std::ostream& operator<<(std::ostream& o, Error const& e);
std::ostream& operator<<(std::ostream& o, String const& s);
}
}
namespace std
{
template
void swap (unity::glib::Object& lhs, unity::glib::Object& rhs)
{
lhs.swap(rhs);
}
}
#include "GLibWrapper-inl.h"
#endif