1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY!
2 
3 
4 #include <glibmm.h>
5 
6 #include <glibmm/checksum.h>
7 #include <glibmm/private/checksum_p.h>
8 
9 
10 /* Copyright (C) 2002 The gtkmm Development Team
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include <glibmm/utility.h>
27 #include <glibmm/checksum.h>
28 
29 namespace Glib
30 {
31 
Checksum(ChecksumType type)32 Checksum::Checksum(ChecksumType type) : gobject_(g_checksum_new((GChecksumType)type))
33 {
34 }
35 
operator bool() const36 Checksum::operator bool() const
37 {
38   return gobject_ != nullptr;
39 }
40 
41 gssize
get_length(ChecksumType checksum_type)42 Checksum::get_length(ChecksumType checksum_type)
43 {
44   return g_checksum_type_get_length((GChecksumType)checksum_type);
45 }
46 
47 std::string
compute_checksum(ChecksumType checksum_type,const std::string & data)48 Checksum::compute_checksum(ChecksumType checksum_type, const std::string& data)
49 {
50   return Glib::convert_return_gchar_ptr_to_stdstring(
51     g_compute_checksum_for_string(((GChecksumType)checksum_type), data.c_str(), data.size()));
52 }
53 
54 void
update(const std::string & data)55 Checksum::update(const std::string& data)
56 {
57   g_checksum_update(gobj(), (const guchar*)data.c_str(), data.size());
58 }
59 
60 // Glib::Value<Glib::Checksum>
value_type()61 GType Value<Checksum>::value_type()
62 {
63   return G_TYPE_CHECKSUM;
64 }
65 
set(const CppType & data)66 void Value<Checksum>::set(const CppType& data)
67 {
68   set_boxed(data.gobj());
69 }
70 
get() const71 Value<Checksum>::CppType Value<Checksum>::get() const
72 {
73   return Glib::wrap(static_cast<CType>(get_boxed()), true);
74 }
75 
76 } // Glib namespace
77 
78 namespace
79 {
80 } // anonymous namespace
81 
82 
83 namespace Glib
84 {
85 
wrap(GChecksum * object,bool take_copy)86 Glib::Checksum wrap(GChecksum* object, bool take_copy /* = false */)
87 {
88   return Glib::Checksum(object, take_copy);
89 }
90 
91 } // namespace Glib
92 
93 
94 namespace Glib
95 {
96 
97 
Checksum()98 Checksum::Checksum()
99 :
100   gobject_ (nullptr) // Allows creation of invalid wrapper, e.g. for output arguments to methods.
101 {}
102 
Checksum(const Checksum & src)103 Checksum::Checksum(const Checksum& src)
104 :
105   gobject_ ((src.gobject_) ? g_checksum_copy(src.gobject_) : nullptr)
106 {}
107 
Checksum(GChecksum * castitem,bool make_a_copy)108 Checksum::Checksum(GChecksum* castitem, bool make_a_copy /* = false */)
109 {
110   if(!make_a_copy)
111   {
112     // It was given to us by a function which has already made a copy for us to keep.
113     gobject_ = castitem;
114   }
115   else
116   {
117     // We are probably getting it via direct access to a struct,
118     // so we can not just take it - we have to take a copy of it.
119     if(castitem)
120       gobject_ = g_checksum_copy(castitem);
121     else
122       gobject_ = nullptr;
123   }
124 }
125 
126 
operator =(const Checksum & src)127 Checksum& Checksum::operator=(const Checksum& src)
128 {
129   const auto new_gobject = (src.gobject_) ? g_checksum_copy(src.gobject_) : nullptr;
130 
131   if(gobject_)
132     g_checksum_free(gobject_);
133 
134   gobject_ = new_gobject;
135 
136   return *this;
137 }
138 
Checksum(Checksum && other)139 Checksum::Checksum(Checksum&& other) noexcept
140 :
141   gobject_(other.gobject_)
142 {
143   other.gobject_ = nullptr;
144 }
145 
operator =(Checksum && other)146 Checksum& Checksum::operator=(Checksum&& other) noexcept
147 {
148   Checksum temp (other);
149   swap(temp);
150   return *this;
151 }
152 
~Checksum()153 Checksum::~Checksum() noexcept
154 {
155   if(gobject_)
156     g_checksum_free(gobject_);
157 }
158 
swap(Checksum & other)159 void Checksum::swap(Checksum& other) noexcept
160 {
161   std::swap(gobject_, other.gobject_);
162 }
163 
gobj_copy() const164 GChecksum* Checksum::gobj_copy() const
165 {
166   return g_checksum_copy(gobject_);
167 }
168 
169 
reset()170 void Checksum::reset()
171 {
172   g_checksum_reset(gobj());
173 }
174 
update(const guchar * data,gsize length)175 void Checksum::update(const guchar* data, gsize length)
176 {
177   g_checksum_update(gobj(), data, (gssize)(length));
178 }
179 
get_digest(guint8 * buffer,gsize * digest_len) const180 void Checksum::get_digest(guint8 * buffer, gsize * digest_len) const
181 {
182   g_checksum_get_digest(const_cast<GChecksum*>(gobj()), buffer, digest_len);
183 }
184 
get_string() const185 std::string Checksum::get_string() const
186 {
187   return Glib::convert_const_gchar_ptr_to_stdstring(g_checksum_get_string(const_cast<GChecksum*>(gobj())));
188 }
189 
compute_checksum(ChecksumType checksum_type,const guchar * data,gsize length)190 std::string Checksum::compute_checksum(ChecksumType checksum_type, const guchar* data, gsize length)
191 {
192   return Glib::convert_return_gchar_ptr_to_stdstring(g_compute_checksum_for_data(((GChecksumType)checksum_type), data, length));
193 }
194 
195 
196 } // namespace Glib
197 
198 
199