// Generated by gtkmmproc -- DO NOT MODIFY!


#include <glibmm/variant.h>
#include <glibmm/private/variant_p.h>

/* Copyright 2010 The glibmm Development Team
 *
 * 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, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <glibmm/variant.h>
#include <glibmm/utility.h>
#include <glib.h>

namespace Glib
{

void VariantBase::get_normal_form(VariantBase& result) const
{
  GVariant* const g_value =
    g_variant_get_normal_form(const_cast<GVariant*>(gobj()));

  //The C function never returns NULL, according to its docuemenation,
  //so we don't need a bool return value.
  result.init(g_value); // g_value is already referenced.
}

void VariantBase::byteswap(VariantBase& result) const
{
  GVariant* const g_value = g_variant_byteswap(const_cast<GVariant*>(gobj()));
  result.init(g_value); // g_value is already referenced.
}

//static
void VariantStringBase::create_object_path(VariantStringBase& output,
  const std::string& object_path)
{
  GVariant* result = 0;
  result = g_variant_new_object_path(object_path.c_str());
  output.init(result);
}

//static
void VariantStringBase::create_signature(VariantStringBase& output,
  const std::string& signature)
{
  GVariant* result = 0;
  result = g_variant_new_signature(signature.c_str());
  output.init(result);
}

void VariantContainerBase::get(VariantBase& child, gsize index) const
{
  GVariant* const gvariant = g_variant_get_child_value(gobject_, index);
  child.init(gvariant);
}

bool VariantContainerBase::get_maybe(Glib::VariantBase& maybe) const
{
  GVariant* const g_value =
    g_variant_get_maybe(const_cast<GVariant*>(gobj()));

  if(g_value)
  {
    maybe.init(g_value); // g_value is already referenced.
    return true;
  }
  else
    return false;
}

/****************** Specializations ***********************************/

void VariantBase::init(const GVariant* cobject, bool take_a_reference)
{
  if(gobject_)
    g_variant_unref(gobject_);

  gobject_ = const_cast<GVariant*>(cobject);
  if(take_a_reference)
    g_variant_ref(gobject_);
}

// static
const VariantType& Variant<VariantBase>::variant_type()
{
  static VariantType type(G_VARIANT_TYPE_VARIANT);
  return type;
}

Variant<VariantBase> Variant<VariantBase>::create(const VariantBase& data)
{
  Variant<VariantBase> result = Variant<VariantBase>(g_variant_new_variant(const_cast<GVariant*>(data.gobj())));

  // Remove the floating reference (since it is newly created).
  g_variant_ref_sink(result.gobj());

  return result;
}

// static
const VariantType& Variant<Glib::ustring>::variant_type()
{
  static VariantType type(G_VARIANT_TYPE_STRING);
  return type;
}

Variant<Glib::ustring>
Variant<Glib::ustring>::create(const Glib::ustring& data)
{
  Variant<Glib::ustring> result =
    Variant<Glib::ustring>(g_variant_new_string(data.c_str()));

  // Remove the floating reference (since it is newly created).
  g_variant_ref_sink(result.gobj());

  return result;
}

Glib::ustring Variant<Glib::ustring>::get() const
{
  return Glib::ustring(g_variant_get_string(gobject_, 0));
}

// static
const VariantType& Variant<std::string>::variant_type()
{
  static VariantType type(G_VARIANT_TYPE_BYTESTRING);
  return type;
}

Variant<std::string>
Variant<std::string>::create(const std::string& data)
{
  Variant<std::string> result =
    Variant<std::string>(g_variant_new_bytestring(data.c_str()));

  // Remove the floating reference (since it is newly created).
  g_variant_ref_sink(result.gobj());

  return result;
}

std::string Variant<std::string>::get() const
{
  return std::string(g_variant_get_bytestring(gobject_));
}

typedef std::vector<Glib::ustring> type_vec_ustring;

// static
const VariantType& Variant<type_vec_ustring>::variant_type()
{
  static VariantType type(G_VARIANT_TYPE_STRING_ARRAY);
  return type;
}

Variant<type_vec_ustring>
Variant<type_vec_ustring>::create(const type_vec_ustring& data)
{
  // Get the variant type of the elements.
  VariantType element_variant_type = Variant<Glib::ustring>::variant_type();

  // Get the variant type of the array.
  VariantType array_variant_type =
    VariantType::create_array(element_variant_type);

  // Create a GVariantBuilder to build the array.
  GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());

  // Add the elements of the vector into the builder.
  for(type_vec_ustring::const_iterator iter = data.begin();
   iter < data.end(); iter++)
  {
    g_variant_builder_add(builder,
      reinterpret_cast<gchar*>(element_variant_type.gobj()), iter->c_str());
  }

  // Create the variant using the builder.
  Variant<type_vec_ustring> result =
    Variant<type_vec_ustring>(g_variant_new(
      reinterpret_cast<gchar*>(array_variant_type.gobj()), builder));

  // Remove the floating reference (since it is newly created).
  g_variant_ref_sink(result.gobj());

  return result;
}

Glib::ustring Variant<type_vec_ustring>::get(gsize index) const
{
  gsize n_elements = 0;

  const gchar** array = g_variant_get_strv(const_cast<GVariant*>(gobj()),
    &n_elements);

  if(index > n_elements)
    throw std::runtime_error(
      "Variant< std::vector<Glib::ustring >::get(): Index out of bounds.");

  return array[index];
}

type_vec_ustring Variant<type_vec_ustring>::get() const
{
  gsize n_elements = 0;

  const gchar** array = g_variant_get_strv(const_cast<GVariant*>(gobj()),
    &n_elements);

  type_vec_ustring result(array, array + n_elements);
  return result;
}

VariantIter Variant<type_vec_ustring>::get_iter()
{
  // Get the variant type of the elements.
  VariantType element_variant_type = Variant<Glib::ustring>::variant_type();

  // Get the variant type of the array.
  VariantType array_variant_type =
    VariantType::create_array(element_variant_type);

  // Get the GVariantIter.
  GVariantIter* g_iter = 0;
  g_variant_get(const_cast<GVariant*>(gobj()),
    reinterpret_cast<gchar*>(array_variant_type.gobj()), &g_iter);

  return VariantIter(g_iter);
}

typedef std::vector<std::string> type_vec_string;

// static
const VariantType& Variant<type_vec_string>::variant_type()
{
  static VariantType type(G_VARIANT_TYPE_BYTESTRING_ARRAY);
  return type;
}

Variant<type_vec_string>
Variant<type_vec_string>::create(const type_vec_string& data)
{
  // Get the variant type of the elements.
  VariantType element_variant_type = Variant<std::string>::variant_type();

  // Get the variant type of the array.
  VariantType array_variant_type =
    VariantType::create_array(element_variant_type);

  // Create a GVariantBuilder to build the array.
  GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());

  // Add the elements of the vector into the builder.
  for(type_vec_string::const_iterator iter = data.begin();
   iter < data.end(); iter++)
  {
    g_variant_builder_add(builder,
      reinterpret_cast<gchar*>(element_variant_type.gobj()), iter->c_str());
  }

  // Create the variant using the builder.
  Variant<type_vec_string> result =
    Variant<type_vec_string>(g_variant_new(
      reinterpret_cast<gchar*>(array_variant_type.gobj()), builder));

  // Remove the floating reference (since it is newly created).
  g_variant_ref_sink(result.gobj());

  return result;
}

std::string Variant<type_vec_string>::get(gsize index) const
{
  gsize n_elements = 0;

  const gchar** array =
    g_variant_get_bytestring_array(const_cast<GVariant*>(gobj()), &n_elements);

  if(index > n_elements)
    throw std::runtime_error(
      "Variant< std::vector<std::string >::get(): Index out of bounds.");

  return array[index];
}

type_vec_string Variant<type_vec_string>::get() const
{
  gsize n_elements = 0;

  const gchar** array =
    g_variant_get_bytestring_array(const_cast<GVariant*>(gobj()), &n_elements);

  type_vec_string result(array, array + n_elements);
  return result;
}

VariantIter Variant<type_vec_string>::get_iter()
{
  // Get the variant type of the elements.
  VariantType element_variant_type = Variant<std::string>::variant_type();

  // Get the variant type of the array.
  VariantType array_variant_type =
    VariantType::create_array(element_variant_type);

  // Get the GVariantIter.
  GVariantIter* g_iter = 0;
  g_variant_get(const_cast<GVariant*>(gobj()),
    reinterpret_cast<gchar*>(array_variant_type.gobj()), &g_iter);

  return VariantIter(g_iter);
}

} // namespace Glib

namespace
{
} // anonymous namespace


namespace Glib
{

Glib::VariantBase wrap(GVariant* object, bool take_copy /* = false */)
{
  return Glib::VariantBase(object, take_copy);
}

} // namespace Glib


namespace Glib
{


VariantBase::VariantBase()
:
  gobject_ (0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.
{}

VariantBase::VariantBase(const VariantBase& src)
:
  gobject_ ((src.gobject_) ? g_variant_ref_sink(src.gobject_) : 0)
{}

VariantBase::VariantBase(GVariant* castitem, bool make_a_copy /* = false */)
{
  if(!make_a_copy)
  {
    // It was given to us by a function which has already made a copy for us to keep.
    gobject_ = castitem;
  }
  else
  {
    // We are probably getting it via direct access to a struct,
    // so we can not just take it - we have to take a copy of it.
    if(castitem)
      gobject_ = g_variant_ref_sink(castitem);
    else
      gobject_ = 0;
  }
}

VariantBase& VariantBase::operator=(const VariantBase& src)
{
  GVariant *const new_gobject = (src.gobject_) ? g_variant_ref_sink(src.gobject_) : 0;

  if(gobject_)
    g_variant_unref(gobject_);

  gobject_ = new_gobject;

  return *this;
}

VariantBase::~VariantBase()
{
  if(gobject_)
    g_variant_unref(gobject_);
}

GVariant* VariantBase::gobj_copy() const
{
  return g_variant_ref_sink(gobject_);
}


VariantType VariantBase::get_type() const
{
  return Glib::wrap(const_cast<GVariantType*>(g_variant_get_type(const_cast<GVariant*>(gobj()))), true);
}

std::string VariantBase::get_type_string() const
{
  return Glib::convert_const_gchar_ptr_to_stdstring(g_variant_get_type_string(const_cast<GVariant*>(gobj())));
}

bool VariantBase::is_floating() const
{
  return g_variant_is_floating(const_cast<GVariant*>(gobj()));
}

bool VariantBase::is_of_type(const VariantType& type) const
{
  return g_variant_is_of_type(const_cast<GVariant*>(gobj()), (type).gobj());
}

bool VariantBase::is_container() const
{
  return g_variant_is_container(const_cast<GVariant*>(gobj()));
}

GVariantClass VariantBase::classify() const
{
  return g_variant_classify(const_cast<GVariant*>(gobj()));
}

gsize VariantBase::get_size() const
{
  return g_variant_get_size(const_cast<GVariant*>(gobj()));
}

gconstpointer VariantBase::get_data()
{
  return g_variant_get_data(gobj());
}

void VariantBase::store(gpointer data) const
{
g_variant_store(const_cast<GVariant*>(gobj()), data); 
}

Glib::ustring VariantBase::print(bool type_annotate) const
{
  return Glib::convert_return_gchar_ptr_to_ustring(g_variant_print(const_cast<GVariant*>(gobj()), static_cast<int>(type_annotate)));
}

guint VariantBase::hash() const
{
  return g_variant_hash(const_cast<GVariant*>(gobj()));
}

bool VariantBase::equal(const VariantBase& other) const
{
  return g_variant_equal(const_cast<GVariant*>(gobj()), const_cast<GVariant*>((other).gobj()));
}

bool VariantBase::is_normal_form() const
{
  return g_variant_is_normal_form(const_cast<GVariant*>(gobj()));
}


} // namespace Glib


namespace Glib
{


bool VariantStringBase::is_object_path(std::string string)
{
  return g_variant_is_object_path(string.c_str());
}


bool VariantStringBase::is_signature(std::string string)
{
  return g_variant_is_signature(string.c_str());
}


} // namespace Glib


namespace Glib
{


gsize VariantContainerBase::get_n_children() const
{
  return g_variant_n_children(const_cast<GVariant*>(gobj()));
}


} // namespace Glib


