// Generated by gmmproc 2.66.9 -- DO NOT MODIFY!


#include <glibmm.h>

#include <glibmm/checksum.h>
#include <glibmm/private/checksum_p.h>


/* Copyright (C) 2002 The gtkmm 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, see <http://www.gnu.org/licenses/>.
 */

#include <glibmm/utility.h>
#include <glibmm/checksum.h>

namespace Glib
{

Checksum::Checksum(ChecksumType type) : gobject_(g_checksum_new((GChecksumType)type))
{
}

Checksum::operator bool() const
{
  return gobject_ != nullptr;
}

gssize
Checksum::get_length(ChecksumType checksum_type)
{
  return g_checksum_type_get_length((GChecksumType)checksum_type);
}

std::string
Checksum::compute_checksum(ChecksumType checksum_type, const std::string& data)
{
  return Glib::convert_return_gchar_ptr_to_stdstring(
    g_compute_checksum_for_string(((GChecksumType)checksum_type), data.c_str(), data.size()));
}

void
Checksum::update(const std::string& data)
{
  g_checksum_update(gobj(), (const guchar*)data.c_str(), data.size());
}

// Glib::Value<Glib::Checksum>
GType Value<Checksum>::value_type()
{
  return G_TYPE_CHECKSUM;
}

void Value<Checksum>::set(const CppType& data)
{
  set_boxed(data.gobj());
}

Value<Checksum>::CppType Value<Checksum>::get() const
{
  return Glib::wrap(static_cast<CType>(get_boxed()), true);
}

} // Glib namespace

namespace
{
} // anonymous namespace


namespace Glib
{

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

} // namespace Glib


namespace Glib
{


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

Checksum::Checksum(const Checksum& src)
:
  gobject_ ((src.gobject_) ? g_checksum_copy(src.gobject_) : nullptr)
{}

Checksum::Checksum(GChecksum* 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_checksum_copy(castitem);
    else
      gobject_ = nullptr;
  }
}


Checksum& Checksum::operator=(const Checksum& src)
{
  const auto new_gobject = (src.gobject_) ? g_checksum_copy(src.gobject_) : nullptr;

  if(gobject_)
    g_checksum_free(gobject_);

  gobject_ = new_gobject;

  return *this;
}

Checksum::Checksum(Checksum&& other) noexcept
:
  gobject_(other.gobject_)
{
  other.gobject_ = nullptr;
}

Checksum& Checksum::operator=(Checksum&& other) noexcept
{
  Checksum temp (std::move(other));
  swap(temp);
  return *this;
}

Checksum::~Checksum() noexcept
{
  if(gobject_)
    g_checksum_free(gobject_);
}

void Checksum::swap(Checksum& other) noexcept
{
  std::swap(gobject_, other.gobject_);
}

GChecksum* Checksum::gobj_copy() const
{
  return g_checksum_copy(gobject_);
}


void Checksum::reset()
{
  g_checksum_reset(gobj());
}

void Checksum::update(const guchar* data, gsize length)
{
  g_checksum_update(gobj(), data, (gssize)(length));
}

void Checksum::get_digest(guint8 * buffer, gsize * digest_len) const
{
  g_checksum_get_digest(const_cast<GChecksum*>(gobj()), buffer, digest_len);
}

std::string Checksum::get_string() const
{
  return Glib::convert_const_gchar_ptr_to_stdstring(g_checksum_get_string(const_cast<GChecksum*>(gobj())));
}

std::string Checksum::compute_checksum(ChecksumType checksum_type, const guchar* data, gsize length)
{
  return Glib::convert_return_gchar_ptr_to_stdstring(g_compute_checksum_for_data(((GChecksumType)checksum_type), data, length));
}


} // namespace Glib


