Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / glibmm2 / glib / glibmm / checksum.cc
1 // Generated by gtkmmproc -- DO NOT MODIFY!
2
3
4 #include <glibmm/checksum.h>
5 #include <glibmm/private/checksum_p.h>
6
7 /* $Id$ */
8
9 /* Copyright (C) 2002 The gtkmm Development Team
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include <glibmm/utility.h>
27 #include <glibmm/checksum.h>
28
29 namespace Glib
30 {
31
32 Checksum::Checksum(ChecksumType type)
33 : gobject_(g_checksum_new((GChecksumType)type))
34 {
35 }
36
37 Checksum::operator bool() const
38 {
39   return gobject_ != 0;
40 }
41
42 gssize Checksum::get_length(ChecksumType checksum_type)
43 {
44   return g_checksum_type_get_length((GChecksumType)checksum_type);
45 }
46
47 std::string Checksum::compute_checksum(ChecksumType type, const std::string& data)
48 {
49   return Glib::convert_return_gchar_ptr_to_ustring(g_compute_checksum_for_string(((GChecksumType)type), data.c_str(), data.size()));
50 }
51
52 void Checksum::update(const std::string& data)
53 {
54   g_checksum_update(gobj(), (const guchar*)data.c_str(), data.size()); 
55 }
56
57 } // Glib namespace
58
59
60 namespace
61 {
62 } // anonymous namespace
63
64
65 namespace Glib
66 {
67
68 Glib::Checksum wrap(GChecksum* object, bool take_copy /* = false */)
69 {
70   return Glib::Checksum(object, take_copy);
71 }
72
73 } // namespace Glib
74
75
76 namespace Glib
77 {
78
79
80 Checksum::Checksum()
81 :
82   gobject_ (0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.
83 {}
84
85 Checksum::Checksum(const Checksum& src)
86 :
87   gobject_ ((src.gobject_) ? g_checksum_copy(src.gobject_) : 0)
88 {}
89
90 Checksum::Checksum(GChecksum* castitem, bool make_a_copy /* = false */)
91 {
92   if(!make_a_copy)
93   {
94     // It was given to us by a function which has already made a copy for us to keep.
95     gobject_ = castitem;
96   }
97   else
98   {
99     // We are probably getting it via direct access to a struct,
100     // so we can not just take it - we have to take a copy of it.
101     if(castitem)
102       gobject_ = g_checksum_copy(castitem);
103     else
104       gobject_ = 0;
105   }
106 }
107
108 Checksum& Checksum::operator=(const Checksum& src)
109 {
110   GChecksum *const new_gobject = (src.gobject_) ? g_checksum_copy(src.gobject_) : 0;
111
112   if(gobject_)
113     g_checksum_free(gobject_);
114
115   gobject_ = new_gobject;
116
117   return *this;
118 }
119
120 Checksum::~Checksum()
121 {
122   if(gobject_)
123     g_checksum_free(gobject_);
124 }
125
126 GChecksum* Checksum::gobj_copy() const
127 {
128   return g_checksum_copy(gobject_);
129 }
130
131
132 void Checksum::reset()
133 {
134 g_checksum_reset(gobj()); 
135 }
136
137 void Checksum::update(const guchar* data, gsize length)
138 {
139 g_checksum_update(gobj(), data, length); 
140 }
141
142 void Checksum::get_digest(guint8 * buffer, gsize * digest_len) const
143 {
144 g_checksum_get_digest(const_cast<GChecksum*>(gobj()), buffer, digest_len); 
145 }
146
147 std::string Checksum::get_string() const
148 {
149   return Glib::convert_const_gchar_ptr_to_stdstring(g_checksum_get_string(const_cast<GChecksum*>(gobj())));
150 }
151
152 std::string Checksum::compute_checksum(ChecksumType type, const guchar* data, gsize length)
153 {
154   return Glib::convert_return_gchar_ptr_to_stdstring(g_compute_checksum_for_data(((GChecksumType)type), data, length));
155 }
156
157
158 } // namespace Glib
159
160