1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY! 2 #ifndef _GLIBMM_BYTEARRAY_H 3 #define _GLIBMM_BYTEARRAY_H 4 5 6 /* Copyright (C) 2013 The glibmm Development Team 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 23 #include <cstddef> // std::size_t 24 #include <sigc++/slot.h> 25 #include <glibmm/refptr.h> 26 #include <glibmm/value.h> 27 #include <glibmm/wrap.h> 28 #include <glib.h> 29 30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 31 typedef struct _GByteArray GByteArray; 32 #endif 33 34 namespace Glib 35 { 36 37 /** ByteArray - Arrays of bytes. 38 * ByteArray is a mutable array of bytes, to provide arrays of bytes which grow 39 * automatically as elements are added. 40 * 41 * To create a new ByteArray use create(). To add elements to a ByteArray, use 42 * append(), and prepend(). 43 * 44 * To set the size of a ByteArray, use set_size(). 45 * 46 * @newin{2,36} 47 */ 48 class GLIBMM_API ByteArray final 49 { 50 public: 51 #ifndef DOXYGEN_SHOULD_SKIP_THIS 52 using CppObjectType = ByteArray; 53 using BaseObjectType = GByteArray; 54 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 55 56 57 /** Increment the reference count for this object. 58 * You should never need to do this manually - use the object via a RefPtr instead. 59 */ 60 void reference() const; 61 62 /** Decrement the reference count for this object. 63 * You should never need to do this manually - use the object via a RefPtr instead. 64 */ 65 void unreference() const; 66 67 ///Provides access to the underlying C instance. 68 GByteArray* gobj(); 69 70 ///Provides access to the underlying C instance. 71 const GByteArray* gobj() const; 72 73 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. 74 GByteArray* gobj_copy() const; 75 76 ByteArray() = delete; 77 78 // noncopyable 79 ByteArray(const ByteArray&) = delete; 80 ByteArray& operator=(const ByteArray&) = delete; 81 82 protected: 83 // Do not derive this. Glib::ByteArray can neither be constructed nor deleted. 84 85 void operator delete(void*, std::size_t); 86 87 private: 88 89 90 public: 91 /** A Slot type to compare two elements in the array. The slot should return 92 * -1 if the first value is less than the second, 0 if they are equal and 1 93 * if the first value is greater than the second. 94 * 95 * Slot Prototype: 96 * 97 * <code> 98 * int compare(const guint8* first, const guint8* second); 99 * </code> 100 */ 101 using SlotCompare = sigc::slot<int, const guint8*, const guint8*>; 102 103 104 /** Creates a new ByteArray with a reference count of 1. 105 * 106 * @return The new ByteArray. 107 */ 108 static Glib::RefPtr<ByteArray> create(); 109 110 111 /** Adds the given bytes to the end of the ByteArray. 112 * The array will grow in size automatically if necessary. 113 * 114 * @param data The byte data to be added. 115 * @param len The number of bytes to add. 116 * @return The ByteArray. 117 */ 118 Glib::RefPtr<ByteArray> append(const guint8* data, guint len); 119 120 /** Adds the given data to the start of the ByteArray. 121 * The array will grow in size automatically if necessary. 122 * 123 * @param data The byte data to be added. 124 * @param len The number of bytes to add. 125 * @return The ByteArray. 126 */ 127 Glib::RefPtr<ByteArray> prepend(const guint8* data, guint len); 128 129 /** Gets the size of the byte array. 130 * @return The size. 131 * @newin{2,36} 132 */ 133 guint size() const; 134 135 /** Gets the data of the byte array. 136 * @return The data. 137 * @newin{2,36} 138 */ 139 guint8* get_data(); 140 141 /** Gets the data of the byte array. 142 * @return The data. 143 * @newin{2,36} 144 */ 145 const guint8* get_data() const; 146 147 148 /** Removes the byte at the given index from a ByteArray. 149 * The following bytes are moved down one place. 150 * 151 * @param index The index of the byte to remove. 152 * @return The ByteArray. 153 */ 154 Glib::RefPtr<ByteArray> remove_index(guint index); 155 156 /** Removes the byte at the given index from a ByteArray. The last 157 * element in the array is used to fill in the space, so this function 158 * does not preserve the order of the ByteArray. But it is faster 159 * than g_byte_array_remove_index(). 160 * 161 * @param index The index of the byte to remove. 162 * @return The ByteArray. 163 */ 164 Glib::RefPtr<ByteArray> remove_index_fast(guint index); 165 166 /** Removes the given number of bytes starting at the given index from a 167 * ByteArray. The following elements are moved to close the gap. 168 * 169 * @newin{2,4} 170 * 171 * @param index The index of the first byte to remove. 172 * @param length The number of bytes to remove. 173 * @return The ByteArray. 174 */ 175 Glib::RefPtr<ByteArray> remove_range(guint index, guint length); 176 177 178 /** Like g_byte_array_sort(), but the comparison function takes an extra 179 * user data argument. 180 * 181 * @param slot Comparison function. 182 */ 183 void sort(const SlotCompare& slot); 184 185 186 /** Sets the size of the ByteArray, expanding it if necessary. 187 * 188 * @param length The new size of the ByteArray. 189 * @return The ByteArray. 190 */ 191 Glib::RefPtr<ByteArray> set_size(guint length); 192 193 #ifndef DOXYGEN_SHOULD_SKIP_THIS 194 static GType get_type() G_GNUC_CONST; 195 #endif 196 197 198 }; 199 200 #ifndef DOXYGEN_SHOULD_SKIP_THIS 201 template <> 202 class GLIBMM_API Value< Glib::RefPtr<Glib::ByteArray> > : public ValueBase_Boxed 203 { 204 public: value_type()205 static GType value_type() { return Glib::ByteArray::get_type(); } set(const Glib::RefPtr<Glib::ByteArray> & array)206 void set(const Glib::RefPtr<Glib::ByteArray>& array) { set_boxed(Glib::unwrap(array)); } get()207 Glib::RefPtr<Glib::ByteArray> get() { return Glib::RefPtr<Glib::ByteArray>(reinterpret_cast<Glib::ByteArray*>(get_boxed())); } 208 }; 209 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 210 211 } // namespace Glib 212 213 214 namespace Glib 215 { 216 217 /** A Glib::wrap() method for this object. 218 * 219 * @param object The C instance. 220 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. 221 * @result A C++ instance that wraps this C instance. 222 * 223 * @relates Glib::ByteArray 224 */ 225 GLIBMM_API 226 Glib::RefPtr<Glib::ByteArray> wrap(GByteArray* object, bool take_copy = false); 227 228 } // namespace Glib 229 230 231 #endif /* _GLIBMM_BYTEARRAY_H */ 232 233