diff options
author | Murray Cumming <murrayc@murrayc.com> | 2016-02-26 22:46:55 +0100 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2016-02-26 22:46:55 +0100 |
commit | e1eb5c1d651a8906074feda2d2a0ad103e838949 (patch) | |
tree | e387d5498d9c2dd53170126b3497b28c25c5d47a /glib/src | |
parent | dc111022570a417f396b81cdaef1a5db58022017 (diff) | |
download | glibmm-e1eb5c1d651a8906074feda2d2a0ad103e838949.tar.gz |
Run clang-format on the .ccg files.
This seems to work.
Diffstat (limited to 'glib/src')
-rw-r--r-- | glib/src/binding.ccg | 63 | ||||
-rw-r--r-- | glib/src/bytearray.ccg | 24 | ||||
-rw-r--r-- | glib/src/bytes.ccg | 5 | ||||
-rw-r--r-- | glib/src/checksum.ccg | 15 | ||||
-rw-r--r-- | glib/src/convert.ccg | 187 | ||||
-rw-r--r-- | glib/src/date.ccg | 223 | ||||
-rw-r--r-- | glib/src/datetime.ccg | 2 | ||||
-rw-r--r-- | glib/src/fileutils.ccg | 97 | ||||
-rw-r--r-- | glib/src/iochannel.ccg | 250 | ||||
-rw-r--r-- | glib/src/keyfile.ccg | 271 | ||||
-rw-r--r-- | glib/src/markup.ccg | 223 | ||||
-rw-r--r-- | glib/src/miscutils.ccg | 217 | ||||
-rw-r--r-- | glib/src/module.ccg | 17 | ||||
-rw-r--r-- | glib/src/optioncontext.ccg | 95 | ||||
-rw-r--r-- | glib/src/optionentry.ccg | 52 | ||||
-rw-r--r-- | glib/src/optiongroup.ccg | 792 | ||||
-rw-r--r-- | glib/src/regex.ccg | 207 | ||||
-rw-r--r-- | glib/src/shell.ccg | 21 | ||||
-rw-r--r-- | glib/src/spawn.ccg | 218 | ||||
-rw-r--r-- | glib/src/thread.ccg | 184 | ||||
-rw-r--r-- | glib/src/threads.ccg | 94 | ||||
-rw-r--r-- | glib/src/timezone.ccg | 2 | ||||
-rw-r--r-- | glib/src/unicode.ccg | 1 | ||||
-rw-r--r-- | glib/src/uriutils.ccg | 16 | ||||
-rw-r--r-- | glib/src/valuearray.ccg | 45 | ||||
-rw-r--r-- | glib/src/variant.ccg | 237 | ||||
-rw-r--r-- | glib/src/variantdict.ccg | 18 | ||||
-rw-r--r-- | glib/src/variantiter.ccg | 10 | ||||
-rw-r--r-- | glib/src/varianttype.ccg | 21 |
29 files changed, 1866 insertions, 1741 deletions
diff --git a/glib/src/binding.ccg b/glib/src/binding.ccg index a36b01c8..576b64f6 100644 --- a/glib/src/binding.ccg +++ b/glib/src/binding.ccg @@ -21,20 +21,19 @@ namespace { struct BindingTransformSlots { - BindingTransformSlots( - const Glib::Binding::SlotTransform& transform_to, + BindingTransformSlots(const Glib::Binding::SlotTransform& transform_to, const Glib::Binding::SlotTransform& transform_from) - : - from_source_to_target(transform_to), from_target_to_source(transform_from) - {} + : from_source_to_target(transform_to), from_target_to_source(transform_from) + { + } Glib::Binding::SlotTransform from_source_to_target; Glib::Binding::SlotTransform from_target_to_source; }; -gboolean Binding_transform_callback_common( - const GValue* from_value, GValue* to_value, - Glib::Binding::SlotTransform& the_slot) +gboolean +Binding_transform_callback_common( + const GValue* from_value, GValue* to_value, Glib::Binding::SlotTransform& the_slot) { bool result = false; try @@ -48,8 +47,9 @@ gboolean Binding_transform_callback_common( return result; } -gboolean Binding_transform_to_callback(GBinding*, - const GValue* from_value, GValue* to_value, gpointer user_data) +gboolean +Binding_transform_to_callback( + GBinding*, const GValue* from_value, GValue* to_value, gpointer user_data) { Glib::Binding::SlotTransform& the_slot = static_cast<BindingTransformSlots*>(user_data)->from_source_to_target; @@ -57,8 +57,9 @@ gboolean Binding_transform_to_callback(GBinding*, return Binding_transform_callback_common(from_value, to_value, the_slot); } -gboolean Binding_transform_from_callback(GBinding*, - const GValue* from_value, GValue* to_value, gpointer user_data) +gboolean +Binding_transform_from_callback( + GBinding*, const GValue* from_value, GValue* to_value, gpointer user_data) { Glib::Binding::SlotTransform& the_slot = static_cast<BindingTransformSlots*>(user_data)->from_target_to_source; @@ -66,7 +67,8 @@ gboolean Binding_transform_from_callback(GBinding*, return Binding_transform_callback_common(from_value, to_value, the_slot); } -void Binding_transform_callback_destroy(gpointer user_data) +void +Binding_transform_callback_destroy(gpointer user_data) { delete static_cast<BindingTransformSlots*>(user_data); } @@ -75,22 +77,19 @@ void Binding_transform_callback_destroy(gpointer user_data) namespace Glib { -//static -Glib::RefPtr<Binding> Binding::bind_property_value( - const PropertyProxy_Base& source_property, - const PropertyProxy_Base& target_property, - BindingFlags flags, - const SlotTransform& transform_to, +// static +Glib::RefPtr<Binding> +Binding::bind_property_value(const PropertyProxy_Base& source_property, + const PropertyProxy_Base& target_property, BindingFlags flags, const SlotTransform& transform_to, const SlotTransform& transform_from) { GBinding* binding = nullptr; if (transform_to.empty() && transform_from.empty()) { // No user-supplied transformations. - binding = g_object_bind_property( - source_property.get_object()->gobj(), source_property.get_name(), - target_property.get_object()->gobj(), target_property.get_name(), - (GBindingFlags)flags); + binding = + g_object_bind_property(source_property.get_object()->gobj(), source_property.get_name(), + target_property.get_object()->gobj(), target_property.get_name(), (GBindingFlags)flags); } else { @@ -99,13 +98,11 @@ Glib::RefPtr<Binding> Binding::bind_property_value( // when Binding_transform_callback_destroy() is called. BindingTransformSlots* slots_copy = new BindingTransformSlots(transform_to, transform_from); - binding = g_object_bind_property_full( - source_property.get_object()->gobj(), source_property.get_name(), - target_property.get_object()->gobj(), target_property.get_name(), - (GBindingFlags)flags, - transform_to.empty() ? nullptr : &Binding_transform_to_callback, - transform_from.empty() ? nullptr : &Binding_transform_from_callback, - slots_copy, &Binding_transform_callback_destroy); + binding = g_object_bind_property_full(source_property.get_object()->gobj(), + source_property.get_name(), target_property.get_object()->gobj(), target_property.get_name(), + (GBindingFlags)flags, transform_to.empty() ? nullptr : &Binding_transform_to_callback, + transform_from.empty() ? nullptr : &Binding_transform_from_callback, slots_copy, + &Binding_transform_callback_destroy); } if (!binding) @@ -118,7 +115,8 @@ Glib::RefPtr<Binding> Binding::bind_property_value( return Glib::RefPtr<Binding>(new Binding(binding)); } -void Binding::unbind() +void +Binding::unbind() { // Call g_binding_unbind() only once. It always calls g_object_unref(). if (g_binding_get_source(gobj())) @@ -132,7 +130,8 @@ void Binding::unbind() // target object is finalized, almost like g_binding_unbind(). // But the GBinding object shall be destroyed when and only when the last // reference from a Glib::RefPtr is dropped. -void Binding::unreference() const +void +Binding::unreference() const { GBinding* const binding = const_cast<GBinding*>(gobj()); diff --git a/glib/src/bytearray.ccg b/glib/src/bytearray.ccg index 4cf3ff16..2cb910ca 100644 --- a/glib/src/bytearray.ccg +++ b/glib/src/bytearray.ccg @@ -18,41 +18,41 @@ namespace { -extern "C" -{ +extern "C" { -int ByteArray_Compare_Data_Func(gconstpointer a, gconstpointer b, - gpointer user_data) +int +ByteArray_Compare_Data_Func(gconstpointer a, gconstpointer b, gpointer user_data) { - Glib::ByteArray::SlotCompare* slot = - static_cast<Glib::ByteArray::SlotCompare*>(user_data); + Glib::ByteArray::SlotCompare* slot = static_cast<Glib::ByteArray::SlotCompare*>(user_data); return (*slot)(static_cast<const guint8*>(a), static_cast<const guint8*>(b)); } - } - } namespace Glib { -guint ByteArray::size() const +guint +ByteArray::size() const { return gobj()->len; } -guint8* ByteArray::get_data() +guint8* +ByteArray::get_data() { return gobj()->data; } -const guint8* ByteArray::get_data() const +const guint8* +ByteArray::get_data() const { return gobj()->data; } -GType ByteArray::get_type() +GType +ByteArray::get_type() { return g_byte_array_get_type(); } diff --git a/glib/src/bytes.ccg b/glib/src/bytes.ccg index ae7270a5..0ff936ad 100644 --- a/glib/src/bytes.ccg +++ b/glib/src/bytes.ccg @@ -18,9 +18,10 @@ namespace Glib { -Glib::RefPtr<Glib::Bytes> Bytes::create(gconstpointer data, gsize size) +Glib::RefPtr<Glib::Bytes> +Bytes::create(gconstpointer data, gsize size) { - GBytes* bytes= g_bytes_new(data, size); + GBytes* bytes = g_bytes_new(data, size); return Glib::wrap(bytes); } diff --git a/glib/src/checksum.ccg b/glib/src/checksum.ccg index 9a700501..140ea792 100644 --- a/glib/src/checksum.ccg +++ b/glib/src/checksum.ccg @@ -21,8 +21,7 @@ namespace Glib { -Checksum::Checksum(ChecksumType type) -: gobject_(g_checksum_new((GChecksumType)type)) +Checksum::Checksum(ChecksumType type) : gobject_(g_checksum_new((GChecksumType)type)) { } @@ -31,17 +30,21 @@ Checksum::operator bool() const return gobject_ != nullptr; } -gssize Checksum::get_length(ChecksumType checksum_type) +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) +std::string +Checksum::compute_checksum(ChecksumType checksum_type, const std::string& data) { - return Glib::convert_return_gchar_ptr_to_ustring(g_compute_checksum_for_string(((GChecksumType)checksum_type), data.c_str(), data.size())); + return Glib::convert_return_gchar_ptr_to_ustring( + g_compute_checksum_for_string(((GChecksumType)checksum_type), data.c_str(), data.size())); } -void Checksum::update(const std::string& data) +void +Checksum::update(const std::string& data) { g_checksum_update(gobj(), (const guchar*)data.c_str(), data.size()); } diff --git a/glib/src/convert.ccg b/glib/src/convert.ccg index 135f135b..6a848475 100644 --- a/glib/src/convert.ccg +++ b/glib/src/convert.ccg @@ -23,17 +23,15 @@ #include <glibmm/utility.h> - namespace Glib { /**** Glib::IConv **********************************************************/ IConv::IConv(const std::string& to_codeset, const std::string& from_codeset) -: - gobject_ (g_iconv_open(to_codeset.c_str(), from_codeset.c_str())) +: gobject_(g_iconv_open(to_codeset.c_str(), from_codeset.c_str())) { - if(gobject_ == reinterpret_cast<GIConv>(-1)) + if (gobject_ == reinterpret_cast<GIConv>(-1)) { GError* gerror = nullptr; @@ -45,61 +43,66 @@ IConv::IConv(const std::string& to_codeset, const std::string& from_codeset) // If this should ever fail we're fucked. g_assert(gerror != nullptr); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); } } -IConv::IConv(GIConv gobject) -: - gobject_ (gobject) -{} +IConv::IConv(GIConv gobject) : gobject_(gobject) +{ +} IConv::~IConv() { g_iconv_close(gobject_); } -std::size_t IConv::iconv(char** inbuf, gsize* inbytes_left, char** outbuf, gsize* outbytes_left) +std::size_t +IConv::iconv(char** inbuf, gsize* inbytes_left, char** outbuf, gsize* outbytes_left) { return g_iconv(gobject_, inbuf, inbytes_left, outbuf, outbytes_left); } -void IConv::reset() +void +IConv::reset() { // Apparently iconv() on Solaris <= 7 segfaults if you pass in // NULL for anything but inbuf; work around that. (NULL outbuf // or NULL *outbuf is allowed by Unix98.) - char* outbuf = nullptr; - gsize inbytes_left = 0; + char* outbuf = nullptr; + gsize inbytes_left = 0; gsize outbytes_left = 0; g_iconv(gobject_, nullptr, &inbytes_left, &outbuf, &outbytes_left); } -std::string IConv::convert(const std::string& str) +std::string +IConv::convert(const std::string& str) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_convert_with_iconv( - str.data(), str.size(), gobject_, nullptr, &bytes_written, &gerror); + char* const buf = + g_convert_with_iconv(str.data(), str.size(), gobject_, nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); - //TODO: Avoid the copy by using a perfect-forwarding std::string constructor? + // TODO: Avoid the copy by using a perfect-forwarding std::string constructor? return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - /**** charset conversion functions *****************************************/ -bool get_charset() +bool +get_charset() { return g_get_charset(nullptr); } -bool get_charset(std::string& charset) +bool +get_charset(std::string& charset) { const char* charset_cstr = nullptr; const bool is_utf8 = g_get_charset(&charset_cstr); @@ -108,132 +111,132 @@ bool get_charset(std::string& charset) return is_utf8; } - -std::string convert(const std::string& str, - const std::string& to_codeset, - const std::string& from_codeset) +std::string +convert(const std::string& str, const std::string& to_codeset, const std::string& from_codeset) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_convert( - str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), - nullptr, &bytes_written, &gerror); + char* const buf = g_convert(str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), + nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); - //TODO: Avoid the copy by using a perfect-forwarding std::string constructor? + // TODO: Avoid the copy by using a perfect-forwarding std::string constructor? return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - -std::string convert_with_fallback(const std::string& str, - const std::string& to_codeset, - const std::string& from_codeset) +std::string +convert_with_fallback( + const std::string& str, const std::string& to_codeset, const std::string& from_codeset) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_convert_with_fallback( - str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), nullptr, - nullptr, &bytes_written, &gerror); + char* const buf = g_convert_with_fallback(str.data(), str.size(), to_codeset.c_str(), + from_codeset.c_str(), nullptr, nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); - //TODO: Avoid the copy by using a perfect-forwarding std::string constructor? + // TODO: Avoid the copy by using a perfect-forwarding std::string constructor? return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - -std::string convert_with_fallback(const std::string& str, - const std::string& to_codeset, - const std::string& from_codeset, - const Glib::ustring& fallback) +std::string +convert_with_fallback(const std::string& str, const std::string& to_codeset, + const std::string& from_codeset, const Glib::ustring& fallback) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_convert_with_fallback( - str.data(), str.size(), to_codeset.c_str(), from_codeset.c_str(), - const_cast<char*>(fallback.c_str()), nullptr, &bytes_written, &gerror); + char* const buf = g_convert_with_fallback(str.data(), str.size(), to_codeset.c_str(), + from_codeset.c_str(), const_cast<char*>(fallback.c_str()), nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - -Glib::ustring locale_to_utf8(const std::string& opsys_string) +Glib::ustring +locale_to_utf8(const std::string& opsys_string) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_locale_to_utf8( - opsys_string.data(), opsys_string.size(), nullptr, &bytes_written, &gerror); + char* const buf = + g_locale_to_utf8(opsys_string.data(), opsys_string.size(), nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); const auto scoped_buf = make_unique_ptr_gfree(buf); return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written); } - -std::string locale_from_utf8(const Glib::ustring& utf8_string) +std::string +locale_from_utf8(const Glib::ustring& utf8_string) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_locale_from_utf8( - utf8_string.data(), utf8_string.bytes(), nullptr, &bytes_written, &gerror); + char* const buf = + g_locale_from_utf8(utf8_string.data(), utf8_string.bytes(), nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - -Glib::ustring filename_to_utf8(const std::string& opsys_string) +Glib::ustring +filename_to_utf8(const std::string& opsys_string) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_filename_to_utf8( - opsys_string.data(), opsys_string.size(), nullptr, &bytes_written, &gerror); + char* const buf = + g_filename_to_utf8(opsys_string.data(), opsys_string.size(), nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); const auto scoped_buf = make_unique_ptr_gfree(buf); return Glib::ustring(scoped_buf.get(), scoped_buf.get() + bytes_written); } - -std::string filename_from_utf8(const Glib::ustring& utf8_string) +std::string +filename_from_utf8(const Glib::ustring& utf8_string) { gsize bytes_written = 0; GError* gerror = nullptr; - char *const buf = g_filename_from_utf8( - utf8_string.data(), utf8_string.bytes(), nullptr, &bytes_written, &gerror); + char* const buf = + g_filename_from_utf8(utf8_string.data(), utf8_string.bytes(), nullptr, &bytes_written, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return std::string(make_unique_ptr_gfree(buf).get(), bytes_written); } - -std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) +std::string +filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) { char* hostname_buf = nullptr; GError* gerror = nullptr; - char *const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &gerror); + char* const buf = g_filename_from_uri(uri.c_str(), &hostname_buf, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); // Let's take ownership at this point. const auto scoped_buf = make_unique_ptr_gfree(buf); - if(hostname_buf) + if (hostname_buf) hostname = make_unique_ptr_gfree(buf).get(); else hostname.erase(); @@ -241,50 +244,54 @@ std::string filename_from_uri(const Glib::ustring& uri, Glib::ustring& hostname) return std::string(scoped_buf.get()); } - -std::string filename_from_uri(const Glib::ustring& uri) +std::string +filename_from_uri(const Glib::ustring& uri) { GError* gerror = nullptr; - char *const buf = g_filename_from_uri(uri.c_str(), nullptr, &gerror); + char* const buf = g_filename_from_uri(uri.c_str(), nullptr, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return std::string(make_unique_ptr_gfree(buf).get()); } - -Glib::ustring filename_to_uri(const std::string& filename, const Glib::ustring& hostname) +Glib::ustring +filename_to_uri(const std::string& filename, const Glib::ustring& hostname) { GError* gerror = nullptr; - char *const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &gerror); + char* const buf = g_filename_to_uri(filename.c_str(), hostname.c_str(), &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return Glib::ustring(make_unique_ptr_gfree(buf).get()); } - -Glib::ustring filename_to_uri(const std::string& filename) +Glib::ustring +filename_to_uri(const std::string& filename) { GError* gerror = nullptr; - char *const buf = g_filename_to_uri(filename.c_str(), nullptr, &gerror); + char* const buf = g_filename_to_uri(filename.c_str(), nullptr, &gerror); - if(gerror) ::Glib::Error::throw_exception(gerror); + if (gerror) + ::Glib::Error::throw_exception(gerror); return Glib::ustring(make_unique_ptr_gfree(buf).get()); } -Glib::ustring filename_display_basename(const std::string& filename) +Glib::ustring +filename_display_basename(const std::string& filename) { - char *const buf = g_filename_display_basename(filename.c_str()); + char* const buf = g_filename_display_basename(filename.c_str()); return Glib::ustring(make_unique_ptr_gfree(buf).get()); } - -Glib::ustring filename_display_name(const std::string& filename) +Glib::ustring +filename_display_name(const std::string& filename) { - char *const buf = g_filename_display_name(filename.c_str()); + char* const buf = g_filename_display_name(filename.c_str()); return Glib::ustring(make_unique_ptr_gfree(buf).get()); } diff --git a/glib/src/date.ccg b/glib/src/date.ccg index 4dcc3f4a..4f15ddaf 100644 --- a/glib/src/date.ccg +++ b/glib/src/date.ccg @@ -35,7 +35,7 @@ Date::Date() Date::Date(Date::Day day, Date::Month month, Date::Year year) { g_date_clear(&gobject_, 1); - g_date_set_dmy(&gobject_, day, (GDateMonth) month, year); + g_date_set_dmy(&gobject_, day, (GDateMonth)month, year); } Date::Date(guint32 julian_day) @@ -44,10 +44,9 @@ Date::Date(guint32 julian_day) g_date_set_julian(&gobject_, julian_day); } -Date::Date(const GDate& castitem) -: - gobject_ (castitem) -{} +Date::Date(const GDate& castitem) : gobject_(castitem) +{ +} Date::Date(const Date& other) { @@ -56,7 +55,8 @@ Date::Date(const Date& other) g_date_set_julian(&gobject_, other.get_julian()); } -Date& Date::operator=(const Date& other) +Date& +Date::operator=(const Date& other) { if (&other != this && g_date_valid(&other.gobject_)) g_date_set_julian(&gobject_, other.get_julian()); @@ -64,243 +64,280 @@ Date& Date::operator=(const Date& other) return *this; } -void Date::clear() +void +Date::clear() { g_date_clear(&gobject_, 1); } -void Date::set_parse(const Glib::ustring& str) +void +Date::set_parse(const Glib::ustring& str) { g_date_set_parse(&gobject_, str.c_str()); } - _DEPRECATE_IFDEF_START -//Avoid a build problem in the case that std::time_t is equivalent to gint32 (GTime is also gint32) -//That would make the set_time() method overload impossible. +// Avoid a build problem in the case that std::time_t is equivalent to gint32 (GTime is also gint32) +// That would make the set_time() method overload impossible. #ifdef GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32 -void Date::set_time(GTime time) +void +Date::set_time(GTime time) { - //This method, and the C function g_date_set_time() that it wraps, are deprecated. + // This method, and the C function g_date_set_time() that it wraps, are deprecated. //(::time_t is used here instead of std::time_t, since the C function is declared - //with ::time_t. It's not important. The C++ standard requires that ::time_t - //and std::time_t shall be identical when both are defined.) + // with ::time_t. It's not important. The C++ standard requires that ::time_t + // and std::time_t shall be identical when both are defined.) g_date_set_time_t(&gobject_, static_cast<time_t>(time)); } -#endif //GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32 +#endif // GLIBMM_HAVE_C_STD_TIME_T_IS_NOT_INT32 _DEPRECATE_IFDEF_END - -void Date::set_time(std::time_t timet) +void +Date::set_time(std::time_t timet) { g_date_set_time_t(&gobject_, timet); } -void Date::set_time_current() +void +Date::set_time_current() { - //As suggested in the C documentation: + // As suggested in the C documentation: g_date_set_time_t(&gobject_, time(nullptr)); } -void Date::set_time(const GTimeVal& timeval) +void +Date::set_time(const GTimeVal& timeval) { g_date_set_time_val(&gobject_, const_cast<GTimeVal*>(&timeval)); } -void Date::set_month(Date::Month month) +void +Date::set_month(Date::Month month) { - g_date_set_month(&gobject_, (GDateMonth) month); + g_date_set_month(&gobject_, (GDateMonth)month); } -void Date::set_day(Date::Day day) +void +Date::set_day(Date::Day day) { g_date_set_day(&gobject_, day); } -void Date::set_year(Date::Year year) +void +Date::set_year(Date::Year year) { g_date_set_year(&gobject_, year); } -void Date::set_dmy(Date::Day day, Date::Month month, Date::Year year) +void +Date::set_dmy(Date::Day day, Date::Month month, Date::Year year) { - g_date_set_dmy(&gobject_, day, (GDateMonth) month, year); + g_date_set_dmy(&gobject_, day, (GDateMonth)month, year); } -void Date::set_julian(guint32 julian_day) +void +Date::set_julian(guint32 julian_day) { g_date_set_julian(&gobject_, julian_day); } -Date& Date::add_days(int n_days) +Date& +Date::add_days(int n_days) { - if(n_days >= 0) + if (n_days >= 0) g_date_add_days(&gobject_, n_days); else g_date_subtract_days(&gobject_, -n_days); return *this; } -Date& Date::subtract_days(int n_days) +Date& +Date::subtract_days(int n_days) { - if(n_days >= 0) + if (n_days >= 0) g_date_subtract_days(&gobject_, n_days); else g_date_add_days(&gobject_, -n_days); return *this; } -Date& Date::add_months(int n_months) +Date& +Date::add_months(int n_months) { - if(n_months >= 0) + if (n_months >= 0) g_date_add_months(&gobject_, n_months); else g_date_subtract_months(&gobject_, -n_months); return *this; } -Date& Date::subtract_months(int n_months) +Date& +Date::subtract_months(int n_months) { - if(n_months >= 0) + if (n_months >= 0) g_date_subtract_months(&gobject_, n_months); else g_date_add_months(&gobject_, -n_months); return *this; } -Date& Date::add_years(int n_years) +Date& +Date::add_years(int n_years) { - if(n_years >= 0) + if (n_years >= 0) g_date_add_years(&gobject_, n_years); else g_date_subtract_years(&gobject_, -n_years); return *this; } -Date& Date::subtract_years(int n_years) +Date& +Date::subtract_years(int n_years) { - if(n_years >= 0) + if (n_years >= 0) g_date_subtract_years(&gobject_, n_years); else g_date_add_years(&gobject_, -n_years); return *this; } -int Date::days_between(const Date& rhs) const +int +Date::days_between(const Date& rhs) const { return g_date_days_between(&gobject_, &rhs.gobject_); } -int Date::compare(const Date& rhs) const +int +Date::compare(const Date& rhs) const { return g_date_compare(&gobject_, &rhs.gobject_); } -Date& Date::clamp(const Date& min_date, const Date& max_date) +Date& +Date::clamp(const Date& min_date, const Date& max_date) { g_date_clamp(&gobject_, &min_date.gobject_, &max_date.gobject_); return *this; } -Date& Date::clamp_min(const Date& min_date) +Date& +Date::clamp_min(const Date& min_date) { g_date_clamp(&gobject_, &min_date.gobject_, nullptr /* see the C docs */); return *this; } -Date& Date::clamp_max(const Date& max_date) +Date& +Date::clamp_max(const Date& max_date) { g_date_clamp(&gobject_, nullptr /* see the C docs */, &max_date.gobject_); return *this; } -void Date::order(Date& other) +void +Date::order(Date& other) { g_date_order(&gobject_, &other.gobject_); } -Date::Weekday Date::get_weekday() const +Date::Weekday +Date::get_weekday() const { - return (Date::Weekday) g_date_get_weekday(&gobject_); + return (Date::Weekday)g_date_get_weekday(&gobject_); } -Date::Month Date::get_month() const +Date::Month +Date::get_month() const { - return (Date::Month) g_date_get_month(&gobject_); + return (Date::Month)g_date_get_month(&gobject_); } -Date::Year Date::get_year() const +Date::Year +Date::get_year() const { return g_date_get_year(&gobject_); } -Date::Day Date::get_day() const +Date::Day +Date::get_day() const { return g_date_get_day(&gobject_); } -guint32 Date::get_julian() const +guint32 +Date::get_julian() const { return g_date_get_julian(&gobject_); } -unsigned int Date::get_day_of_year() const +unsigned int +Date::get_day_of_year() const { return g_date_get_day_of_year(&gobject_); } -unsigned int Date::get_monday_week_of_year() const +unsigned int +Date::get_monday_week_of_year() const { return g_date_get_monday_week_of_year(&gobject_); } -unsigned int Date::get_sunday_week_of_year() const +unsigned int +Date::get_sunday_week_of_year() const { return g_date_get_sunday_week_of_year(&gobject_); } -unsigned int Date::get_iso8601_week_of_year() const +unsigned int +Date::get_iso8601_week_of_year() const { return g_date_get_iso8601_week_of_year(&gobject_); } -bool Date::is_first_of_month() const +bool +Date::is_first_of_month() const { return g_date_is_first_of_month(&gobject_); } -bool Date::is_last_of_month() const +bool +Date::is_last_of_month() const { return g_date_is_last_of_month(&gobject_); } -//static -guint8 Date::get_days_in_month(Date::Month month, Date::Year year) +// static +guint8 +Date::get_days_in_month(Date::Month month, Date::Year year) { - return g_date_get_days_in_month((GDateMonth) month, year); + return g_date_get_days_in_month((GDateMonth)month, year); } -//static -guint8 Date::get_monday_weeks_in_year(Date::Year year) +// static +guint8 +Date::get_monday_weeks_in_year(Date::Year year) { return g_date_get_monday_weeks_in_year(year); } -//static -guint8 Date::get_sunday_weeks_in_year(Date::Year year) +// static +guint8 +Date::get_sunday_weeks_in_year(Date::Year year) { return g_date_get_sunday_weeks_in_year(year); } -//static -bool Date::is_leap_year(Date::Year year) +// static +bool +Date::is_leap_year(Date::Year year) { return g_date_is_leap_year(year); } -Glib::ustring Date::format_string(const Glib::ustring& format) const +Glib::ustring +Date::format_string(const Glib::ustring& format) const { struct tm tm_data; g_date_to_struct_tm(&gobject_, &tm_data); @@ -318,13 +355,12 @@ Glib::ustring Date::format_string(const Glib::ustring& format) const buf.get()[0] = '\1'; const auto len = strftime(buf.get(), bufsize, locale_format.c_str(), &tm_data); - if(len != 0 || buf.get()[0] == '\0') + if (len != 0 || buf.get()[0] == '\0') { g_assert(len < bufsize); return locale_to_utf8(std::string(buf.get(), len)); } - } - while((bufsize *= 2) <= 65536); + } while ((bufsize *= 2) <= 65536); // This error is quite unlikely (unless strftime is buggy). g_warning("Glib::Date::format_string(): maximum size of strftime buffer exceeded, giving up"); @@ -332,51 +368,58 @@ Glib::ustring Date::format_string(const Glib::ustring& format) const return Glib::ustring(); } -void Date::to_struct_tm(struct tm& dest) const +void +Date::to_struct_tm(struct tm& dest) const { g_date_to_struct_tm(&gobject_, &dest); } -bool Date::valid() const +bool +Date::valid() const { return g_date_valid(&gobject_); } -//static -bool Date::valid_day(Date::Day day) +// static +bool +Date::valid_day(Date::Day day) { return g_date_valid_day(day); } -//static -bool Date::valid_month(Date::Month month) +// static +bool +Date::valid_month(Date::Month month) { - return g_date_valid_month((GDateMonth) month); + return g_date_valid_month((GDateMonth)month); } -//static -bool Date::valid_year(Date::Year year) +// static +bool +Date::valid_year(Date::Year year) { return g_date_valid_year(year); } -//static -bool Date::valid_weekday(Date::Weekday weekday) +// static +bool +Date::valid_weekday(Date::Weekday weekday) { - return g_date_valid_weekday((GDateWeekday) weekday); + return g_date_valid_weekday((GDateWeekday)weekday); } -//static -bool Date::valid_julian(guint32 julian_day) +// static +bool +Date::valid_julian(guint32 julian_day) { return g_date_valid_julian(julian_day); } -//static -bool Date::valid_dmy(Date::Day day, Date::Month month, Date::Year year) +// static +bool +Date::valid_dmy(Date::Day day, Date::Month month, Date::Year year) { - return g_date_valid_dmy(day, (GDateMonth) month, year); + return g_date_valid_dmy(day, (GDateMonth)month, year); } } // namespace Glib - diff --git a/glib/src/datetime.ccg b/glib/src/datetime.ccg index f27df969..d47f05cd 100644 --- a/glib/src/datetime.ccg +++ b/glib/src/datetime.ccg @@ -23,4 +23,4 @@ namespace Glib { -}// namespace Glib +} // namespace Glib diff --git a/glib/src/fileutils.ccg b/glib/src/fileutils.ccg index 36385f68..eabe8e2c 100644 --- a/glib/src/fileutils.ccg +++ b/glib/src/fileutils.ccg @@ -18,7 +18,6 @@ #include <glib.h> #include <glibmm/utility.h> - namespace Glib { @@ -29,66 +28,65 @@ Dir::Dir(const std::string& path) GError* error = nullptr; gobject_ = g_dir_open(path.c_str(), 0, &error); - if(error) + if (error) Glib::Error::throw_exception(error); } -Dir::Dir(GDir* gobject) -: - gobject_ (gobject) -{} +Dir::Dir(GDir* gobject) : gobject_(gobject) +{ +} Dir::~Dir() { - if(gobject_) + if (gobject_) g_dir_close(gobject_); } -std::string Dir::read_name() +std::string +Dir::read_name() { - const char *const name = g_dir_read_name(gobject_); + const char* const name = g_dir_read_name(gobject_); return Glib::convert_const_gchar_ptr_to_stdstring(name); } -void Dir::rewind() +void +Dir::rewind() { g_dir_rewind(gobject_); } -void Dir::close() +void +Dir::close() { - if(gobject_) + if (gobject_) { g_dir_close(gobject_); gobject_ = nullptr; } } -DirIterator Dir::begin() +DirIterator +Dir::begin() { g_dir_rewind(gobject_); return DirIterator(gobject_, g_dir_read_name(gobject_)); } -DirIterator Dir::end() +DirIterator +Dir::end() { return DirIterator(gobject_, nullptr); } - /**** Glib::DirIterator ****************************************************/ -DirIterator::DirIterator() -: - gobject_ (nullptr), - current_ (nullptr) -{} +DirIterator::DirIterator() : gobject_(nullptr), current_(nullptr) +{ +} -DirIterator::DirIterator(GDir* gobject, const char* current) -: - gobject_ (gobject), - current_ (current) -{} +DirIterator::DirIterator(GDir* gobject, const char* current) : gobject_(gobject), current_(current) +{ +} std::string DirIterator::operator*() const { @@ -106,34 +104,39 @@ void DirIterator::operator++(int) current_ = g_dir_read_name(gobject_); } -bool DirIterator::operator==(const DirIterator& rhs) const +bool +DirIterator::operator==(const DirIterator& rhs) const { return (current_ == rhs.current_); } -bool DirIterator::operator!=(const DirIterator& rhs) const +bool +DirIterator::operator!=(const DirIterator& rhs) const { return (current_ != rhs.current_); } - -bool file_test(const std::string& filename, FileTest test) +bool +file_test(const std::string& filename, FileTest test) { return g_file_test(filename.c_str(), static_cast<GFileTest>(unsigned(test))); } -int mkstemp(std::string& filename_template) +int +mkstemp(std::string& filename_template) { - const auto buf = make_unique_ptr_gfree(g_strndup(filename_template.data(), filename_template.size())); + const auto buf = + make_unique_ptr_gfree(g_strndup(filename_template.data(), filename_template.size())); const auto fileno = g_mkstemp(buf.get()); filename_template = buf.get(); return fileno; } -int file_open_tmp(std::string& name_used, const std::string& prefix) +int +file_open_tmp(std::string& name_used, const std::string& prefix) { - std::string basename_template (prefix); + std::string basename_template(prefix); basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface GError* error = nullptr; @@ -141,58 +144,58 @@ int file_open_tmp(std::string& name_used, const std::string& prefix) const auto fileno = g_file_open_tmp(basename_template.c_str(), &pch_buf_name_used, &error); auto buf_name_used = make_unique_ptr_gfree(pch_buf_name_used); - if(error) + if (error) Glib::Error::throw_exception(error); name_used = buf_name_used.get(); return fileno; } -int file_open_tmp(std::string& name_used) +int +file_open_tmp(std::string& name_used) { GError* error = nullptr; char* pch_buf_name_used = nullptr; const auto fileno = g_file_open_tmp(nullptr, &pch_buf_name_used, &error); auto buf_name_used = make_unique_ptr_gfree(pch_buf_name_used); - if(error) + if (error) Glib::Error::throw_exception(error); name_used = buf_name_used.get(); return fileno; } -std::string file_get_contents(const std::string& filename) +std::string +file_get_contents(const std::string& filename) { - gsize length = 0; - GError* error = nullptr; + gsize length = 0; + GError* error = nullptr; char* pch_contents = nullptr; g_file_get_contents(filename.c_str(), &pch_contents, &length, &error); auto contents = make_unique_ptr_gfree(pch_contents); - if(error) + if (error) Glib::Error::throw_exception(error); return std::string(contents.get(), length); } void -file_set_contents(const std::string& filename, - const gchar *contents, - gssize length) +file_set_contents(const std::string& filename, const gchar* contents, gssize length) { - GError* error = nullptr; + GError* error = nullptr; g_file_set_contents(filename.c_str(), contents, length, &error); - if(error) + if (error) Glib::Error::throw_exception(error); } void -file_set_contents (const std::string& filename, const std::string& contents) +file_set_contents(const std::string& filename, const std::string& contents) { - file_set_contents(filename, contents.c_str(), contents.size()); + file_set_contents(filename, contents.c_str(), contents.size()); } } // namespace Glib diff --git a/glib/src/iochannel.ccg b/glib/src/iochannel.ccg index fc5bb6c2..7577a846 100644 --- a/glib/src/iochannel.ccg +++ b/glib/src/iochannel.ccg @@ -20,7 +20,6 @@ #include <glibmm/utility.h> #include <glibmm/main.h> - namespace { @@ -48,7 +47,9 @@ class ForeignIOChannel : public Glib::IOChannel { public: ForeignIOChannel(GIOChannel* gobject, bool take_copy) - : Glib::IOChannel(gobject, take_copy), ref_count_(0) {} + : Glib::IOChannel(gobject, take_copy), ref_count_(0) + { + } void reference() const override; void unreference() const override; @@ -57,69 +58,62 @@ private: mutable int ref_count_; }; -void ForeignIOChannel::reference() const +void +ForeignIOChannel::reference() const { ++ref_count_; } -void ForeignIOChannel::unreference() const +void +ForeignIOChannel::unreference() const { - if (!(--ref_count_)) delete this; + if (!(--ref_count_)) + delete this; } } // anonymous namespace - namespace Glib { class GlibmmIOChannel { public: - GIOChannel base; - Glib::IOChannel* wrapper; + GIOChannel base; + Glib::IOChannel* wrapper; static const GIOFuncs vfunc_table; - static GIOStatus io_read(GIOChannel* channel, char* buf, gsize count, - gsize* bytes_read, GError** err); + static GIOStatus io_read( + GIOChannel* channel, char* buf, gsize count, gsize* bytes_read, GError** err); - static GIOStatus io_write(GIOChannel* channel, const char* buf, gsize count, - gsize* bytes_written, GError** err); + static GIOStatus io_write( + GIOChannel* channel, const char* buf, gsize count, gsize* bytes_written, GError** err); - static GIOStatus io_seek (GIOChannel* channel, gint64 offset, GSeekType type, GError** err); + static GIOStatus io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err); static GIOStatus io_close(GIOChannel* channel, GError** err); - static GSource* io_create_watch(GIOChannel* channel, GIOCondition condition); - static void io_free(GIOChannel* channel); + static GSource* io_create_watch(GIOChannel* channel, GIOCondition condition); + static void io_free(GIOChannel* channel); static GIOStatus io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err); - static GIOFlags io_get_flags(GIOChannel* channel); + static GIOFlags io_get_flags(GIOChannel* channel); }; // static -const GIOFuncs GlibmmIOChannel::vfunc_table = -{ - &GlibmmIOChannel::io_read, - &GlibmmIOChannel::io_write, - &GlibmmIOChannel::io_seek, - &GlibmmIOChannel::io_close, - &GlibmmIOChannel::io_create_watch, - &GlibmmIOChannel::io_free, - &GlibmmIOChannel::io_set_flags, - &GlibmmIOChannel::io_get_flags, +const GIOFuncs GlibmmIOChannel::vfunc_table = { + &GlibmmIOChannel::io_read, &GlibmmIOChannel::io_write, &GlibmmIOChannel::io_seek, + &GlibmmIOChannel::io_close, &GlibmmIOChannel::io_create_watch, &GlibmmIOChannel::io_free, + &GlibmmIOChannel::io_set_flags, &GlibmmIOChannel::io_get_flags, }; - /**** GLib::IOChannel ******************************************************/ /* Construct a custom C++-implemented IOChannel. GlibmmIOChannel is an * extended GIOChannel struct which allows us to hook up a pointer to this * persistent wrapper instance. */ -IOChannel::IOChannel() -: - gobject_ (static_cast<GIOChannel*>(g_malloc(sizeof(GlibmmIOChannel)))) +IOChannel::IOChannel() : gobject_(static_cast<GIOChannel*>(g_malloc(sizeof(GlibmmIOChannel)))) { g_io_channel_init(gobject_); gobject_->funcs = const_cast<GIOFuncs*>(&GlibmmIOChannel::vfunc_table); @@ -127,14 +121,14 @@ IOChannel::IOChannel() reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = this; } -IOChannel::IOChannel(IOChannel&& other) noexcept -: sigc::trackable(std::move(other)), - gobject_(std::move(other.gobject_)) +IOChannel::IOChannel(IOChannel&& other) noexcept : sigc::trackable(std::move(other)), + gobject_(std::move(other.gobject_)) { other.gobject_ = nullptr; } -IOChannel& IOChannel::operator=(IOChannel&& other) noexcept +IOChannel& +IOChannel::operator=(IOChannel&& other) noexcept { sigc::trackable::operator=(std::move(other)); @@ -150,21 +144,20 @@ IOChannel& IOChannel::operator=(IOChannel&& other) noexcept * See the comment at the top of this file for an explanation of the * problems with this approach. */ -IOChannel::IOChannel(GIOChannel* gobject, bool take_copy) -: - gobject_ (gobject) +IOChannel::IOChannel(GIOChannel* gobject, bool take_copy) : gobject_(gobject) { // This ctor should never be called for GlibmmIOChannel instances. g_assert(gobject != nullptr); g_assert(gobject->funcs != &GlibmmIOChannel::vfunc_table); - if(take_copy) + if (take_copy) g_io_channel_ref(gobject_); } -void IOChannel::release_gobject() +void +IOChannel::release_gobject() { - if(gobject_) + if (gobject_) { // Check whether this IOChannel is implemented in C++, i.e. whether it // uses our GlibmmIOChannel forwarding backend. Normally, this will never @@ -173,7 +166,7 @@ void IOChannel::release_gobject() // of a derived class threw an exception the GIOChannel must be destroyed // prematurely. // - if(gobject_->funcs == &GlibmmIOChannel::vfunc_table) + if (gobject_->funcs == &GlibmmIOChannel::vfunc_table) { // Disconnect the wrapper object so that it won't be deleted twice. reinterpret_cast<GlibmmIOChannel*>(gobject_)->wrapper = nullptr; @@ -191,12 +184,13 @@ IOChannel::~IOChannel() release_gobject(); } -Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, const std::string& mode) +Glib::RefPtr<IOChannel> +IOChannel::create_from_file(const std::string& filename, const std::string& mode) { GError* gerror = nullptr; const auto channel = g_io_channel_new_file(filename.c_str(), mode.c_str(), &gerror); - if(gerror) + if (gerror) { Glib::Error::throw_exception(gerror); } @@ -204,132 +198,143 @@ Glib::RefPtr<IOChannel> IOChannel::create_from_file(const std::string& filename, return Glib::wrap(channel, false); } -Glib::RefPtr<IOChannel> IOChannel::create_from_fd(int fd) +Glib::RefPtr<IOChannel> +IOChannel::create_from_fd(int fd) { return Glib::wrap(g_io_channel_unix_new(fd), false); } #ifdef G_OS_WIN32 -Glib::RefPtr<IOChannel> IOChannel::create_from_win32_fd(int fd) +Glib::RefPtr<IOChannel> +IOChannel::create_from_win32_fd(int fd) { return Glib::wrap(g_io_channel_win32_new_fd(fd), false); } -Glib::RefPtr<IOChannel> IOChannel::create_from_win32_socket(int socket) +Glib::RefPtr<IOChannel> +IOChannel::create_from_win32_socket(int socket) { return Glib::wrap(g_io_channel_win32_new_socket(socket), false); } #endif /* G_OS_WIN32 */ -IOStatus IOChannel::write(const Glib::ustring& str) +IOStatus +IOChannel::write(const Glib::ustring& str) { gsize bytes_written = 0; return write(str.data(), str.bytes(), bytes_written); } -IOStatus IOChannel::read_line(Glib::ustring& line) +IOStatus +IOChannel::read_line(Glib::ustring& line) { GError* gerror = nullptr; - gsize bytes = 0; + gsize bytes = 0; char* pch_buf = nullptr; const auto status = g_io_channel_read_line(gobj(), &pch_buf, &bytes, nullptr, &gerror); auto buf = make_unique_ptr_gfree(pch_buf); - if(gerror) + if (gerror) { Glib::Error::throw_exception(gerror); } - if(buf.get()) + if (buf.get()) line.assign(buf.get(), buf.get() + bytes); else line.erase(); - return (IOStatus) status; + return (IOStatus)status; } -IOStatus IOChannel::read_to_end(Glib::ustring& str) +IOStatus +IOChannel::read_to_end(Glib::ustring& str) { GError* gerror = nullptr; - gsize bytes = 0; + gsize bytes = 0; char* pch_buf = nullptr; const auto status = g_io_channel_read_to_end(gobj(), &pch_buf, &bytes, &gerror); auto buf = make_unique_ptr_gfree(pch_buf); - if(gerror) + if (gerror) { Glib::Error::throw_exception(gerror); } - if(buf.get()) + if (buf.get()) str.assign(buf.get(), buf.get() + bytes); else str.erase(); - return (IOStatus) status; + return (IOStatus)status; } -IOStatus IOChannel::read(Glib::ustring& str, gsize count) +IOStatus +IOChannel::read(Glib::ustring& str, gsize count) { auto buf = make_unique_ptr_gfree(g_new(char, count)); GError* gerror = nullptr; - gsize bytes = 0; + gsize bytes = 0; const auto status = g_io_channel_read_chars(gobj(), buf.get(), count, &bytes, &gerror); - if(gerror) + if (gerror) { Glib::Error::throw_exception(gerror); } - if(buf.get()) + if (buf.get()) str.assign(buf.get(), buf.get() + bytes); else str.erase(); - return (IOStatus) status; + return (IOStatus)status; } -IOStatus IOChannel::set_encoding(const std::string& encoding) +IOStatus +IOChannel::set_encoding(const std::string& encoding) { GError* gerror = nullptr; - const auto status = g_io_channel_set_encoding( - gobj(), Glib::c_str_or_nullptr(encoding), &gerror); + const auto status = g_io_channel_set_encoding(gobj(), Glib::c_str_or_nullptr(encoding), &gerror); - if(gerror) + if (gerror) { Glib::Error::throw_exception(gerror); } - return (IOStatus) status; + return (IOStatus)status; } -std::string IOChannel::get_encoding() const +std::string +IOChannel::get_encoding() const { - const char *const encoding = g_io_channel_get_encoding(gobject_); + const char* const encoding = g_io_channel_get_encoding(gobject_); return convert_const_gchar_ptr_to_stdstring(encoding); } -void IOChannel::set_line_term(const std::string& term) +void +IOChannel::set_line_term(const std::string& term) { - if(term.empty()) + if (term.empty()) g_io_channel_set_line_term(gobj(), nullptr, 0); else g_io_channel_set_line_term(gobj(), term.data(), term.size()); } -std::string IOChannel::get_line_term() const +std::string +IOChannel::get_line_term() const { int len = 0; - const char *const term = g_io_channel_get_line_term(gobject_, &len); + const char* const term = g_io_channel_get_line_term(gobject_, &len); return (term) ? std::string(term, len) : std::string(); } -Glib::RefPtr<IOSource> IOChannel::create_watch(IOCondition condition) +Glib::RefPtr<IOSource> +IOChannel::create_watch(IOCondition condition) { // The corresponding unreference() takes place in the dtor // of the Glib::RefPtr<IOChannel> object below. @@ -337,13 +342,15 @@ Glib::RefPtr<IOSource> IOChannel::create_watch(IOCondition condition) return IOSource::create(Glib::RefPtr<IOChannel>(this), condition); } -IOStatus IOChannel::read_vfunc(char*, gsize, gsize&) +IOStatus +IOChannel::read_vfunc(char*, gsize, gsize&) { g_assert_not_reached(); return IO_STATUS_ERROR; } -IOStatus IOChannel::write_vfunc(const char*, gsize, gsize&) +IOStatus +IOChannel::write_vfunc(const char*, gsize, gsize&) { g_assert_not_reached(); return IO_STATUS_ERROR; @@ -355,7 +362,8 @@ IOStatus IOChannel::seek_vfunc(gint64, SeekType) return IO_STATUS_ERROR; } -IOStatus IOChannel::close_vfunc() +IOStatus +IOChannel::close_vfunc() { g_assert_not_reached(); return IO_STATUS_ERROR; @@ -373,33 +381,37 @@ IOStatus IOChannel::set_flags_vfunc(IOFlags) return IO_STATUS_ERROR; } -IOFlags IOChannel::get_flags_vfunc() +IOFlags +IOChannel::get_flags_vfunc() { g_assert_not_reached(); return IOFlags(0); } -void IOChannel::reference() const +void +IOChannel::reference() const { g_io_channel_ref(gobject_); } -void IOChannel::unreference() const +void +IOChannel::unreference() const { g_io_channel_unref(gobject_); } -Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy) +Glib::RefPtr<IOChannel> +wrap(GIOChannel* gobject, bool take_copy) { IOChannel* cpp_object = nullptr; - if(gobject) + if (gobject) { - if(gobject->funcs == &GlibmmIOChannel::vfunc_table) + if (gobject->funcs == &GlibmmIOChannel::vfunc_table) { cpp_object = reinterpret_cast<GlibmmIOChannel*>(gobject)->wrapper; - if(take_copy && cpp_object) + if (take_copy && cpp_object) cpp_object->reference(); } else @@ -412,23 +424,23 @@ Glib::RefPtr<IOChannel> wrap(GIOChannel* gobject, bool take_copy) return Glib::RefPtr<IOChannel>(cpp_object); } - /**** Glib::GlibmmIOChannel ************************************************/ -GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count, - gsize* bytes_read, GError** err) +GIOStatus +GlibmmIOChannel::io_read( + GIOChannel* channel, char* buf, gsize count, gsize* bytes_read, GError** err) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOStatus) wrapper->read_vfunc(buf, count, *bytes_read); + return (GIOStatus)wrapper->read_vfunc(buf, count, *bytes_read); } - catch(Glib::Error& error) + catch (Glib::Error& error) { error.propagate(err); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -436,20 +448,21 @@ GIOStatus GlibmmIOChannel::io_read(GIOChannel* channel, char* buf, gsize count, return G_IO_STATUS_ERROR; } -GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize count, - gsize* bytes_written, GError** err) +GIOStatus +GlibmmIOChannel::io_write( + GIOChannel* channel, const char* buf, gsize count, gsize* bytes_written, GError** err) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOStatus) wrapper->write_vfunc(buf, count, *bytes_written); + return (GIOStatus)wrapper->write_vfunc(buf, count, *bytes_written); } - catch(Glib::Error& error) + catch (Glib::Error& error) { error.propagate(err); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -457,19 +470,20 @@ GIOStatus GlibmmIOChannel::io_write(GIOChannel* channel, const char* buf, gsize return G_IO_STATUS_ERROR; } -GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err) +GIOStatus +GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType type, GError** err) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOStatus) wrapper->seek_vfunc(offset, (SeekType) type); + return (GIOStatus)wrapper->seek_vfunc(offset, (SeekType)type); } - catch(Glib::Error& error) + catch (Glib::Error& error) { error.propagate(err); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -477,38 +491,39 @@ GIOStatus GlibmmIOChannel::io_seek(GIOChannel* channel, gint64 offset, GSeekType return G_IO_STATUS_ERROR; } -GIOStatus GlibmmIOChannel::io_close(GIOChannel* channel, GError** err) +GIOStatus +GlibmmIOChannel::io_close(GIOChannel* channel, GError** err) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOStatus) wrapper->close_vfunc(); + return (GIOStatus)wrapper->close_vfunc(); } - catch(Glib::Error& error) + catch (Glib::Error& error) { error.propagate(err); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } - return G_IO_STATUS_ERROR; } // static -GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition condition) +GSource* +GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition condition) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - const auto source = wrapper->create_watch_vfunc((IOCondition) condition); + const auto source = wrapper->create_watch_vfunc((IOCondition)condition); return (source) ? source->gobj_copy() : nullptr; } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -517,9 +532,10 @@ GSource* GlibmmIOChannel::io_create_watch(GIOChannel* channel, GIOCondition cond } // static -void GlibmmIOChannel::io_free(GIOChannel* channel) +void +GlibmmIOChannel::io_free(GIOChannel* channel) { - if(IOChannel *const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper) + if (IOChannel* const wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper) { wrapper->gobject_ = nullptr; delete wrapper; @@ -528,19 +544,20 @@ void GlibmmIOChannel::io_free(GIOChannel* channel) g_free(channel); } -GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err) +GIOStatus +GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GError** err) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOStatus) wrapper->set_flags_vfunc((IOFlags) flags); + return (GIOStatus)wrapper->set_flags_vfunc((IOFlags)flags); } - catch(Glib::Error& error) + catch (Glib::Error& error) { error.propagate(err); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -549,15 +566,16 @@ GIOStatus GlibmmIOChannel::io_set_flags(GIOChannel* channel, GIOFlags flags, GEr } // static -GIOFlags GlibmmIOChannel::io_get_flags(GIOChannel* channel) +GIOFlags +GlibmmIOChannel::io_get_flags(GIOChannel* channel) { const auto wrapper = reinterpret_cast<GlibmmIOChannel*>(channel)->wrapper; try { - return (GIOFlags) wrapper->get_flags_vfunc(); + return (GIOFlags)wrapper->get_flags_vfunc(); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } diff --git a/glib/src/keyfile.ccg b/glib/src/keyfile.ccg index 6487cbc1..65e2fb67 100644 --- a/glib/src/keyfile.ccg +++ b/glib/src/keyfile.ccg @@ -32,15 +32,15 @@ KeyFile::KeyFile(GKeyFile* castitem, bool takes_ownership) owns_gobject_ = takes_ownership; } -KeyFile::KeyFile(KeyFile&& other) noexcept -: gobject_(std::move(other.gobject_)), - owns_gobject_(std::move(other.owns_gobject_)) +KeyFile::KeyFile(KeyFile&& other) noexcept : gobject_(std::move(other.gobject_)), + owns_gobject_(std::move(other.owns_gobject_)) { other.gobject_ = nullptr; other.owns_gobject_ = false; } -KeyFile& KeyFile::operator=(KeyFile&& other) noexcept +KeyFile& +KeyFile::operator=(KeyFile&& other) noexcept { if (owns_gobject_) g_key_file_free(gobject_); @@ -60,35 +60,33 @@ KeyFile::~KeyFile() g_key_file_free(gobject_); } -bool KeyFile::load_from_data(const Glib::ustring& data, KeyFileFlags flags) +bool +KeyFile::load_from_data(const Glib::ustring& data, KeyFileFlags flags) { GError* gerror = nullptr; const gboolean result = g_key_file_load_from_data( - gobj(), data.c_str(), data.bytes(), - static_cast<GKeyFileFlags>(unsigned(flags)), - &gerror); + gobj(), data.c_str(), data.bytes(), static_cast<GKeyFileFlags>(unsigned(flags)), &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return (result != 0); } -bool KeyFile::load_from_data_dirs(const std::string& file, std::string& full_path, KeyFileFlags flags) +bool +KeyFile::load_from_data_dirs(const std::string& file, std::string& full_path, KeyFileFlags flags) { GError* gerror = nullptr; char* full_path_c = nullptr; const gboolean result = g_key_file_load_from_data_dirs( - gobj(), file.c_str(), &full_path_c, - static_cast<GKeyFileFlags>(unsigned(flags)), - &gerror); + gobj(), file.c_str(), &full_path_c, static_cast<GKeyFileFlags>(unsigned(flags)), &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); - if(full_path_c) + if (full_path_c) full_path = Glib::make_unique_ptr_gfree(full_path_c).get(); else full_path.erase(); @@ -96,17 +94,18 @@ bool KeyFile::load_from_data_dirs(const std::string& file, std::string& full_pat return (result != 0); } -bool KeyFile::load_from_dirs(const std::string& file, const Glib::ArrayHandle<std::string>& search_dirs, std::string& full_path, KeyFileFlags flags) +bool +KeyFile::load_from_dirs(const std::string& file, const Glib::ArrayHandle<std::string>& search_dirs, + std::string& full_path, KeyFileFlags flags) { GError* gerror = nullptr; char* full_path_c = nullptr; - const gboolean result = g_key_file_load_from_dirs( - gobj(), file.c_str(), const_cast<const gchar**>(search_dirs.data()), - &full_path_c, static_cast<GKeyFileFlags>(unsigned(flags)), - &gerror); + const gboolean result = + g_key_file_load_from_dirs(gobj(), file.c_str(), const_cast<const gchar**>(search_dirs.data()), + &full_path_c, static_cast<GKeyFileFlags>(unsigned(flags)), &gerror); - if(gerror) + if (gerror) { if (full_path_c) { @@ -115,7 +114,7 @@ bool KeyFile::load_from_dirs(const std::string& file, const Glib::ArrayHandle<st Glib::Error::throw_exception(gerror); } - if(full_path_c) + if (full_path_c) full_path = Glib::make_unique_ptr_gfree(full_path_c).get(); else full_path.erase(); @@ -123,18 +122,20 @@ bool KeyFile::load_from_dirs(const std::string& file, const Glib::ArrayHandle<st return (result != 0); } -Glib::ustring KeyFile::to_data() +Glib::ustring +KeyFile::to_data() { GError* gerror = nullptr; - char *const str = g_key_file_to_data(gobj(), nullptr, &gerror); + char* const str = g_key_file_to_data(gobj(), nullptr, &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return Glib::convert_return_gchar_ptr_to_ustring(str); } -Glib::ArrayHandle<Glib::ustring> KeyFile::get_groups() const +Glib::ArrayHandle<Glib::ustring> +KeyFile::get_groups() const { gsize length = 0; char** const array = g_key_file_get_groups(const_cast<GKeyFile*>(gobj()), &length); @@ -142,247 +143,249 @@ Glib::ArrayHandle<Glib::ustring> KeyFile::get_groups() const return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP); } -Glib::ArrayHandle<Glib::ustring> KeyFile::get_keys(const Glib::ustring& group_name) const +Glib::ArrayHandle<Glib::ustring> +KeyFile::get_keys(const Glib::ustring& group_name) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; char** const array = g_key_file_get_keys( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - &length, &gerror); + const_cast<GKeyFile*>(gobj()), Glib::c_str_or_nullptr(group_name), &length, &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP); } -Glib::ustring KeyFile::get_locale_string(const Glib::ustring& group_name, - const Glib::ustring& key) const +Glib::ustring +KeyFile::get_locale_string(const Glib::ustring& group_name, const Glib::ustring& key) const { GError* gerror = nullptr; - char *const str = g_key_file_get_locale_string( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - key.c_str(), nullptr, &gerror); + char* const str = g_key_file_get_locale_string(const_cast<GKeyFile*>(gobj()), + Glib::c_str_or_nullptr(group_name), key.c_str(), nullptr, &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return Glib::convert_return_gchar_ptr_to_ustring(str); } -bool KeyFile::get_boolean(const Glib::ustring& key) const +bool +KeyFile::get_boolean(const Glib::ustring& key) const { GError* gerror = nullptr; - const bool value = - static_cast<bool>(g_key_file_get_boolean(const_cast<GKeyFile*>(gobj()), - nullptr, key.c_str(), &gerror)); - if(gerror) + const bool value = static_cast<bool>( + g_key_file_get_boolean(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &gerror)); + if (gerror) Glib::Error::throw_exception(gerror); return value; } -int KeyFile::get_integer(const Glib::ustring& key) const +int +KeyFile::get_integer(const Glib::ustring& key) const { GError* gerror = nullptr; - const int value = g_key_file_get_integer(const_cast<GKeyFile*>(gobj()), - nullptr, key.c_str(), &gerror); - if(gerror) + const int value = + g_key_file_get_integer(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &gerror); + if (gerror) Glib::Error::throw_exception(gerror); return value; } -gint64 KeyFile::get_int64(const Glib::ustring& key) const +gint64 +KeyFile::get_int64(const Glib::ustring& key) const { GError* gerror = nullptr; - const gint64 value = g_key_file_get_int64(const_cast<GKeyFile*>(gobj()), nullptr, - key.c_str(), &gerror); + const gint64 value = + g_key_file_get_int64(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return value; } -guint64 KeyFile::get_uint64(const Glib::ustring& key) const +guint64 +KeyFile::get_uint64(const Glib::ustring& key) const { GError* gerror = nullptr; - const guint64 value = g_key_file_get_uint64(const_cast<GKeyFile*>(gobj()), - nullptr, key.c_str(), &gerror); + const guint64 value = + g_key_file_get_uint64(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return value; } -double KeyFile::get_double(const Glib::ustring& key) const +double +KeyFile::get_double(const Glib::ustring& key) const { GError* gerror = nullptr; - double retvalue = g_key_file_get_double(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &(gerror)); + double retvalue = + g_key_file_get_double(const_cast<GKeyFile*>(gobj()), nullptr, key.c_str(), &(gerror)); - if(gerror) + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -void KeyFile::set_double(const Glib::ustring& key, double value) +void +KeyFile::set_double(const Glib::ustring& key, double value) { g_key_file_set_double(gobj(), nullptr, key.c_str(), value); } -# define GLIBMM_ERROR_ARG -# define GLIBMM_THROW(err) if (err) Glib::Error::throw_exception(err) +#define GLIBMM_ERROR_ARG +#define GLIBMM_THROW(err) \ + if (err) \ + Glib::Error::throw_exception(err) -Glib::ArrayHandle<Glib::ustring> KeyFile::get_string_list(const Glib::ustring& group_name, - const Glib::ustring& key - GLIBMM_ERROR_ARG) const +Glib::ArrayHandle<Glib::ustring> +KeyFile::get_string_list( + const Glib::ustring& group_name, const Glib::ustring& key GLIBMM_ERROR_ARG) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; - char** const array = g_key_file_get_string_list( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - key.c_str(), &length, &gerror); + char** const array = g_key_file_get_string_list(const_cast<GKeyFile*>(gobj()), + Glib::c_str_or_nullptr(group_name), key.c_str(), &length, &gerror); GLIBMM_THROW(gerror); return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP); } -Glib::ArrayHandle<Glib::ustring> KeyFile::get_locale_string_list(const Glib::ustring& group_name, - const Glib::ustring& key, - const Glib::ustring& locale - GLIBMM_ERROR_ARG) const +Glib::ArrayHandle<Glib::ustring> +KeyFile::get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, + const Glib::ustring& locale GLIBMM_ERROR_ARG) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; - char** const array = g_key_file_get_locale_string_list( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - key.c_str(), locale.c_str(), &length, &gerror); + char** const array = g_key_file_get_locale_string_list(const_cast<GKeyFile*>(gobj()), + Glib::c_str_or_nullptr(group_name), key.c_str(), locale.c_str(), &length, &gerror); GLIBMM_THROW(gerror); return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP); } -Glib::ArrayHandle<bool> KeyFile::get_boolean_list(const Glib::ustring& group_name, - const Glib::ustring& key - GLIBMM_ERROR_ARG) const +Glib::ArrayHandle<bool> +KeyFile::get_boolean_list( + const Glib::ustring& group_name, const Glib::ustring& key GLIBMM_ERROR_ARG) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; - gboolean *const array = g_key_file_get_boolean_list( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - key.c_str(), &length, &gerror); + gboolean* const array = g_key_file_get_boolean_list(const_cast<GKeyFile*>(gobj()), + Glib::c_str_or_nullptr(group_name), key.c_str(), &length, &gerror); GLIBMM_THROW(gerror); return Glib::ArrayHandle<bool>(array, length, Glib::OWNERSHIP_SHALLOW); } -Glib::ArrayHandle<int> KeyFile::get_integer_list(const Glib::ustring& group_name, - const Glib::ustring& key - GLIBMM_ERROR_ARG) const +Glib::ArrayHandle<int> +KeyFile::get_integer_list( + const Glib::ustring& group_name, const Glib::ustring& key GLIBMM_ERROR_ARG) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; - int *const array = g_key_file_get_integer_list( - const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - key.c_str(), &length, &gerror); + int* const array = g_key_file_get_integer_list(const_cast<GKeyFile*>(gobj()), + Glib::c_str_or_nullptr(group_name), key.c_str(), &length, &gerror); GLIBMM_THROW(gerror); return Glib::ArrayHandle<int>(array, length, Glib::OWNERSHIP_SHALLOW); } -Glib::ArrayHandle<double> KeyFile::get_double_list(const Glib::ustring& group_name, - const Glib::ustring& key - GLIBMM_ERROR_ARG) const +Glib::ArrayHandle<double> +KeyFile::get_double_list( + const Glib::ustring& group_name, const Glib::ustring& key GLIBMM_ERROR_ARG) const { - gsize length = 0; + gsize length = 0; GError* gerror = nullptr; - double *const array = g_key_file_get_double_list(const_cast<GKeyFile*>(gobj()), - group_name.c_str(), key.c_str(), - &length, &gerror); + double* const array = g_key_file_get_double_list( + const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length, &gerror); GLIBMM_THROW(gerror); return Glib::ArrayHandle<double>(array, length, Glib::OWNERSHIP_SHALLOW); } -void KeyFile::set_string_list(const Glib::ustring& group_name, const Glib::ustring& key, - const Glib::ArrayHandle<Glib::ustring>& list) +void +KeyFile::set_string_list(const Glib::ustring& group_name, const Glib::ustring& key, + const Glib::ArrayHandle<Glib::ustring>& list) { - g_key_file_set_string_list(gobj(), Glib::c_str_or_nullptr(group_name), - key.c_str(), list.data(), list.size()); + g_key_file_set_string_list( + gobj(), Glib::c_str_or_nullptr(group_name), key.c_str(), list.data(), list.size()); } -void KeyFile::set_locale_string_list(const Glib::ustring& group_name, - const Glib::ustring& key, const Glib::ustring& locale, - const Glib::ArrayHandle<Glib::ustring>& list) +void +KeyFile::set_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, + const Glib::ustring& locale, const Glib::ArrayHandle<Glib::ustring>& list) { - g_key_file_set_locale_string_list(gobj(), Glib::c_str_or_nullptr(group_name), - key.c_str(), locale.c_str(), list.data(), list.size()); + g_key_file_set_locale_string_list(gobj(), Glib::c_str_or_nullptr(group_name), key.c_str(), + locale.c_str(), list.data(), list.size()); } -void KeyFile::set_integer_list(const Glib::ustring& group_name, const Glib::ustring& key, - const Glib::ArrayHandle<int>& list) +void +KeyFile::set_integer_list( + const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle<int>& list) { - g_key_file_set_integer_list(gobj(), Glib::c_str_or_nullptr(group_name), - key.c_str(), const_cast<int*>(list.data()), list.size()); + g_key_file_set_integer_list(gobj(), Glib::c_str_or_nullptr(group_name), key.c_str(), + const_cast<int*>(list.data()), list.size()); } -void KeyFile::set_double_list(const Glib::ustring& group_name, const Glib::ustring& key, - const Glib::ArrayHandle<double>& list) +void +KeyFile::set_double_list( + const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle<double>& list) { - g_key_file_set_double_list(gobj(), group_name.c_str(), key.c_str(), - const_cast<double*>(list.data()), list.size()); + g_key_file_set_double_list( + gobj(), group_name.c_str(), key.c_str(), const_cast<double*>(list.data()), list.size()); } -void KeyFile::set_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key, - const Glib::ArrayHandle<bool>& list) +void +KeyFile::set_boolean_list( + const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ArrayHandle<bool>& list) { - g_key_file_set_boolean_list(gobj(), Glib::c_str_or_nullptr(group_name), - key.c_str(), const_cast<gboolean*>(list.data()), list.size()); + g_key_file_set_boolean_list(gobj(), Glib::c_str_or_nullptr(group_name), key.c_str(), + const_cast<gboolean*>(list.data()), list.size()); } -Glib::ustring KeyFile::get_comment() const +Glib::ustring +KeyFile::get_comment() const { GError* gerror = nullptr; - char *const str = g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), nullptr, nullptr, &gerror); + char* const str = + g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), nullptr, nullptr, &gerror); GLIBMM_THROW(gerror); return Glib::convert_return_gchar_ptr_to_ustring(str); } -Glib::ustring KeyFile::get_comment(const Glib::ustring& group_name GLIBMM_ERROR_ARG) const +Glib::ustring +KeyFile::get_comment(const Glib::ustring& group_name GLIBMM_ERROR_ARG) const { GError* gerror = nullptr; - char *const str = g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), - Glib::c_str_or_nullptr(group_name), - nullptr, &gerror); + char* const str = g_key_file_get_comment( + const_cast<GKeyFile*>(gobj()), Glib::c_str_or_nullptr(group_name), nullptr, &gerror); GLIBMM_THROW(gerror); return Glib::convert_return_gchar_ptr_to_ustring(str); } -void KeyFile::set_comment(const Glib::ustring& comment GLIBMM_ERROR_ARG) +void +KeyFile::set_comment(const Glib::ustring& comment GLIBMM_ERROR_ARG) { GError* gerror = nullptr; g_key_file_set_comment(gobj(), nullptr, nullptr, comment.c_str(), &gerror); @@ -390,12 +393,12 @@ void KeyFile::set_comment(const Glib::ustring& comment GLIBMM_ERROR_ARG) GLIBMM_THROW(gerror); } -void KeyFile::set_comment(const Glib::ustring& group_name, const Glib::ustring& comment - GLIBMM_ERROR_ARG) +void +KeyFile::set_comment(const Glib::ustring& group_name, const Glib::ustring& comment GLIBMM_ERROR_ARG) { GError* gerror = nullptr; - g_key_file_set_comment(gobj(), Glib::c_str_or_nullptr(group_name), - nullptr, comment.c_str(), &gerror); + g_key_file_set_comment( + gobj(), Glib::c_str_or_nullptr(group_name), nullptr, comment.c_str(), &gerror); GLIBMM_THROW(gerror); } diff --git a/glib/src/markup.ccg b/glib/src/markup.ccg index f04b2fbf..4e2bf54e 100644 --- a/glib/src/markup.ccg +++ b/glib/src/markup.ccg @@ -20,28 +20,27 @@ #include <glibmm/utility.h> #include <glib.h> - namespace Glib { namespace Markup { -Glib::ustring escape_text(const Glib::ustring& text) +Glib::ustring +escape_text(const Glib::ustring& text) { const auto buf = make_unique_ptr_gfree(g_markup_escape_text(text.data(), text.bytes())); return Glib::ustring(buf.get()); } - /**** Glib::Markup::AttributeKeyLess ***************************************/ -bool AttributeKeyLess::operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const +bool +AttributeKeyLess::operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const { return (lhs.raw() < rhs.raw()); } - /**** Glib::Markup::ParserCallbacks ****************************************/ class ParserCallbacks @@ -49,51 +48,29 @@ class ParserCallbacks public: static const GMarkupParser vfunc_table; - static void start_element(GMarkupParseContext* context, - const char* element_name, - const char** attribute_names, - const char** attribute_values, - void* user_data, - GError** error); - - static void end_element(GMarkupParseContext* context, - const char* element_name, - void* user_data, - GError** error); - - static void text(GMarkupParseContext* context, - const char* text, - gsize text_len, - void* user_data, - GError** error); - - static void passthrough(GMarkupParseContext* context, - const char* passthrough_text, - gsize text_len, - void* user_data, - GError** error); - - static void error(GMarkupParseContext* context, - GError* error, - void* user_data); -}; + static void start_element(GMarkupParseContext* context, const char* element_name, + const char** attribute_names, const char** attribute_values, void* user_data, GError** error); + static void end_element( + GMarkupParseContext* context, const char* element_name, void* user_data, GError** error); -const GMarkupParser ParserCallbacks::vfunc_table = -{ - &ParserCallbacks::start_element, - &ParserCallbacks::end_element, - &ParserCallbacks::text, - &ParserCallbacks::passthrough, - &ParserCallbacks::error, + static void text(GMarkupParseContext* context, const char* text, gsize text_len, void* user_data, + GError** error); + + static void passthrough(GMarkupParseContext* context, const char* passthrough_text, + gsize text_len, void* user_data, GError** error); + + static void error(GMarkupParseContext* context, GError* error, void* user_data); }; -void ParserCallbacks::start_element(GMarkupParseContext* context, - const char* element_name, - const char** attribute_names, - const char** attribute_values, - void* user_data, - GError** error) +const GMarkupParser ParserCallbacks::vfunc_table = { + &ParserCallbacks::start_element, &ParserCallbacks::end_element, &ParserCallbacks::text, + &ParserCallbacks::passthrough, &ParserCallbacks::error, +}; + +void +ParserCallbacks::start_element(GMarkupParseContext* context, const char* element_name, + const char** attribute_names, const char** attribute_values, void* user_data, GError** error) { ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); @@ -102,12 +79,12 @@ void ParserCallbacks::start_element(GMarkupParseContext* context, { Parser::AttributeMap attributes; - if(attribute_names && attribute_values) + if (attribute_names && attribute_values) { - const char *const * pname = attribute_names; - const char *const * pvalue = attribute_values; + const char* const* pname = attribute_names; + const char* const* pvalue = attribute_values; - for(; *pname && *pvalue; ++pname, ++pvalue) + for (; *pname && *pvalue; ++pname, ++pvalue) attributes.insert(Parser::AttributeMap::value_type(*pname, *pvalue)); g_return_if_fail(*pname == nullptr && *pvalue == nullptr); @@ -115,20 +92,19 @@ void ParserCallbacks::start_element(GMarkupParseContext* context, cpp_context.get_parser()->on_start_element(cpp_context, element_name, attributes); } - catch(MarkupError& err) + catch (MarkupError& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } -void ParserCallbacks::end_element(GMarkupParseContext* context, - const char* element_name, - void* user_data, - GError** error) +void +ParserCallbacks::end_element( + GMarkupParseContext* context, const char* element_name, void* user_data, GError** error) { ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); @@ -137,21 +113,19 @@ void ParserCallbacks::end_element(GMarkupParseContext* context, { cpp_context.get_parser()->on_end_element(cpp_context, element_name); } - catch(MarkupError& err) + catch (MarkupError& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } -void ParserCallbacks::text(GMarkupParseContext* context, - const char* text, - gsize text_len, - void* user_data, - GError** error) +void +ParserCallbacks::text( + GMarkupParseContext* context, const char* text, gsize text_len, void* user_data, GError** error) { ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); @@ -160,21 +134,19 @@ void ParserCallbacks::text(GMarkupParseContext* context, { cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len)); } - catch(MarkupError& err) + catch (MarkupError& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } -void ParserCallbacks::passthrough(GMarkupParseContext* context, - const char* passthrough_text, - gsize text_len, - void* user_data, - GError** error) +void +ParserCallbacks::passthrough(GMarkupParseContext* context, const char* passthrough_text, + gsize text_len, void* user_data, GError** error) { ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); g_return_if_fail(context == cpp_context.gobj()); @@ -182,21 +154,20 @@ void ParserCallbacks::passthrough(GMarkupParseContext* context, try { cpp_context.get_parser()->on_passthrough( - cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len)); + cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len)); } - catch(MarkupError& err) + catch (MarkupError& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } -void ParserCallbacks::error(GMarkupParseContext* context, - GError* error, - void* user_data) +void +ParserCallbacks::error(GMarkupParseContext* context, GError* error, void* user_data) { ParseContext& cpp_context = *static_cast<ParseContext*>(user_data); @@ -207,65 +178,75 @@ void ParserCallbacks::error(GMarkupParseContext* context, { cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error))); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } - /**** Glib::Markup::Parser *************************************************/ Parser::Parser() -{} +{ +} -Parser::Parser(Parser&& other) noexcept -: sigc::trackable(std::move(other)) +Parser::Parser(Parser&& other) noexcept : sigc::trackable(std::move(other)) { } -Parser& Parser::operator=(Parser&& other) noexcept +Parser& +Parser::operator=(Parser&& other) noexcept { sigc::trackable::operator=(std::move(other)); return *this; } Parser::~Parser() -{} - -void Parser::on_start_element(ParseContext&, const Glib::ustring&, const Parser::AttributeMap&) -{} +{ +} -void Parser::on_end_element(ParseContext&, const Glib::ustring&) -{} +void +Parser::on_start_element(ParseContext&, const Glib::ustring&, const Parser::AttributeMap&) +{ +} -void Parser::on_text(ParseContext&, const Glib::ustring&) -{} +void +Parser::on_end_element(ParseContext&, const Glib::ustring&) +{ +} -void Parser::on_passthrough(ParseContext&, const Glib::ustring&) -{} +void +Parser::on_text(ParseContext&, const Glib::ustring&) +{ +} -void Parser::on_error(ParseContext&, const MarkupError&) -{} +void +Parser::on_passthrough(ParseContext&, const Glib::ustring&) +{ +} +void +Parser::on_error(ParseContext&, const MarkupError&) +{ +} /**** Glib::Markup::ParseContext *******************************************/ ParseContext::ParseContext(Parser& parser, ParseFlags flags) -: - parser_ (&parser), - gobject_ (g_markup_parse_context_new(&ParserCallbacks::vfunc_table, (GMarkupParseFlags) flags, - this, &ParseContext::destroy_notify_callback)) -{} - -ParseContext::ParseContext(ParseContext&& other) noexcept -: sigc::trackable(std::move(other)), - parser_(std::move(other.parser_)), - gobject_(std::move(other.gobject_)) +: parser_(&parser), + gobject_(g_markup_parse_context_new(&ParserCallbacks::vfunc_table, (GMarkupParseFlags)flags, this, + &ParseContext::destroy_notify_callback)) { } -ParseContext& ParseContext::operator=(ParseContext&& other) noexcept +ParseContext::ParseContext(ParseContext&& other) noexcept : sigc::trackable(std::move(other)), + parser_(std::move(other.parser_)), + gobject_(std::move(other.gobject_)) +{ +} + +ParseContext& +ParseContext::operator=(ParseContext&& other) noexcept { sigc::trackable::operator=(std::move(other)); @@ -284,47 +265,53 @@ ParseContext::~ParseContext() g_markup_parse_context_free(gobject_); } -void ParseContext::parse(const Glib::ustring& text) +void +ParseContext::parse(const Glib::ustring& text) { GError* error = nullptr; g_markup_parse_context_parse(gobject_, text.data(), text.bytes(), &error); - if(error) + if (error) Glib::Error::throw_exception(error); } -void ParseContext::parse(const char* text_begin, const char* text_end) +void +ParseContext::parse(const char* text_begin, const char* text_end) { GError* error = nullptr; g_markup_parse_context_parse(gobject_, text_begin, text_end - text_begin, &error); - if(error) + if (error) Glib::Error::throw_exception(error); } -void ParseContext::end_parse() +void +ParseContext::end_parse() { GError* error = nullptr; g_markup_parse_context_end_parse(gobject_, &error); - if(error) + if (error) Glib::Error::throw_exception(error); } -Glib::ustring ParseContext::get_element() const +Glib::ustring +ParseContext::get_element() const { - const char *const element_name = g_markup_parse_context_get_element(gobject_); + const char* const element_name = g_markup_parse_context_get_element(gobject_); return convert_const_gchar_ptr_to_ustring(element_name); } -int ParseContext::get_line_number() const +int +ParseContext::get_line_number() const { int line_number = 0; g_markup_parse_context_get_position(gobject_, &line_number, nullptr); return line_number; } -int ParseContext::get_char_number() const +int +ParseContext::get_char_number() const { int char_number = 0; g_markup_parse_context_get_position(gobject_, nullptr, &char_number); @@ -332,9 +319,10 @@ int ParseContext::get_char_number() const } // static -void ParseContext::destroy_notify_callback(void* data) +void +ParseContext::destroy_notify_callback(void* data) { - ParseContext *const self = static_cast<ParseContext*>(data); + ParseContext* const self = static_cast<ParseContext*>(data); // Detect premature destruction. g_return_if_fail(self->parser_ == nullptr); @@ -343,4 +331,3 @@ void ParseContext::destroy_notify_callback(void* data) } // namespace Markup } // namespace Glib - diff --git a/glib/src/miscutils.ccg b/glib/src/miscutils.ccg index c0600a6c..a6754c31 100644 --- a/glib/src/miscutils.ccg +++ b/glib/src/miscutils.ccg @@ -22,255 +22,282 @@ #include <glibmm/utility.h> #include <glib.h> - namespace Glib { -Glib::ustring get_application_name() +Glib::ustring +get_application_name() { - return convert_const_gchar_ptr_to_ustring (g_get_application_name()); + return convert_const_gchar_ptr_to_ustring(g_get_application_name()); } -void set_application_name(const Glib::ustring& application_name) +void +set_application_name(const Glib::ustring& application_name) { g_set_application_name(application_name.c_str()); } -std::string get_prgname() +std::string +get_prgname() { return convert_const_gchar_ptr_to_stdstring(g_get_prgname()); } -void set_prgname(const std::string& prgname) +void +set_prgname(const std::string& prgname) { g_set_prgname(prgname.c_str()); } -std::string getenv(const std::string& variable, bool& found) +std::string +getenv(const std::string& variable, bool& found) { - const char *const value = g_getenv(variable.c_str()); + const char* const value = g_getenv(variable.c_str()); found = (value != nullptr); return convert_const_gchar_ptr_to_stdstring(value); } -std::string getenv(const std::string& variable) +std::string +getenv(const std::string& variable) { return convert_const_gchar_ptr_to_stdstring(g_getenv(variable.c_str())); } -bool setenv(const std::string& variable, const std::string& value, bool overwrite) +bool +setenv(const std::string& variable, const std::string& value, bool overwrite) { return g_setenv(variable.c_str(), value.c_str(), overwrite); } -void unsetenv(const std::string& variable) +void +unsetenv(const std::string& variable) { g_unsetenv(variable.c_str()); } -Glib::ArrayHandle<std::string> listenv() +Glib::ArrayHandle<std::string> +listenv() { - char **value = g_listenv(); - char **end = value; - while(*end){ + char** value = g_listenv(); + char** end = value; + while (*end) + { ++end; } - return Glib::ArrayHandle<std::string>(value, end-value, Glib::OWNERSHIP_DEEP); + return Glib::ArrayHandle<std::string>(value, end - value, Glib::OWNERSHIP_DEEP); } -std::string get_user_name() +std::string +get_user_name() { return convert_const_gchar_ptr_to_stdstring(g_get_user_name()); } -std::string get_real_name() +std::string +get_real_name() { return convert_const_gchar_ptr_to_stdstring(g_get_real_name()); } -std::string get_home_dir() +std::string +get_home_dir() { return convert_const_gchar_ptr_to_stdstring(g_get_home_dir()); } -std::string get_tmp_dir() +std::string +get_tmp_dir() { return convert_const_gchar_ptr_to_stdstring(g_get_tmp_dir()); } -std::string get_current_dir() +std::string +get_current_dir() { return convert_return_gchar_ptr_to_stdstring(g_get_current_dir()); } #ifndef GLIBMM_DISABLE_DEPRECATED -std::string get_user_special_dir(GUserDirectory directory) +std::string +get_user_special_dir(GUserDirectory directory) { return convert_const_gchar_ptr_to_stdstring(g_get_user_special_dir(directory)); } #endif // GLIBMM_DISABLE_DEPRECATED -std::string get_user_special_dir(UserDirectory directory) +std::string +get_user_special_dir(UserDirectory directory) { return convert_const_gchar_ptr_to_stdstring(g_get_user_special_dir((GUserDirectory)directory)); } -std::string get_user_data_dir() +std::string +get_user_data_dir() { return convert_const_gchar_ptr_to_stdstring(g_get_user_data_dir()); } -std::string get_user_config_dir() +std::string +get_user_config_dir() { return convert_const_gchar_ptr_to_stdstring(g_get_user_config_dir()); } -std::vector<std::string> get_system_data_dirs() +std::vector<std::string> +get_system_data_dirs() { - //TODO: Use a utility function: + // TODO: Use a utility function: std::vector<std::string> result; - const char* const * cresult = g_get_system_data_dirs(); - if(!cresult) + const char* const* cresult = g_get_system_data_dirs(); + if (!cresult) return result; - for(const gchar* const * iter = cresult; *iter != nullptr; ++iter) + for (const gchar* const* iter = cresult; *iter != nullptr; ++iter) { - result.emplace_back( - convert_const_gchar_ptr_to_stdstring(*iter)); + result.emplace_back(convert_const_gchar_ptr_to_stdstring(*iter)); } return result; } -std::vector<std::string> get_system_config_dirs() +std::vector<std::string> +get_system_config_dirs() { - //TODO: Use a utility function: + // TODO: Use a utility function: std::vector<std::string> result; - const char* const * cresult = g_get_system_config_dirs(); - if(!cresult) + const char* const* cresult = g_get_system_config_dirs(); + if (!cresult) return result; - for(const gchar* const * iter = cresult; *iter != nullptr; ++iter) + for (const gchar* const* iter = cresult; *iter != nullptr; ++iter) { - result.emplace_back( - convert_const_gchar_ptr_to_stdstring(*iter)); + result.emplace_back(convert_const_gchar_ptr_to_stdstring(*iter)); } return result; } -std::string get_user_cache_dir() +std::string +get_user_cache_dir() { return convert_const_gchar_ptr_to_stdstring(g_get_user_cache_dir()); } -bool path_is_absolute(const std::string& filename) +bool +path_is_absolute(const std::string& filename) { return (g_path_is_absolute(filename.c_str()) != 0); } -std::string path_skip_root(const std::string& filename) +std::string +path_skip_root(const std::string& filename) { // g_path_skip_root() returns a pointer _into_ the argument string, // or NULL if there was no root component. return convert_const_gchar_ptr_to_stdstring(g_path_skip_root(filename.c_str())); } -std::string path_get_basename(const std::string& filename) +std::string +path_get_basename(const std::string& filename) { return convert_return_gchar_ptr_to_stdstring(g_path_get_basename(filename.c_str())); } -std::string path_get_dirname(const std::string& filename) +std::string +path_get_dirname(const std::string& filename) { return convert_return_gchar_ptr_to_stdstring(g_path_get_dirname(filename.c_str())); } -std::string build_filename(const Glib::ArrayHandle<std::string>& elements) +std::string +build_filename(const Glib::ArrayHandle<std::string>& elements) { - return convert_return_gchar_ptr_to_stdstring(g_build_filenamev(const_cast<char**>(elements.data()))); + return convert_return_gchar_ptr_to_stdstring( + g_build_filenamev(const_cast<char**>(elements.data()))); } -std::string build_filename(const std::string& elem1, const std::string& elem2) +std::string +build_filename(const std::string& elem1, const std::string& elem2) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring( + g_build_filename(elem1.c_str(), elem2.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring( + g_build_filename(elem1.c_str(), elem2.c_str(), elem3.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring( + g_build_filename(elem1.c_str(), elem2.c_str(), elem3.c_str(), elem4.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4, - const std::string& elem5) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4, const std::string& elem5) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), - nullptr)); + return convert_return_gchar_ptr_to_stdstring(g_build_filename( + elem1.c_str(), elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4, - const std::string& elem5, const std::string& elem6) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4, const std::string& elem5, const std::string& elem6) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), - nullptr)); + return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), elem2.c_str(), + elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4, - const std::string& elem5, const std::string& elem6, - const std::string& elem7) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4, const std::string& elem5, const std::string& elem6, + const std::string& elem7) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), - elem7.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), elem2.c_str(), + elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), elem7.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4, - const std::string& elem5, const std::string& elem6, - const std::string& elem7, const std::string& elem8) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4, const std::string& elem5, const std::string& elem6, + const std::string& elem7, const std::string& elem8) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), - elem7.c_str(), elem8.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring( + g_build_filename(elem1.c_str(), elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), + elem6.c_str(), elem7.c_str(), elem8.c_str(), nullptr)); } -std::string build_filename(const std::string& elem1, const std::string& elem2, - const std::string& elem3, const std::string& elem4, - const std::string& elem5, const std::string& elem6, - const std::string& elem7, const std::string& elem8, - const std::string& elem9) +std::string +build_filename(const std::string& elem1, const std::string& elem2, const std::string& elem3, + const std::string& elem4, const std::string& elem5, const std::string& elem6, + const std::string& elem7, const std::string& elem8, const std::string& elem9) { - return convert_return_gchar_ptr_to_stdstring(g_build_filename(elem1.c_str(), - elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), elem6.c_str(), - elem7.c_str(), elem8.c_str(), elem9.c_str(), nullptr)); + return convert_return_gchar_ptr_to_stdstring( + g_build_filename(elem1.c_str(), elem2.c_str(), elem3.c_str(), elem4.c_str(), elem5.c_str(), + elem6.c_str(), elem7.c_str(), elem8.c_str(), elem9.c_str(), nullptr)); } -std::string build_path(const std::string& separator, const Glib::ArrayHandle<std::string>& elements) +std::string +build_path(const std::string& separator, const Glib::ArrayHandle<std::string>& elements) { - return convert_return_gchar_ptr_to_stdstring(g_build_pathv(separator.c_str(), const_cast<char**>(elements.data()))); + return convert_return_gchar_ptr_to_stdstring( + g_build_pathv(separator.c_str(), const_cast<char**>(elements.data()))); } -std::string find_program_in_path(const std::string& program) +std::string +find_program_in_path(const std::string& program) { return convert_return_gchar_ptr_to_stdstring(g_find_program_in_path(program.c_str())); } -Glib::ustring format_size(guint64 size, FormatSizeFlags flags) +Glib::ustring +format_size(guint64 size, FormatSizeFlags flags) { return convert_return_gchar_ptr_to_ustring(g_format_size_full(size, (GFormatSizeFlags)flags)); } diff --git a/glib/src/module.ccg b/glib/src/module.ccg index bcce3e48..2cf23fd0 100644 --- a/glib/src/module.ccg +++ b/glib/src/module.ccg @@ -22,19 +22,19 @@ namespace Glib { Module::Module(const std::string& file_name, ModuleFlags flags) -: - gobject_ (g_module_open(file_name.c_str(), (GModuleFlags) flags)) -{} +: gobject_(g_module_open(file_name.c_str(), (GModuleFlags)flags)) +{ +} -Module::Module(Module&& other) noexcept -: gobject_(std::move(other.gobject_)) +Module::Module(Module&& other) noexcept : gobject_(std::move(other.gobject_)) { other.gobject_ = nullptr; } -Module& Module::operator=(Module&& other) noexcept +Module& +Module::operator=(Module&& other) noexcept { - if(gobject_) + if (gobject_) g_module_close(gobject_); gobject_ = std::move(other.gobject_); @@ -45,7 +45,7 @@ Module& Module::operator=(Module&& other) noexcept Module::~Module() { - if(gobject_) + if (gobject_) g_module_close(gobject_); } @@ -55,4 +55,3 @@ Module::operator bool() const } } // namespace Glib - diff --git a/glib/src/optioncontext.ccg b/glib/src/optioncontext.ccg index f38c54d8..ed05faa2 100644 --- a/glib/src/optioncontext.ccg +++ b/glib/src/optioncontext.ccg @@ -22,55 +22,56 @@ namespace Glib { - namespace OptionContextPrivate +namespace OptionContextPrivate +{ +static const gchar* +SignalProxy_translate_gtk_callback(const gchar* str, gpointer data) +{ + Glib::ustring translated_str; + Glib::OptionContext::SlotTranslate* the_slot = + static_cast<Glib::OptionContext::SlotTranslate*>(data); + + try { - static const gchar* SignalProxy_translate_gtk_callback (const gchar* str, gpointer data) - { - Glib::ustring translated_str; - Glib::OptionContext::SlotTranslate* the_slot = - static_cast<Glib::OptionContext::SlotTranslate*>(data); - - try - { - translated_str = (*the_slot)(str); - } - catch(...) - { - Glib::exception_handlers_invoke(); - } - return translated_str.c_str (); - } - - static void SignalProxy_translate_gtk_callback_destroy (gpointer data) - { - delete static_cast<Glib::OptionContext::SlotTranslate*>(data); - } - - } //namespace OptionContextPrivate + translated_str = (*the_slot)(str); + } + catch (...) + { + Glib::exception_handlers_invoke(); + } + return translated_str.c_str(); +} + +static void +SignalProxy_translate_gtk_callback_destroy(gpointer data) +{ + delete static_cast<Glib::OptionContext::SlotTranslate*>(data); +} + +} // namespace OptionContextPrivate OptionContext::OptionContext(const Glib::ustring& parameter_string) -: gobject_( g_option_context_new(parameter_string.c_str()) ), - has_ownership_(true) +: gobject_(g_option_context_new(parameter_string.c_str())), has_ownership_(true) { } OptionContext::OptionContext(GOptionContext* castitem, bool take_ownership) -: gobject_(castitem), - has_ownership_(take_ownership) +: gobject_(castitem), has_ownership_(take_ownership) { } OptionContext::OptionContext(OptionContext&& other) noexcept -: gobject_(std::move(other.gobject_)), - has_ownership_(std::move(other.has_ownership_)) + : gobject_(std::move(other.gobject_)), + has_ownership_(std::move(other.has_ownership_)) { other.gobject_ = nullptr; other.has_ownership_ = false; } -OptionContext& OptionContext::operator=(OptionContext&& other) noexcept +OptionContext& +OptionContext::operator=(OptionContext&& other) noexcept { - if(has_ownership_) + if (has_ownership_) g_option_context_free(gobj()); gobject_ = std::move(other.gobject_); @@ -84,25 +85,26 @@ OptionContext& OptionContext::operator=(OptionContext&& other) noexcept OptionContext::~OptionContext() { - if(has_ownership_) + if (has_ownership_) g_option_context_free(gobj()); gobject_ = nullptr; } -void OptionContext::add_group(OptionGroup& group) +void +OptionContext::add_group(OptionGroup& group) { - //Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later. + // Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later. g_option_context_add_group(gobj(), (group).gobj_give_ownership()); } -void OptionContext::set_main_group(OptionGroup& group) +void +OptionContext::set_main_group(OptionGroup& group) { - //Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later. + // Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later. g_option_context_set_main_group(gobj(), (group).gobj_give_ownership()); } - /* OptionGroup OptionContext::get_main_group() const { @@ -113,18 +115,21 @@ OptionGroup OptionContext::get_main_group() const */ -void OptionContext::set_translate_func (const SlotTranslate& slot) +void +OptionContext::set_translate_func(const SlotTranslate& slot) { - //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter. - //It will be deleted when SignalProxy_translate_gtk_callback_destroy() is called. + // Create a copy of the slot. A pointer to this will be passed through the callback's data + // parameter. + // It will be deleted when SignalProxy_translate_gtk_callback_destroy() is called. auto slot_copy = new SlotTranslate(slot); - g_option_context_set_translate_func( - gobj(), &OptionContextPrivate::SignalProxy_translate_gtk_callback, slot_copy, - &OptionContextPrivate::SignalProxy_translate_gtk_callback_destroy); + g_option_context_set_translate_func(gobj(), + &OptionContextPrivate::SignalProxy_translate_gtk_callback, slot_copy, + &OptionContextPrivate::SignalProxy_translate_gtk_callback_destroy); } -Glib::ustring OptionContext::get_help(bool main_help) const +Glib::ustring +OptionContext::get_help(bool main_help) const { return Glib::convert_return_gchar_ptr_to_ustring(g_option_context_get_help( const_cast<GOptionContext*>(gobj()), static_cast<int>(main_help), nullptr)); diff --git a/glib/src/optionentry.ccg b/glib/src/optionentry.ccg index 49810c4d..0a807a51 100644 --- a/glib/src/optionentry.ccg +++ b/glib/src/optionentry.ccg @@ -31,9 +31,10 @@ OptionEntry::~OptionEntry() release_gobject(); } -void OptionEntry::release_gobject() noexcept +void +OptionEntry::release_gobject() noexcept { - if(!gobject_) + if (!gobject_) return; g_free(const_cast<char*>(gobject_->long_name)); @@ -49,27 +50,30 @@ OptionEntry::OptionEntry(const OptionEntry& src) operator=(src); } -OptionEntry& OptionEntry::operator=(const OptionEntry& src) +OptionEntry& +OptionEntry::operator=(const OptionEntry& src) { - if(this != &src) + if (this != &src) { - if(gobject_->long_name) + if (gobject_->long_name) g_free(const_cast<char*>(gobject_->long_name)); gobject_->long_name = g_strdup(src.gobject_->long_name); - gobject_->short_name = src.gobject_->short_name; //It's just one char. + gobject_->short_name = src.gobject_->short_name; // It's just one char. gobject_->flags = src.gobject_->flags; gobject_->arg = src.gobject_->arg; - gobject_->arg_data = src.gobject_->arg_data; //Shared, because it's not owned by any instance of this class anyway. + gobject_->arg_data = + src.gobject_ + ->arg_data; // Shared, because it's not owned by any instance of this class anyway. - if(gobject_->description) + if (gobject_->description) g_free(const_cast<char*>(gobject_->description)); gobject_->description = g_strdup(src.gobject_->description); - if(gobject_->arg_description) + if (gobject_->arg_description) g_free(const_cast<char*>(gobject_->arg_description)); gobject_->arg_description = g_strdup(src.gobject_->arg_description); @@ -78,13 +82,13 @@ OptionEntry& OptionEntry::operator=(const OptionEntry& src) return *this; } -OptionEntry::OptionEntry(OptionEntry&& other) noexcept -: gobject_(std::move(other.gobject_)) +OptionEntry::OptionEntry(OptionEntry&& other) noexcept : gobject_(std::move(other.gobject_)) { other.gobject_ = nullptr; } -OptionEntry& OptionEntry::operator=(OptionEntry&& other) noexcept +OptionEntry& +OptionEntry::operator=(OptionEntry&& other) noexcept { release_gobject(); @@ -94,23 +98,26 @@ OptionEntry& OptionEntry::operator=(OptionEntry&& other) noexcept return *this; } -void OptionEntry::set_long_name(const Glib::ustring& value) +void +OptionEntry::set_long_name(const Glib::ustring& value) { - if(gobject_->long_name) + if (gobject_->long_name) { g_free((gchar*)(gobject_->long_name)); gobject_->long_name = nullptr; } - //Note that we do not use nullptr for an empty string, - //because G_OPTION_REMAINING is actually a "", so it actually has a distinct meaning: - //TODO: Wrap G_OPTION_REMAINING in C++ somehow, maybe as an explicit set_long_name(void) or set_is_remaining()? murrayc. + // Note that we do not use nullptr for an empty string, + // because G_OPTION_REMAINING is actually a "", so it actually has a distinct meaning: + // TODO: Wrap G_OPTION_REMAINING in C++ somehow, maybe as an explicit set_long_name(void) or + // set_is_remaining()? murrayc. gobj()->long_name = (value).c_str() ? g_strdup((value).c_str()) : nullptr; } -void OptionEntry::set_description(const Glib::ustring& value) +void +OptionEntry::set_description(const Glib::ustring& value) { - if(gobject_->description) + if (gobject_->description) { g_free((gchar*)(gobject_->description)); gobject_->description = nullptr; @@ -119,9 +126,10 @@ void OptionEntry::set_description(const Glib::ustring& value) gobj()->description = (value).empty() ? nullptr : g_strdup((value).c_str()); } -void OptionEntry::set_arg_description(const Glib::ustring& value) +void +OptionEntry::set_arg_description(const Glib::ustring& value) { - if(gobject_->arg_description) + if (gobject_->arg_description) { g_free((gchar*)(gobject_->arg_description)); gobject_->arg_description = nullptr; @@ -130,6 +138,4 @@ void OptionEntry::set_arg_description(const Glib::ustring& value) gobj()->arg_description = (value).empty() ? nullptr : g_strdup((value).c_str()); } - } // namespace Glib - diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg index 56236e4d..20f3ae15 100644 --- a/glib/src/optiongroup.ccg +++ b/glib/src/optiongroup.ccg @@ -26,30 +26,29 @@ namespace Glib { -namespace //anonymous +namespace // anonymous { -//A pointer to an OptionArgCallback instance is stored in CppOptionEntry::cpparg_ -//when a callback function shall parse the command option's value. +// A pointer to an OptionArgCallback instance is stored in CppOptionEntry::cpparg_ +// when a callback function shall parse the command option's value. class OptionArgCallback { public: explicit OptionArgCallback(const OptionGroup::SlotOptionArgString& slot) : slot_string_(new OptionGroup::SlotOptionArgString(slot)), slot_filename_(nullptr) - { } + { + } explicit OptionArgCallback(const OptionGroup::SlotOptionArgFilename& slot) : slot_string_(nullptr), slot_filename_(new OptionGroup::SlotOptionArgFilename(slot)) - { } + { + } - bool is_filename_option() const - { return slot_filename_ != nullptr; } + bool is_filename_option() const { return slot_filename_ != nullptr; } - const OptionGroup::SlotOptionArgString* get_slot_string() const - { return slot_string_; } + const OptionGroup::SlotOptionArgString* get_slot_string() const { return slot_string_; } - const OptionGroup::SlotOptionArgFilename* get_slot_filename() const - { return slot_filename_; } + const OptionGroup::SlotOptionArgFilename* get_slot_filename() const { return slot_filename_; } ~OptionArgCallback() { @@ -58,28 +57,29 @@ public: } private: - //One of these slot pointers is 0 and the other one points to a slot. + // One of these slot pointers is 0 and the other one points to a slot. OptionGroup::SlotOptionArgString* slot_string_; OptionGroup::SlotOptionArgFilename* slot_filename_; - //Not copyable + // Not copyable OptionArgCallback(const OptionArgCallback&); OptionArgCallback& operator=(const OptionArgCallback&); }; -extern "C" -{ +extern "C" { -static gboolean g_callback_pre_parse(GOptionContext* context, - GOptionGroup* /* group */, gpointer data, GError** error) +static gboolean +g_callback_pre_parse( + GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** error) { OptionContext cppContext(context, false /* take_ownership */); auto option_group = static_cast<OptionGroup*>(data); - if(!option_group) + if (!option_group) { OptionError(OptionError::FAILED, "Glib::OptionGroup: g_callback_pre_parse(): " - "No OptionGroup pointer available").propagate(error); + "No OptionGroup pointer available") + .propagate(error); return false; } @@ -87,19 +87,20 @@ static gboolean g_callback_pre_parse(GOptionContext* context, { return option_group->on_pre_parse(cppContext, *option_group); } - catch(Glib::Error& err) + catch (Glib::Error& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } return false; } -static void g_callback_error(GOptionContext* context, - GOptionGroup* /* group */, gpointer data, GError** /* TODO error */) +static void +g_callback_error( + GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** /* TODO error */) { // TODO GError** error is input data containing information on an error that // has occurred before this function is called. When API can be broken, @@ -109,22 +110,21 @@ static void g_callback_error(GOptionContext* context, OptionContext cppContext(context, false /* take_ownership */); auto option_group = static_cast<OptionGroup*>(data); - if(option_group) + if (option_group) return option_group->on_error(cppContext, *option_group); } -const gchar* OptionGroup_Translate_glibmm_callback(const gchar* string, - gpointer data) +const gchar* +OptionGroup_Translate_glibmm_callback(const gchar* string, gpointer data) { - Glib::OptionGroup::SlotTranslate* the_slot = - static_cast<Glib::OptionGroup::SlotTranslate*>(data); + Glib::OptionGroup::SlotTranslate* the_slot = static_cast<Glib::OptionGroup::SlotTranslate*>(data); try { // The C docs says that the char* belongs to Glib. return g_strdup((*the_slot)(Glib::ustring(string)).c_str()); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -132,32 +132,35 @@ const gchar* OptionGroup_Translate_glibmm_callback(const gchar* string, return nullptr; } -static void OptionGroup_Translate_glibmm_callback_destroy(void* data) +static void +OptionGroup_Translate_glibmm_callback_destroy(void* data) { delete static_cast<Glib::OptionGroup::SlotTranslate*>(data); } } /* extern "C" */ -} //anonymous namespace +} // anonymous namespace -//static -gboolean OptionGroup::post_parse_callback(GOptionContext* context, - GOptionGroup* /* group */, gpointer data, GError** error) +// static +gboolean +OptionGroup::post_parse_callback( + GOptionContext* context, GOptionGroup* /* group */, gpointer data, GError** error) { OptionContext cppContext(context, false /* take_ownership */); OptionGroup* option_group = static_cast<OptionGroup*>(data); - if(!option_group) + if (!option_group) { OptionError(OptionError::FAILED, "Glib::OptionGroup::post_parse_callback(): " - "No OptionGroup pointer available").propagate(error); + "No OptionGroup pointer available") + .propagate(error); return false; } - //The C args have now been given values by g_option_context_parse(). - //Convert C values to C++ values: - for(auto& the_pair : option_group->map_entries_) + // The C args have now been given values by g_option_context_parse(). + // Convert C values to C++ values: + for (auto& the_pair : option_group->map_entries_) { auto& cpp_entry = the_pair.second; cpp_entry.convert_c_to_cpp(); @@ -167,57 +170,61 @@ gboolean OptionGroup::post_parse_callback(GOptionContext* context, { return option_group->on_post_parse(cppContext, *option_group); } - catch(Glib::Error& err) + catch (Glib::Error& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } return false; } -//static -gboolean OptionGroup::option_arg_callback(const gchar* option_name, const gchar* value, - gpointer data, GError** error) +// static +gboolean +OptionGroup::option_arg_callback( + const gchar* option_name, const gchar* value, gpointer data, GError** error) { const Glib::ustring cpp_option_name(option_name); const OptionGroup* const option_group = static_cast<const OptionGroup*>(data); - if(!option_group) + if (!option_group) { OptionError(OptionError::FAILED, "Glib::OptionGroup::option_arg_callback(): " - "No OptionGroup pointer available for option " + cpp_option_name).propagate(error); + "No OptionGroup pointer available for option " + + cpp_option_name) + .propagate(error); return false; } - //option_name is either a single dash followed by a single letter (for a - //short name) or two dashes followed by a long option name. + // option_name is either a single dash followed by a single letter (for a + // short name) or two dashes followed by a long option name. OptionGroup::type_map_entries::const_iterator iterFind = option_group->map_entries_.end(); - if(option_name[1] == '-') + if (option_name[1] == '-') { - //Long option name. - const auto long_option_name = Glib::ustring(option_name+2); + // Long option name. + const auto long_option_name = Glib::ustring(option_name + 2); iterFind = option_group->map_entries_.find(long_option_name); } else { - //Short option name. + // Short option name. const auto short_option_name = option_name[1]; - for(iterFind = option_group->map_entries_.begin(); - iterFind != option_group->map_entries_.end(); ++iterFind) + for (iterFind = option_group->map_entries_.begin(); + iterFind != option_group->map_entries_.end(); ++iterFind) { const auto& cppOptionEntry = iterFind->second; - if (cppOptionEntry.entry_ && - cppOptionEntry.entry_->get_short_name() == short_option_name) + if (cppOptionEntry.entry_ && cppOptionEntry.entry_->get_short_name() == short_option_name) break; } } - if(iterFind == option_group->map_entries_.end()) + if (iterFind == option_group->map_entries_.end()) { OptionError(OptionError::UNKNOWN_OPTION, "Glib::OptionGroup::option_arg_callback(): " - "Unknown option " + cpp_option_name).propagate(error); + "Unknown option " + + cpp_option_name) + .propagate(error); return false; } @@ -225,7 +232,9 @@ gboolean OptionGroup::option_arg_callback(const gchar* option_name, const gchar* if (cppOptionEntry.carg_type_ != G_OPTION_ARG_CALLBACK) { OptionError(OptionError::FAILED, "Glib::OptionGroup::option_arg_callback() " - "called for non-callback option " + cpp_option_name).propagate(error); + "called for non-callback option " + + cpp_option_name) + .propagate(error); return false; } @@ -247,50 +256,50 @@ gboolean OptionGroup::option_arg_callback(const gchar* option_name, const gchar* return (*the_slot)(cpp_option_name, cpp_value, has_value); } } - catch(Glib::Error& err) + catch (Glib::Error& err) { err.propagate(error); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } return false; } -OptionGroup::OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description) -: gobject_( g_option_group_new(name.c_str(), description.c_str(), help_description.c_str(), - this /* user_data */, nullptr /* destroy_func */) ), +OptionGroup::OptionGroup(const Glib::ustring& name, const Glib::ustring& description, + const Glib::ustring& help_description) +: gobject_(g_option_group_new(name.c_str(), description.c_str(), help_description.c_str(), + this /* user_data */, nullptr /* destroy_func */)), has_ownership_(true) { - //g_callback_pre_parse(), post_parse_callback(), g_callback_error(), and - //option_arg_callback() depend on user_data being this. The first three - //functions get a GOptionGroup*, but it would not be correct to use it for - //creating a new OptionGroup. They must call their virtual functions in the - //original OptionGroup instance. + // g_callback_pre_parse(), post_parse_callback(), g_callback_error(), and + // option_arg_callback() depend on user_data being this. The first three + // functions get a GOptionGroup*, but it would not be correct to use it for + // creating a new OptionGroup. They must call their virtual functions in the + // original OptionGroup instance. - //Connect callbacks, so that derived classes can override the virtual methods: + // Connect callbacks, so that derived classes can override the virtual methods: g_option_group_set_parse_hooks(gobj(), &g_callback_pre_parse, &post_parse_callback); g_option_group_set_error_hook(gobj(), &g_callback_error); } -OptionGroup::OptionGroup(GOptionGroup* castitem) -: gobject_(castitem), - has_ownership_(true) +OptionGroup::OptionGroup(GOptionGroup* castitem) : gobject_(castitem), has_ownership_(true) { - //Always takes ownership - never takes copy. + // Always takes ownership - never takes copy. } OptionGroup::OptionGroup(OptionGroup&& other) noexcept -: map_entries_(std::move(other.map_entries_)), - gobject_(std::move(other.gobject_)), - has_ownership_(std::move(other.has_ownership_)) + : map_entries_(std::move(other.map_entries_)), + gobject_(std::move(other.gobject_)), + has_ownership_(std::move(other.has_ownership_)) { other.gobject_ = nullptr; other.has_ownership_ = false; } -OptionGroup& OptionGroup::operator=(OptionGroup&& other) noexcept +OptionGroup& +OptionGroup::operator=(OptionGroup&& other) noexcept { release_gobject(); @@ -304,16 +313,17 @@ OptionGroup& OptionGroup::operator=(OptionGroup&& other) noexcept return *this; } -void OptionGroup::release_gobject() noexcept +void +OptionGroup::release_gobject() noexcept { - //Free any C types that were allocated during add_entry(): - for(auto& the_pair : map_entries_) + // Free any C types that were allocated during add_entry(): + for (auto& the_pair : map_entries_) { auto& cpp_entry = the_pair.second; cpp_entry.release_c_arg(); } - if(has_ownership_ && gobject_) + if (has_ownership_ && gobject_) { g_option_group_unref(gobj()); gobject_ = nullptr; @@ -325,52 +335,63 @@ OptionGroup::~OptionGroup() release_gobject(); } -void OptionGroup::add_entry(const OptionEntry& entry) +void +OptionGroup::add_entry(const OptionEntry& entry) { - //It does not copy the entry, so it needs to live as long as the group. + // It does not copy the entry, so it needs to live as long as the group. - //g_option_group_add_entries takes an array, with the last item in the array having a null long_name. - //Hopefully this will be properly documented eventually - see bug # + // g_option_group_add_entries takes an array, with the last item in the array having a null + // long_name. + // Hopefully this will be properly documented eventually - see bug # - //Create a temporary array, just so we can give the correct thing to g_option_group_add_entries: + // Create a temporary array, just so we can give the correct thing to g_option_group_add_entries: GOptionEntry array[2]; - array[0] = *(entry.gobj()); //Copy contents. + array[0] = *(entry.gobj()); // Copy contents. std::memset(&array[1], 0, sizeof(GOptionEntry)); g_option_group_add_entries(gobj(), array); } -void OptionGroup::add_entry(const OptionEntry& entry, bool& arg) +void +OptionGroup::add_entry(const OptionEntry& entry, bool& arg) { - add_entry_with_wrapper(entry, G_OPTION_ARG_NONE /* Actually a boolean on/off, depending on whether the argument name was given, without argument parameters. */, &arg); + add_entry_with_wrapper(entry, + G_OPTION_ARG_NONE /* Actually a boolean on/off, depending on whether the argument name was given, without argument parameters. */, + &arg); } -void OptionGroup::add_entry(const OptionEntry& entry, int& arg) +void +OptionGroup::add_entry(const OptionEntry& entry, int& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_INT, &arg); } -void OptionGroup::add_entry(const OptionEntry& entry, double& arg) +void +OptionGroup::add_entry(const OptionEntry& entry, double& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_DOUBLE, &arg); } -void OptionGroup::add_entry(const OptionEntry& entry, Glib::ustring& arg) +void +OptionGroup::add_entry(const OptionEntry& entry, Glib::ustring& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_STRING, &arg); } -void OptionGroup::add_entry(const OptionEntry& entry, vecustrings& arg) +void +OptionGroup::add_entry(const OptionEntry& entry, vecustrings& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_STRING_ARRAY, &arg); } -void OptionGroup::add_entry_filename(const OptionEntry& entry, std::string& arg) +void +OptionGroup::add_entry_filename(const OptionEntry& entry, std::string& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_FILENAME, &arg); } -void OptionGroup::add_entry_filename(const OptionEntry& entry, vecstrings& arg) +void +OptionGroup::add_entry_filename(const OptionEntry& entry, vecstrings& arg) { add_entry_with_wrapper(entry, G_OPTION_ARG_FILENAME_ARRAY, &arg); } @@ -387,28 +408,31 @@ void OptionGroup::add_entry_filename(const OptionEntry& entry, vecstrings& arg) // with G_OPTION_FLAG_FILENAME. We do this automatiically in set_c_arg_default(). // Other option flags are set by OptionEntry::set_flags(). -void OptionGroup::add_entry(const OptionEntry& entry, const SlotOptionArgString& slot) +void +OptionGroup::add_entry(const OptionEntry& entry, const SlotOptionArgString& slot) { - //The OptionArgCallback is deleted in release_c_arg(). + // The OptionArgCallback is deleted in release_c_arg(). add_entry_with_wrapper(entry, G_OPTION_ARG_CALLBACK, new OptionArgCallback(slot)); } -void OptionGroup::add_entry_filename(const OptionEntry& entry, const SlotOptionArgFilename& slot) +void +OptionGroup::add_entry_filename(const OptionEntry& entry, const SlotOptionArgFilename& slot) { - //The OptionArgCallback is deleted in release_c_arg(). + // The OptionArgCallback is deleted in release_c_arg(). add_entry_with_wrapper(entry, G_OPTION_ARG_CALLBACK, new OptionArgCallback(slot)); } -void OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg) +void +OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg) { const auto name = entry.get_long_name(); type_map_entries::iterator iterFind = map_entries_.find(name); - if (iterFind == map_entries_.end()) //If we have not added this entry already + if (iterFind == map_entries_.end()) // If we have not added this entry already { CppOptionEntry cppEntry; - //g_option_group_add_entry() does not take its own copy, so we must keep the instance alive. + // g_option_group_add_entry() does not take its own copy, so we must keep the instance alive. cppEntry.entry_ = new OptionEntry(entry); - //cppEntry.entry_ is deleted in release_c_arg(), via the destructor. + // cppEntry.entry_ is deleted in release_c_arg(), via the destructor. // Several options can refer to the same C++ variable, // typically a pair of --enable-x / --disable-x options. @@ -418,13 +442,11 @@ void OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg ar void* carg = nullptr; if (arg_type != G_OPTION_ARG_CALLBACK) { - for (type_map_entries::iterator iter = map_entries_.begin(); - iter != map_entries_.end(); ++iter) + for (type_map_entries::iterator iter = map_entries_.begin(); iter != map_entries_.end(); + ++iter) { const auto& cpp_entry = iter->second; - if (cpp_entry.cpparg_ == cpp_arg && - cpp_entry.carg_type_ == arg_type && - cpp_entry.carg_) + if (cpp_entry.cpparg_ == cpp_arg && cpp_entry.carg_type_ == arg_type && cpp_entry.carg_) { is_duplicate = true; carg = cpp_entry.carg_; @@ -442,386 +464,394 @@ void OptionGroup::add_entry_with_wrapper(const OptionEntry& entry, GOptionArg ar } cppEntry.cpparg_ = cpp_arg; - //Give the information to the C API: + // Give the information to the C API: cppEntry.entry_->gobj()->arg = arg_type; cppEntry.entry_->gobj()->arg_data = carg; - //Remember the C++/C mapping so that we can use it later: + // Remember the C++/C mapping so that we can use it later: map_entries_[name] = cppEntry; add_entry(*(cppEntry.entry_)); } else if (arg_type == G_OPTION_ARG_CALLBACK) { - //Delete the OptionArgCallback instance that was allocated by add_entry() - //or add_entry_filename(). + // Delete the OptionArgCallback instance that was allocated by add_entry() + // or add_entry_filename(). auto option_arg = static_cast<OptionArgCallback*>(cpp_arg); delete option_arg; } } - -bool OptionGroup::on_pre_parse(OptionContext& /* context */, OptionGroup& /* group */) +bool +OptionGroup::on_pre_parse(OptionContext& /* context */, OptionGroup& /* group */) { return true; } -bool OptionGroup::on_post_parse(OptionContext& /* context */, OptionGroup& /* group */) +bool +OptionGroup::on_post_parse(OptionContext& /* context */, OptionGroup& /* group */) { return true; } -void OptionGroup::on_error(OptionContext& /* context */, OptionGroup& /* group */) +void +OptionGroup::on_error(OptionContext& /* context */, OptionGroup& /* group */) { } -void OptionGroup::set_translate_func(const SlotTranslate& slot) +void +OptionGroup::set_translate_func(const SlotTranslate& slot) { // Create a copy of the slot. A pointer to this will be passed through the // callback's data parameter. It will be deleted when // OptionGroup_Translate_glibmm_callback_destroy() is called. auto slot_copy = new SlotTranslate(slot); - g_option_group_set_translate_func(gobj(), - &OptionGroup_Translate_glibmm_callback, slot_copy, + g_option_group_set_translate_func(gobj(), &OptionGroup_Translate_glibmm_callback, slot_copy, &OptionGroup_Translate_glibmm_callback_destroy); } - OptionGroup::CppOptionEntry::CppOptionEntry() : carg_type_(G_OPTION_ARG_NONE), carg_(nullptr), cpparg_(nullptr), entry_(nullptr) -{} +{ +} -void OptionGroup::CppOptionEntry::allocate_c_arg() +void +OptionGroup::CppOptionEntry::allocate_c_arg() { - //Create an instance of the appropriate C type. - //This will be destroyed in the OptionGroup destructor. + // Create an instance of the appropriate C type. + // This will be destroyed in the OptionGroup destructor. // - //We must also call set_c_arg_default() to give these C types the specified - //defaults based on the C++-typed arguments. - switch(carg_type_) + // We must also call set_c_arg_default() to give these C types the specified + // defaults based on the C++-typed arguments. + switch (carg_type_) { - case G_OPTION_ARG_STRING: //The char* will be for UTF8 a string. - case G_OPTION_ARG_FILENAME: //The char* will be for a string in the current locale's encoding. - { - char** typed_arg = new char*; - //The C code will allocate a char* and put it here, for us to g_free() later. - *typed_arg = nullptr; - carg_ = typed_arg; + case G_OPTION_ARG_STRING: // The char* will be for UTF8 a string. + case G_OPTION_ARG_FILENAME: // The char* will be for a string in the current locale's encoding. + { + char** typed_arg = new char*; + // The C code will allocate a char* and put it here, for us to g_free() later. + *typed_arg = nullptr; + carg_ = typed_arg; - break; - } - case G_OPTION_ARG_INT: - { - int* typed_arg = new int; - *typed_arg = 0; - carg_ = typed_arg; + break; + } + case G_OPTION_ARG_INT: + { + int* typed_arg = new int; + *typed_arg = 0; + carg_ = typed_arg; - break; - } - case G_OPTION_ARG_DOUBLE: - { - double* typed_arg = new double; - *typed_arg = 0.0; - carg_ = typed_arg; + break; + } + case G_OPTION_ARG_DOUBLE: + { + double* typed_arg = new double; + *typed_arg = 0.0; + carg_ = typed_arg; - break; - } - case G_OPTION_ARG_STRING_ARRAY: - case G_OPTION_ARG_FILENAME_ARRAY: - { - char*** typed_arg = new char**; - //The C code will allocate a char** and put it here, for us to g_strfreev() later. - *typed_arg = nullptr; - carg_ = typed_arg; + break; + } + case G_OPTION_ARG_STRING_ARRAY: + case G_OPTION_ARG_FILENAME_ARRAY: + { + char*** typed_arg = new char**; + // The C code will allocate a char** and put it here, for us to g_strfreev() later. + *typed_arg = nullptr; + carg_ = typed_arg; - break; - } - case G_OPTION_ARG_NONE: // Actually a boolean. - { - gboolean* typed_arg = new gboolean; - *typed_arg = false; - carg_ = typed_arg; + break; + } + case G_OPTION_ARG_NONE: // Actually a boolean. + { + gboolean* typed_arg = new gboolean; + *typed_arg = false; + carg_ = typed_arg; - break; - } - case G_OPTION_ARG_CALLBACK: - { - //The C arg pointer is a function pointer, cast to void*. - union { - void* dp; - GOptionArgFunc fp; - } u; - u.fp = &OptionGroup::option_arg_callback; - carg_ = u.dp; - - // With all compiler warnings turned on and a high optimization level - // it's difficult to cast a function pointer to a void*. See bug 589197. - // A few results with g++ 4.4.5 with the flags -pedantic -O2 -Werror: - // - // carg_ = reinterpret_cast<void*>(&OptionGroup::option_arg_callback); - // error: ISO C++ forbids casting between pointer-to-function and pointer-to-object - // - // *reinterpret_cast<GOptionArgFunc*>(&carg_) = &OptionGroup::option_arg_callback; - // *(OptionArgFunc*)&carg_ = &OptionGroup::option_arg_callback; - // error: dereferencing type-punned pointer will break strict-aliasing rules - // - // If any compiler dislikes the union, the following code is worth testing: - // carg_ = reinterpret_cast<void*>( - // reinterpret_cast<unsigned long>(&OptionGroup::option_arg_callback)); + break; + } + case G_OPTION_ARG_CALLBACK: + { + // The C arg pointer is a function pointer, cast to void*. + union { + void* dp; + GOptionArgFunc fp; + } u; + u.fp = &OptionGroup::option_arg_callback; + carg_ = u.dp; + + // With all compiler warnings turned on and a high optimization level + // it's difficult to cast a function pointer to a void*. See bug 589197. + // A few results with g++ 4.4.5 with the flags -pedantic -O2 -Werror: + // + // carg_ = reinterpret_cast<void*>(&OptionGroup::option_arg_callback); + // error: ISO C++ forbids casting between pointer-to-function and pointer-to-object + // + // *reinterpret_cast<GOptionArgFunc*>(&carg_) = &OptionGroup::option_arg_callback; + // *(OptionArgFunc*)&carg_ = &OptionGroup::option_arg_callback; + // error: dereferencing type-punned pointer will break strict-aliasing rules + // + // If any compiler dislikes the union, the following code is worth testing: + // carg_ = reinterpret_cast<void*>( + // reinterpret_cast<unsigned long>(&OptionGroup::option_arg_callback)); + + break; + } + default: + { + break; + } + } +} - break; +void +OptionGroup::CppOptionEntry::set_c_arg_default(void* cpp_arg) +{ + switch (carg_type_) + { + case G_OPTION_ARG_INT: + { + *static_cast<int*>(carg_) = *static_cast<int*>(cpp_arg); + break; + } + case G_OPTION_ARG_DOUBLE: + { + *static_cast<double*>(carg_) = *static_cast<double*>(cpp_arg); + break; + } + case G_OPTION_ARG_NONE: + { + *static_cast<gboolean*>(carg_) = *static_cast<bool*>(cpp_arg); + break; + } + case G_OPTION_ARG_STRING: + case G_OPTION_ARG_FILENAME: + case G_OPTION_ARG_STRING_ARRAY: + case G_OPTION_ARG_FILENAME_ARRAY: + { + // No need to set default values for string-valued options. + // If *carg_ is still 0, when convert_c_to_cpp() is called, just don't + // touch *cpparg_. Besides, setting default values in *carg_ can result + // in memory leaks, because glib would not free the strings before + // the char*'s are overwritten with pointers to newly allocated copies + // of the command option arguments. + break; + } + case G_OPTION_ARG_CALLBACK: + { + // No value to set here. The arg pointer is a function pointer. + + // Set or clear FLAG_FILENAME in *entry_. + const OptionArgCallback* const option_arg = static_cast<const OptionArgCallback*>(cpp_arg); + if (option_arg->is_filename_option()) + { + entry_->set_flags(entry_->get_flags() | OptionEntry::FLAG_FILENAME); } - default: + else { - break; + entry_->set_flags(entry_->get_flags() & ~OptionEntry::FLAG_FILENAME); } + break; + } + default: + { + break; + } } } -void OptionGroup::CppOptionEntry::set_c_arg_default(void* cpp_arg) +void +OptionGroup::CppOptionEntry::release_c_arg() { - switch(carg_type_) + // Delete the instances that we created in allocate_c_arg(). + // Notice that we delete the type that we created, but not the value to which it points. + if (carg_) { - case G_OPTION_ARG_INT: + switch (carg_type_) { - *static_cast<int*>(carg_) = *static_cast<int*>(cpp_arg); + case G_OPTION_ARG_STRING: + case G_OPTION_ARG_FILENAME: + { + char** typed_arg = static_cast<char**>(carg_); + g_free(*typed_arg); // Free the char* string at typed_arg, if allocated by the C code. + delete typed_arg; // Delete the char** that we allocated in allocate_c_arg(). + break; } - case G_OPTION_ARG_DOUBLE: + case G_OPTION_ARG_INT: { - *static_cast<double*>(carg_) = *static_cast<double*>(cpp_arg); + int* typed_arg = static_cast<int*>(carg_); + delete typed_arg; + break; } - case G_OPTION_ARG_NONE: + case G_OPTION_ARG_DOUBLE: { - *static_cast<gboolean*>(carg_) = *static_cast<bool*>(cpp_arg); + double* typed_arg = static_cast<double*>(carg_); + delete typed_arg; + break; } - case G_OPTION_ARG_STRING: - case G_OPTION_ARG_FILENAME: case G_OPTION_ARG_STRING_ARRAY: case G_OPTION_ARG_FILENAME_ARRAY: { - // No need to set default values for string-valued options. - // If *carg_ is still 0, when convert_c_to_cpp() is called, just don't - // touch *cpparg_. Besides, setting default values in *carg_ can result - // in memory leaks, because glib would not free the strings before - // the char*'s are overwritten with pointers to newly allocated copies - // of the command option arguments. + char*** typed_arg = static_cast<char***>(carg_); + g_strfreev(*typed_arg); // Free the array of strings and the array at typed_arg, if allocated + // by the C code. + delete typed_arg; // Delete the char*** that we allocated in allocate_c_arg(). + + break; + } + case G_OPTION_ARG_NONE: // Actually a boolean. + { + gboolean* typed_arg = static_cast<gboolean*>(carg_); + delete typed_arg; + break; } case G_OPTION_ARG_CALLBACK: { - //No value to set here. The arg pointer is a function pointer. + // Delete the OptionArgCallback instance that was allocated by add_entry() + // or add_entry_filename(). + auto option_arg = static_cast<OptionArgCallback*>(cpparg_); + delete option_arg; + cpparg_ = nullptr; - //Set or clear FLAG_FILENAME in *entry_. - const OptionArgCallback* const option_arg = static_cast<const OptionArgCallback*>(cpp_arg); - if (option_arg->is_filename_option()) - { - entry_->set_flags(entry_->get_flags() | OptionEntry::FLAG_FILENAME); - } - else - { - entry_->set_flags(entry_->get_flags() & ~OptionEntry::FLAG_FILENAME); - } break; } default: { break; } - } -} - -void OptionGroup::CppOptionEntry::release_c_arg() -{ - //Delete the instances that we created in allocate_c_arg(). - //Notice that we delete the type that we created, but not the value to which it points. - if(carg_) - { - switch(carg_type_) - { - case G_OPTION_ARG_STRING: - case G_OPTION_ARG_FILENAME: - { - char** typed_arg = static_cast<char**>(carg_); - g_free(*typed_arg); //Free the char* string at typed_arg, if allocated by the C code. - delete typed_arg; //Delete the char** that we allocated in allocate_c_arg(). - - break; - } - case G_OPTION_ARG_INT: - { - int* typed_arg = static_cast<int*>(carg_); - delete typed_arg; - - break; - } - case G_OPTION_ARG_DOUBLE: - { - double* typed_arg = static_cast<double*>(carg_); - delete typed_arg; - - break; - } - case G_OPTION_ARG_STRING_ARRAY: - case G_OPTION_ARG_FILENAME_ARRAY: - { - char*** typed_arg = static_cast<char***>(carg_); - g_strfreev(*typed_arg); //Free the array of strings and the array at typed_arg, if allocated by the C code. - delete typed_arg; //Delete the char*** that we allocated in allocate_c_arg(). - - break; - } - case G_OPTION_ARG_NONE: // Actually a boolean. - { - gboolean* typed_arg = static_cast<gboolean*>(carg_); - delete typed_arg; - - break; - } - case G_OPTION_ARG_CALLBACK: - { - //Delete the OptionArgCallback instance that was allocated by add_entry() - //or add_entry_filename(). - auto option_arg = static_cast<OptionArgCallback*>(cpparg_); - delete option_arg; - cpparg_ = nullptr; - - break; - } - default: - { - break; - } } carg_ = nullptr; } - if(entry_) + if (entry_) delete entry_; } -void OptionGroup::CppOptionEntry::convert_c_to_cpp() +void +OptionGroup::CppOptionEntry::convert_c_to_cpp() { if (!carg_) return; - switch(carg_type_) + switch (carg_type_) { - case G_OPTION_ARG_STRING: - { - char** typed_arg = static_cast<char**>(carg_); - auto typed_cpp_arg = static_cast<Glib::ustring*>(cpparg_); - if(typed_arg && *typed_arg && typed_cpp_arg) - { - *typed_cpp_arg = *typed_arg; - } - break; - } - case G_OPTION_ARG_FILENAME: + case G_OPTION_ARG_STRING: + { + char** typed_arg = static_cast<char**>(carg_); + auto typed_cpp_arg = static_cast<Glib::ustring*>(cpparg_); + if (typed_arg && *typed_arg && typed_cpp_arg) { - char** typed_arg = static_cast<char**>(carg_); - auto typed_cpp_arg = static_cast<std::string*>(cpparg_); - if(typed_arg && *typed_arg && typed_cpp_arg) - { - *typed_cpp_arg = *typed_arg; - } - break; + *typed_cpp_arg = *typed_arg; } - case G_OPTION_ARG_INT: + break; + } + case G_OPTION_ARG_FILENAME: + { + char** typed_arg = static_cast<char**>(carg_); + auto typed_cpp_arg = static_cast<std::string*>(cpparg_); + if (typed_arg && *typed_arg && typed_cpp_arg) { - *((int*)cpparg_) = *(static_cast<int*>(carg_)); - break; + *typed_cpp_arg = *typed_arg; } - case G_OPTION_ARG_DOUBLE: - { - *((double*)cpparg_) = *(static_cast<double*>(carg_)); - break; - } - case G_OPTION_ARG_STRING_ARRAY: + break; + } + case G_OPTION_ARG_INT: + { + *((int*)cpparg_) = *(static_cast<int*>(carg_)); + break; + } + case G_OPTION_ARG_DOUBLE: + { + *((double*)cpparg_) = *(static_cast<double*>(carg_)); + break; + } + case G_OPTION_ARG_STRING_ARRAY: + { + char*** typed_arg = static_cast<char***>(carg_); + auto typed_cpp_arg = static_cast<vecustrings*>(cpparg_); + if (typed_arg && *typed_arg && typed_cpp_arg) { - char*** typed_arg = static_cast<char***>(carg_); - auto typed_cpp_arg = static_cast<vecustrings*>(cpparg_); - if(typed_arg && *typed_arg && typed_cpp_arg) + typed_cpp_arg->clear(); + + // The C array is null-terminated. + // Glib::StringArrayHandle array_handle(*typed_arg, Glib::OWNERSHIP_NONE); + + // The SUN Forte compiler complains about this: + // "optiongroup.cc", line 354: Error: Cannot assign Glib::ArrayHandle<Glib::ustring, + // Glib::Container_Helpers::TypeTraits<Glib::ustring>> to std::vector<Glib::ustring> without + // "std::vector<Glib::ustring>::operator=(const std::vector<Glib::ustring>&)";. + // + //(*typed_cpp_arg) = array_handle; + // + // And the Tru64 compiler does not even like us to instantiate the StringArrayHandle: + // + // cxx: Error: ../../glib/glibmm/containerhandle_shared.h, line 149: the operand + // of a pointer dynamic_cast must be a pointer to a complete class type + // return dynamic_cast<CppType>(Glib::wrap_auto(cobj, false /* take_copy */)); + + // for(Glib::StringArrayHandle::iterator iter = array_handle.begin(); iter != + // array_handle.end(); ++iter) + //{ + // typed_cpp_arg->emplace_back(*iter); + //} + + // So we do this: + + char** char_array_next = *typed_arg; + while (*char_array_next) { - typed_cpp_arg->clear(); - - //The C array is null-terminated. - //Glib::StringArrayHandle array_handle(*typed_arg, Glib::OWNERSHIP_NONE); - - //The SUN Forte compiler complains about this: - // "optiongroup.cc", line 354: Error: Cannot assign Glib::ArrayHandle<Glib::ustring, - // Glib::Container_Helpers::TypeTraits<Glib::ustring>> to std::vector<Glib::ustring> without - // "std::vector<Glib::ustring>::operator=(const std::vector<Glib::ustring>&)";. - // - //(*typed_cpp_arg) = array_handle; - // - //And the Tru64 compiler does not even like us to instantiate the StringArrayHandle: - // - // cxx: Error: ../../glib/glibmm/containerhandle_shared.h, line 149: the operand - // of a pointer dynamic_cast must be a pointer to a complete class type - // return dynamic_cast<CppType>(Glib::wrap_auto(cobj, false /* take_copy */)); - - //for(Glib::StringArrayHandle::iterator iter = array_handle.begin(); iter != array_handle.end(); ++iter) - //{ - // typed_cpp_arg->emplace_back(*iter); - //} - - //So we do this: - - char** char_array_next = *typed_arg; - while(*char_array_next) - { - typed_cpp_arg->emplace_back(*char_array_next); - ++char_array_next; - } + typed_cpp_arg->emplace_back(*char_array_next); + ++char_array_next; } - break; } - case G_OPTION_ARG_FILENAME_ARRAY: + break; + } + case G_OPTION_ARG_FILENAME_ARRAY: + { + char*** typed_arg = static_cast<char***>(carg_); + auto typed_cpp_arg = static_cast<vecstrings*>(cpparg_); + if (typed_arg && *typed_arg && typed_cpp_arg) { - char*** typed_arg = static_cast<char***>(carg_); - auto typed_cpp_arg = static_cast<vecstrings*>(cpparg_); - if(typed_arg && *typed_arg && typed_cpp_arg) - { - typed_cpp_arg->clear(); + typed_cpp_arg->clear(); - //See comments above about the SUN Forte and Tru64 compilers. + // See comments above about the SUN Forte and Tru64 compilers. - char** char_array_next = *typed_arg; - while(*char_array_next) - { - typed_cpp_arg->emplace_back(*char_array_next); - ++char_array_next; - } + char** char_array_next = *typed_arg; + while (*char_array_next) + { + typed_cpp_arg->emplace_back(*char_array_next); + ++char_array_next; } - break; - } - case G_OPTION_ARG_NONE: // Actually a boolean. - { - *(static_cast<bool*>(cpparg_)) = *(static_cast<gboolean*>(carg_)); - break; - } - case G_OPTION_ARG_CALLBACK: - { - //Nothing to convert here. That's a task for the callback function - //(the SlotOptionArgString or SlotOptionArgFilename). - break; - } - default: - { - break; } + break; + } + case G_OPTION_ARG_NONE: // Actually a boolean. + { + *(static_cast<bool*>(cpparg_)) = *(static_cast<gboolean*>(carg_)); + break; + } + case G_OPTION_ARG_CALLBACK: + { + // Nothing to convert here. That's a task for the callback function + //(the SlotOptionArgString or SlotOptionArgFilename). + break; + } + default: + { + break; + } } } -GOptionGroup* OptionGroup::gobj_give_ownership() +GOptionGroup* +OptionGroup::gobj_give_ownership() { has_ownership_ = false; return gobj(); } } // namespace Glib - diff --git a/glib/src/regex.ccg b/glib/src/regex.ccg index bdfd2619..a4185393 100644 --- a/glib/src/regex.ccg +++ b/glib/src/regex.ccg @@ -20,246 +20,242 @@ namespace Glib { -Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern, - RegexCompileFlags compile_options, - RegexMatchFlags match_options) +Glib::RefPtr<Glib::Regex> +Regex::create( + const Glib::ustring& pattern, RegexCompileFlags compile_options, RegexMatchFlags match_options) { GError* gerror = nullptr; - auto regex = g_regex_new(pattern.c_str(), (GRegexCompileFlags)compile_options, - (GRegexMatchFlags)match_options, &gerror); + auto regex = g_regex_new( + pattern.c_str(), (GRegexCompileFlags)compile_options, (GRegexMatchFlags)match_options, &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); return Glib::wrap(regex); } // static -Glib::ustring Regex::escape_string(const Glib::ustring& string) +Glib::ustring +Regex::escape_string(const Glib::ustring& string) { - const auto buf = make_unique_ptr_gfree(g_regex_escape_string(string.raw().c_str(), - string.raw().size())); + const auto buf = + make_unique_ptr_gfree(g_regex_escape_string(string.raw().c_str(), string.raw().size())); return Glib::ustring(buf.get()); } -bool Regex::match( - const Glib::ustring& string, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match( + const Glib::ustring& string, Glib::MatchInfo& match_info, RegexMatchFlags match_options) { GMatchInfo* ginfo = nullptr; - bool const result = static_cast<bool>(g_regex_match(gobj(), string.c_str(), - static_cast<GRegexMatchFlags>(match_options), &ginfo)); + bool const result = static_cast<bool>( + g_regex_match(gobj(), string.c_str(), static_cast<GRegexMatchFlags>(match_options), &ginfo)); match_info.set_gobject(ginfo); return result; } -bool Regex::match(const Glib::ustring& string, RegexMatchFlags match_options) +bool +Regex::match(const Glib::ustring& string, RegexMatchFlags match_options) { return g_regex_match(gobj(), string.c_str(), (GRegexMatchFlags)(match_options), nullptr); } -bool Regex::match( - const Glib::ustring& string, - int start_position, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match(const Glib::ustring& string, int start_position, Glib::MatchInfo& match_info, + RegexMatchFlags match_options) { GError* gerror = nullptr; GMatchInfo* ginfo = nullptr; - bool const result = static_cast<bool>(g_regex_match_full(gobj(), - string.c_str(), -1, start_position, - static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); + bool const result = static_cast<bool>(g_regex_match_full(gobj(), string.c_str(), -1, + start_position, static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); - if(gerror) + if (gerror) ::Glib::Error::throw_exception(gerror); match_info.set_gobject(ginfo); return result; } -bool Regex::match( - const Glib::ustring& string, - gssize string_len, - int start_position, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match(const Glib::ustring& string, gssize string_len, int start_position, + Glib::MatchInfo& match_info, RegexMatchFlags match_options) { GError* gerror = nullptr; GMatchInfo* ginfo = nullptr; - bool const result = static_cast<bool>(g_regex_match_full(gobj(), - string.c_str(), string_len, start_position, - static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); + bool const result = static_cast<bool>(g_regex_match_full(gobj(), string.c_str(), string_len, + start_position, static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); - if(gerror) + if (gerror) ::Glib::Error::throw_exception(gerror); match_info.set_gobject(ginfo); return result; } -bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options) +bool +Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options) { GError* gerror = nullptr; - bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); - if(gerror) + bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, + ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options) +bool +Regex::match( + const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options) { GError* gerror = nullptr; - bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); - if(gerror) + bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, + ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -bool Regex::match_all( - const Glib::ustring& string, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match_all( + const Glib::ustring& string, Glib::MatchInfo& match_info, RegexMatchFlags match_options) { GMatchInfo* ginfo = nullptr; - bool const result = static_cast<bool>(g_regex_match_all(gobj(), - string.c_str(), static_cast<GRegexMatchFlags>(match_options), - &ginfo)); + bool const result = static_cast<bool>(g_regex_match_all( + gobj(), string.c_str(), static_cast<GRegexMatchFlags>(match_options), &ginfo)); match_info.set_gobject(ginfo); return result; } -bool Regex::match_all(const Glib::ustring& string, RegexMatchFlags match_options) +bool +Regex::match_all(const Glib::ustring& string, RegexMatchFlags match_options) { return g_regex_match_all(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), nullptr); } -bool Regex::match_all( - const Glib::ustring& string, - int start_position, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match_all(const Glib::ustring& string, int start_position, Glib::MatchInfo& match_info, + RegexMatchFlags match_options) { GError* gerror = nullptr; GMatchInfo* ginfo = nullptr; - bool const retvalue = static_cast<bool>(g_regex_match_all_full(gobj(), - string.c_str(), -1, start_position, - static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); + bool const retvalue = static_cast<bool>(g_regex_match_all_full(gobj(), string.c_str(), -1, + start_position, static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); - if(gerror) + if (gerror) ::Glib::Error::throw_exception(gerror); match_info.set_gobject(ginfo); return retvalue; } -bool Regex::match_all( - const Glib::ustring& string, - gssize string_len, - int start_position, - Glib::MatchInfo& match_info, - RegexMatchFlags match_options -) +bool +Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, + Glib::MatchInfo& match_info, RegexMatchFlags match_options) { GError* gerror = nullptr; GMatchInfo* ginfo = nullptr; - bool const retvalue = static_cast<bool>(g_regex_match_all_full(gobj(), - string.c_str(), string_len, start_position, - static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); + bool const retvalue = static_cast<bool>(g_regex_match_all_full(gobj(), string.c_str(), string_len, + start_position, static_cast<GRegexMatchFlags>(match_options), &ginfo, &gerror)); - if(gerror) + if (gerror) ::Glib::Error::throw_exception(gerror); match_info.set_gobject(ginfo); return retvalue; } -bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options) +bool +Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options) { GError* gerror = nullptr; - bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); - if(gerror) + bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, + ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options) +bool +Regex::match_all( + const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options) { GError* gerror = nullptr; - bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); - if(gerror) + bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, + ((GRegexMatchFlags)(match_options)), nullptr, &(gerror)); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -Glib::ustring Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options) +Glib::ustring +Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, + RegexMatchFlags match_options) { GError* gerror = nullptr; - auto retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror))); - if(gerror) + auto retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace(gobj(), string.c_str(), + -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror))); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } - -Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options) +Glib::ustring +Regex::replace_literal(const Glib::ustring& string, int start_position, + const Glib::ustring& replacement, RegexMatchFlags match_options) { GError* gerror = nullptr; - auto retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace_literal(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror))); - if(gerror) + auto retvalue = + Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace_literal(gobj(), string.c_str(), -1, + start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror))); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } -Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const +Glib::StringArrayHandle +Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, + int max_tokens) const { GError* gerror = nullptr; - auto retvalue = Glib::StringArrayHandle(g_regex_split_full(const_cast<GRegex*>(gobj()), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), max_tokens, &(gerror)), Glib::OWNERSHIP_DEEP); - if(gerror) + auto retvalue = Glib::StringArrayHandle( + g_regex_split_full(const_cast<GRegex*>(gobj()), string.c_str(), -1, start_position, + ((GRegexMatchFlags)(match_options)), max_tokens, &(gerror)), + Glib::OWNERSHIP_DEEP); + if (gerror) ::Glib::Error::throw_exception(gerror); return retvalue; } - -MatchInfo::MatchInfo() -: gobject_(nullptr), - take_ownership(false) +MatchInfo::MatchInfo() : gobject_(nullptr), take_ownership(false) { } MatchInfo::MatchInfo(GMatchInfo* castitem, bool take_the_ownership) -: gobject_(castitem), - take_ownership(take_the_ownership) +: gobject_(castitem), take_ownership(take_the_ownership) { } - -MatchInfo::MatchInfo(MatchInfo&& other) noexcept -: gobject_(std::move(other.gobject_)), - take_ownership(std::move(other.take_ownership)) +MatchInfo::MatchInfo(MatchInfo&& other) noexcept : gobject_(std::move(other.gobject_)), + take_ownership(std::move(other.take_ownership)) { other.gobject_ = nullptr; other.take_ownership = false; } -MatchInfo& MatchInfo::operator=(MatchInfo&& other) noexcept +MatchInfo& +MatchInfo::operator=(MatchInfo&& other) noexcept { - if(take_ownership && gobject_) + if (take_ownership && gobject_) g_match_info_free(gobject_); gobject_ = std::move(other.gobject_); @@ -271,9 +267,10 @@ MatchInfo& MatchInfo::operator=(MatchInfo&& other) noexcept return *this; } -void MatchInfo::set_gobject(GMatchInfo* castitem, bool take_the_ownership) +void +MatchInfo::set_gobject(GMatchInfo* castitem, bool take_the_ownership) { - if(gobject_ && this->take_ownership) + if (gobject_ && this->take_ownership) g_match_info_free(gobject_); gobject_ = castitem; @@ -282,7 +279,7 @@ void MatchInfo::set_gobject(GMatchInfo* castitem, bool take_the_ownership) MatchInfo::~MatchInfo() { - if(take_ownership && gobject_) + if (take_ownership && gobject_) g_match_info_free(gobject_); } diff --git a/glib/src/shell.ccg b/glib/src/shell.ccg index 84b9a512..aaa34379 100644 --- a/glib/src/shell.ccg +++ b/glib/src/shell.ccg @@ -17,42 +17,43 @@ #include <glibmm/utility.h> - namespace Glib { /**** shell utility functions **********************************************/ -Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line) +Glib::ArrayHandle<std::string> +shell_parse_argv(const std::string& command_line) { - char** argv = nullptr; - int argc = 0; + char** argv = nullptr; + int argc = 0; GError* error = nullptr; g_shell_parse_argv(command_line.c_str(), &argc, &argv, &error); - if(error) + if (error) Glib::Error::throw_exception(error); return Glib::ArrayHandle<std::string>(argv, argc, Glib::OWNERSHIP_DEEP); } -std::string shell_quote(const std::string& unquoted_string) +std::string +shell_quote(const std::string& unquoted_string) { const auto buf = make_unique_ptr_gfree(g_shell_quote(unquoted_string.c_str())); return std::string(buf.get()); } -std::string shell_unquote(const std::string& quoted_string) +std::string +shell_unquote(const std::string& quoted_string) { GError* error = nullptr; - char *const buf = g_shell_unquote(quoted_string.c_str(), &error); + char* const buf = g_shell_unquote(quoted_string.c_str(), &error); - if(error) + if (error) Glib::Error::throw_exception(error); return std::string(make_unique_ptr_gfree(buf).get()); } } // namespace Glib - diff --git a/glib/src/spawn.ccg b/glib/src/spawn.ccg index 7369f5f1..867e413f 100644 --- a/glib/src/spawn.ccg +++ b/glib/src/spawn.ccg @@ -19,198 +19,153 @@ #include <glibmm/exceptionhandler.h> #include <glibmm/utility.h> - namespace { -extern "C" -{ +extern "C" { /* Helper callback to invoke the actual sigc++ slot. * We don't need to worry about (un)referencing, since the * child process gets its own copy of the parent's memory anyway. */ -static void child_setup_callback(void* user_data) +static void +child_setup_callback(void* user_data) { try { (*reinterpret_cast<Glib::SlotSpawnChildSetup*>(user_data))(); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } } -static void copy_output_buf(std::string* dest, const char* buf) +static void +copy_output_buf(std::string* dest, const char* buf) { - if(dest) + if (dest) { - if(buf) + if (buf) *dest = buf; else dest->erase(); } } -} //extern "C" - -} //anonymous namespace +} // extern "C" +} // anonymous namespace namespace Glib { /**** process spawning functions *******************************************/ -void spawn_async_with_pipes(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - const Glib::ArrayHandle<std::string>& envp, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - Pid* child_pid, - int* standard_input, - int* standard_output, - int* standard_error) +void +spawn_async_with_pipes(const std::string& working_directory, + const Glib::ArrayHandle<std::string>& argv, const Glib::ArrayHandle<std::string>& envp, + SpawnFlags flags, const SlotSpawnChildSetup& child_setup, Pid* child_pid, int* standard_input, + int* standard_output, int* standard_error) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; GError* gerror = nullptr; - g_spawn_async_with_pipes( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), - const_cast<char**>(envp.data()), - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - child_pid, - standard_input, standard_output, standard_error, - &gerror); - - if(gerror) + g_spawn_async_with_pipes(Glib::c_str_or_nullptr(working_directory), + const_cast<char**>(argv.data()), const_cast<char**>(envp.data()), + static_cast<GSpawnFlags>(unsigned(flags)), (setup_slot) ? &child_setup_callback : nullptr, + (setup_slot) ? &child_setup_ : nullptr, child_pid, standard_input, standard_output, + standard_error, &gerror); + + if (gerror) Glib::Error::throw_exception(gerror); } -void spawn_async_with_pipes(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - Pid* child_pid, - int* standard_input, - int* standard_output, - int* standard_error) +void +spawn_async_with_pipes(const std::string& working_directory, + const Glib::ArrayHandle<std::string>& argv, SpawnFlags flags, + const SlotSpawnChildSetup& child_setup, Pid* child_pid, int* standard_input, int* standard_output, + int* standard_error) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; GError* gerror = nullptr; - g_spawn_async_with_pipes( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), nullptr, - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - child_pid, - standard_input, standard_output, standard_error, - &gerror); - - if(gerror) + g_spawn_async_with_pipes(Glib::c_str_or_nullptr(working_directory), + const_cast<char**>(argv.data()), nullptr, static_cast<GSpawnFlags>(unsigned(flags)), + (setup_slot) ? &child_setup_callback : nullptr, (setup_slot) ? &child_setup_ : nullptr, + child_pid, standard_input, standard_output, standard_error, &gerror); + + if (gerror) Glib::Error::throw_exception(gerror); } -void spawn_async(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - const Glib::ArrayHandle<std::string>& envp, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - Pid* child_pid) +void +spawn_async(const std::string& working_directory, const Glib::ArrayHandle<std::string>& argv, + const Glib::ArrayHandle<std::string>& envp, SpawnFlags flags, + const SlotSpawnChildSetup& child_setup, Pid* child_pid) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; GError* gerror = nullptr; - g_spawn_async( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), - const_cast<char**>(envp.data()), - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - child_pid, - &gerror); - - if(gerror) + g_spawn_async(Glib::c_str_or_nullptr(working_directory), const_cast<char**>(argv.data()), + const_cast<char**>(envp.data()), static_cast<GSpawnFlags>(unsigned(flags)), + (setup_slot) ? &child_setup_callback : nullptr, (setup_slot) ? &child_setup_ : nullptr, + child_pid, &gerror); + + if (gerror) Glib::Error::throw_exception(gerror); } -void spawn_async(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - Pid* child_pid) +void +spawn_async(const std::string& working_directory, const Glib::ArrayHandle<std::string>& argv, + SpawnFlags flags, const SlotSpawnChildSetup& child_setup, Pid* child_pid) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; GError* gerror = nullptr; - g_spawn_async( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), nullptr, - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - child_pid, - &gerror); + g_spawn_async(Glib::c_str_or_nullptr(working_directory), const_cast<char**>(argv.data()), nullptr, + static_cast<GSpawnFlags>(unsigned(flags)), (setup_slot) ? &child_setup_callback : nullptr, + (setup_slot) ? &child_setup_ : nullptr, child_pid, &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); } -void spawn_sync(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - const Glib::ArrayHandle<std::string>& envp, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - std::string* standard_output, - std::string* standard_error, - int* exit_status) +void +spawn_sync(const std::string& working_directory, const Glib::ArrayHandle<std::string>& argv, + const Glib::ArrayHandle<std::string>& envp, SpawnFlags flags, + const SlotSpawnChildSetup& child_setup, std::string* standard_output, std::string* standard_error, + int* exit_status) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; - GError* gerror = nullptr; char* pch_buf_standard_output = nullptr; char* pch_buf_standard_error = nullptr; - g_spawn_sync( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), - const_cast<char**>(envp.data()), - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - (standard_output) ? &pch_buf_standard_output : nullptr, - (standard_error) ? &pch_buf_standard_error : nullptr, - exit_status, - &gerror); + g_spawn_sync(Glib::c_str_or_nullptr(working_directory), const_cast<char**>(argv.data()), + const_cast<char**>(envp.data()), static_cast<GSpawnFlags>(unsigned(flags)), + (setup_slot) ? &child_setup_callback : nullptr, (setup_slot) ? &child_setup_ : nullptr, + (standard_output) ? &pch_buf_standard_output : nullptr, + (standard_error) ? &pch_buf_standard_error : nullptr, exit_status, &gerror); auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output); auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); copy_output_buf(standard_output, buf_standard_output.get()); copy_output_buf(standard_error, buf_standard_error.get()); } -void spawn_sync(const std::string& working_directory, - const Glib::ArrayHandle<std::string>& argv, - SpawnFlags flags, - const SlotSpawnChildSetup& child_setup, - std::string* standard_output, - std::string* standard_error, - int* exit_status) +void +spawn_sync(const std::string& working_directory, const Glib::ArrayHandle<std::string>& argv, + SpawnFlags flags, const SlotSpawnChildSetup& child_setup, std::string* standard_output, + std::string* standard_error, int* exit_status) { const bool setup_slot = !child_setup.empty(); auto child_setup_ = child_setup; @@ -219,64 +174,55 @@ void spawn_sync(const std::string& working_directory, char* pch_buf_standard_error = nullptr; GError* gerror = nullptr; - g_spawn_sync( - Glib::c_str_or_nullptr(working_directory), - const_cast<char**>(argv.data()), nullptr, - static_cast<GSpawnFlags>(unsigned(flags)), - (setup_slot) ? &child_setup_callback : nullptr, - (setup_slot) ? &child_setup_ : nullptr, - (standard_output) ? &pch_buf_standard_output : nullptr, - (standard_error) ? &pch_buf_standard_error : nullptr, - exit_status, - &gerror); + g_spawn_sync(Glib::c_str_or_nullptr(working_directory), const_cast<char**>(argv.data()), nullptr, + static_cast<GSpawnFlags>(unsigned(flags)), (setup_slot) ? &child_setup_callback : nullptr, + (setup_slot) ? &child_setup_ : nullptr, (standard_output) ? &pch_buf_standard_output : nullptr, + (standard_error) ? &pch_buf_standard_error : nullptr, exit_status, &gerror); auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output); auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); copy_output_buf(standard_output, buf_standard_output.get()); copy_output_buf(standard_error, buf_standard_error.get()); } -void spawn_command_line_async(const std::string& command_line) +void +spawn_command_line_async(const std::string& command_line) { GError* gerror = nullptr; g_spawn_command_line_async(command_line.c_str(), &gerror); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); } -void spawn_command_line_sync(const std::string& command_line, - std::string* standard_output, - std::string* standard_error, - int* exit_status) +void +spawn_command_line_sync(const std::string& command_line, std::string* standard_output, + std::string* standard_error, int* exit_status) { char* pch_buf_standard_output = nullptr; char* pch_buf_standard_error = nullptr; GError* gerror = nullptr; - g_spawn_command_line_sync( - command_line.c_str(), - (standard_output) ? &pch_buf_standard_output : nullptr, - (standard_error) ? &pch_buf_standard_error : nullptr, - exit_status, - &gerror); + g_spawn_command_line_sync(command_line.c_str(), + (standard_output) ? &pch_buf_standard_output : nullptr, + (standard_error) ? &pch_buf_standard_error : nullptr, exit_status, &gerror); auto buf_standard_output = make_unique_ptr_gfree(pch_buf_standard_output); auto buf_standard_error = make_unique_ptr_gfree(pch_buf_standard_error); - if(gerror) + if (gerror) Glib::Error::throw_exception(gerror); copy_output_buf(standard_output, buf_standard_output.get()); copy_output_buf(standard_error, buf_standard_error.get()); } -void spawn_close_pid(Pid pid) +void +spawn_close_pid(Pid pid) { g_spawn_close_pid(pid); } } // namespace Glib - diff --git a/glib/src/thread.ccg b/glib/src/thread.ccg index af4695fc..3d6d7955 100644 --- a/glib/src/thread.ccg +++ b/glib/src/thread.ccg @@ -21,10 +21,10 @@ namespace { -extern "C" -{ +extern "C" { -static void* call_thread_entry_slot(void* data) +static void* +call_thread_entry_slot(void* data) { const auto slot = reinterpret_cast<sigc::slot_base*>(data); @@ -33,12 +33,12 @@ static void* call_thread_entry_slot(void* data) // Recreate the specific slot, and drop the reference obtained by create(). (*static_cast<sigc::slot<void>*>(slot))(); } - catch(Glib::Thread::Exit&) + catch (Glib::Thread::Exit&) { // Just exit from the thread. The Thread::Exit exception // is our sane C++ replacement of g_thread_exit(). } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -47,11 +47,10 @@ static void* call_thread_entry_slot(void* data) return nullptr; } -} //extern "C" +} // extern "C" } // anonymous namespace - namespace Glib { @@ -59,7 +58,8 @@ namespace Glib // and no longer needs to be called. We are keeping it just to avoid // breaking ABI, though hopefully nobody is using it anyway. // TODO: Remove this when we can break ABI. -void thread_init_impl() +void +thread_init_impl() { // Make sure the exception map is initialized before creating any thread. Glib::Error::register_init(); @@ -68,17 +68,17 @@ void thread_init_impl() /**** Glib::Thread *********************************************************/ // static -Thread* Thread::create(const sigc::slot<void>& slot, bool /* joinable */) +Thread* +Thread::create(const sigc::slot<void>& slot, bool /* joinable */) { // Make a copy of slot on the heap const auto slot_copy = new sigc::slot<void>(slot); GError* error = nullptr; - const auto thread = g_thread_try_new(nullptr, - &call_thread_entry_slot, slot_copy, &error); + const auto thread = g_thread_try_new(nullptr, &call_thread_entry_slot, slot_copy, &error); - if(error) + if (error) { delete slot_copy; // Glib::Error::throw_exception() will probably wrap G_THREAD_ERROR in a @@ -93,19 +93,19 @@ Thread* Thread::create(const sigc::slot<void>& slot, bool /* joinable */) } // static -Thread* Thread::create(const sigc::slot<void>& slot, unsigned long stack_size, - bool joinable, bool bound, ThreadPriority priority) +Thread* +Thread::create(const sigc::slot<void>& slot, unsigned long stack_size, bool joinable, bool bound, + ThreadPriority priority) { // Make a copy of slot on the heap const auto slot_copy = new sigc::slot<void>(slot); GError* error = nullptr; - const auto thread = g_thread_create_full( - &call_thread_entry_slot, slot_copy, stack_size, joinable, - bound, (GThreadPriority) priority, &error); + const auto thread = g_thread_create_full(&call_thread_entry_slot, slot_copy, stack_size, joinable, + bound, (GThreadPriority)priority, &error); - if(error) + if (error) { delete slot_copy; // Glib::Error::throw_exception() will probably wrap G_THREAD_ERROR in a @@ -120,74 +120,85 @@ Thread* Thread::create(const sigc::slot<void>& slot, unsigned long stack_size, } // static -Thread* Thread::self() +Thread* +Thread::self() { return reinterpret_cast<Thread*>(g_thread_self()); } -void Thread::join() +void +Thread::join() { g_thread_join(&gobject_); } -bool Thread::joinable() const +bool +Thread::joinable() const { - return true; //An appropriate result now that this is deprecated because all threads are now joinable. + return true; // An appropriate result now that this is deprecated because all threads are now + // joinable. } -void Thread::set_priority(ThreadPriority priority) +void +Thread::set_priority(ThreadPriority priority) { - g_thread_set_priority(&gobject_, (GThreadPriority) priority); + g_thread_set_priority(&gobject_, (GThreadPriority)priority); } -ThreadPriority Thread::get_priority() const +ThreadPriority +Thread::get_priority() const { - return THREAD_PRIORITY_NORMAL; //An appropriate result now that this is deprecated because the priority concept has been removed. + return THREAD_PRIORITY_NORMAL; // An appropriate result now that this is deprecated because the + // priority concept has been removed. } -void thread_init(GThreadFunctions* /* vtable */) +void +thread_init(GThreadFunctions* /* vtable */) { - //g_thread_init() is deprecated and now does nothing, - //so we do not even call it. That avoids a need to link to gthread-2.0, - //which contains the empty g_thread_init() implementation. - //g_thread_init(vtable); + // g_thread_init() is deprecated and now does nothing, + // so we do not even call it. That avoids a need to link to gthread-2.0, + // which contains the empty g_thread_init() implementation. + // g_thread_init(vtable); Glib::thread_init_impl(); } -bool thread_supported() +bool +thread_supported() { - //MSVC++ needs the != 0 to avoid an int -> bool cast warning. + // MSVC++ needs the != 0 to avoid an int -> bool cast warning. return (g_thread_supported() != 0); } - // static -void Thread::yield() +void +Thread::yield() { g_thread_yield(); } - -Thread* wrap(GThread* gobject) +Thread* +wrap(GThread* gobject) { return reinterpret_cast<Thread*>(gobject); } - /**** Glib::StaticMutex ****************************************************/ -void StaticMutex::lock() +void +StaticMutex::lock() { g_static_mutex_lock(&gobject_); } -bool StaticMutex::trylock() +bool +StaticMutex::trylock() { return g_static_mutex_trylock(&gobject_); } -void StaticMutex::unlock() +void +StaticMutex::unlock() { g_static_mutex_unlock(&gobject_); } @@ -216,58 +227,64 @@ StaticMutex::operator Mutex&() return reinterpret_cast<Mutex&>(runtime_mutex); } - /**** Glib::Mutex **********************************************************/ Mutex::Mutex() -: - gobject_ (g_mutex_new()) //TODO: Use a statically-allocated GMutext instead, with g_mutex_init(). -{} +: gobject_(g_mutex_new()) // TODO: Use a statically-allocated GMutext instead, with g_mutex_init(). +{ +} Mutex::~Mutex() { g_mutex_free(gobject_); } -void Mutex::lock() +void +Mutex::lock() { g_mutex_lock(gobject_); } -bool Mutex::trylock() +bool +Mutex::trylock() { return g_mutex_trylock(gobject_); } -void Mutex::unlock() +void +Mutex::unlock() { g_mutex_unlock(gobject_); } - /**** Glib::StaticRecMutex *************************************************/ -void StaticRecMutex::lock() +void +StaticRecMutex::lock() { g_static_rec_mutex_lock(&gobject_); } -bool StaticRecMutex::trylock() +bool +StaticRecMutex::trylock() { return g_static_rec_mutex_trylock(&gobject_); } -void StaticRecMutex::unlock() +void +StaticRecMutex::unlock() { g_static_rec_mutex_unlock(&gobject_); } -void StaticRecMutex::lock_full(unsigned int depth) +void +StaticRecMutex::lock_full(unsigned int depth) { g_static_rec_mutex_lock_full(&gobject_, depth); } -unsigned int StaticRecMutex::unlock_full() +unsigned int +StaticRecMutex::unlock_full() { return g_static_rec_mutex_unlock_full(&gobject_); } @@ -277,7 +294,6 @@ StaticRecMutex::operator RecMutex&() return static_cast<RecMutex&>(*this); } - /**** Glib::RecMutex *******************************************************/ RecMutex::RecMutex() @@ -290,35 +306,40 @@ RecMutex::~RecMutex() g_static_rec_mutex_free(&gobject_); } - /**** Glib::StaticRWLock ***************************************************/ -void StaticRWLock::reader_lock() +void +StaticRWLock::reader_lock() { g_static_rw_lock_reader_lock(&gobject_); } -bool StaticRWLock::reader_trylock() +bool +StaticRWLock::reader_trylock() { return g_static_rw_lock_reader_trylock(&gobject_); } -void StaticRWLock::reader_unlock() +void +StaticRWLock::reader_unlock() { g_static_rw_lock_reader_unlock(&gobject_); } -void StaticRWLock::writer_lock() +void +StaticRWLock::writer_lock() { g_static_rw_lock_writer_lock(&gobject_); } -bool StaticRWLock::writer_trylock() +bool +StaticRWLock::writer_trylock() { return g_static_rw_lock_writer_trylock(&gobject_); } -void StaticRWLock::writer_unlock() +void +StaticRWLock::writer_unlock() { g_static_rw_lock_writer_unlock(&gobject_); } @@ -328,7 +349,6 @@ StaticRWLock::operator RWLock&() return static_cast<RWLock&>(*this); } - /**** Glib::RWLock *********************************************************/ RWLock::RWLock() @@ -339,9 +359,9 @@ RWLock::RWLock() // of the mutex and the condition variables now, to mimic the behaviour // of a (hypothetical) GRWLock. - if(g_static_mutex_get_mutex(&gobject_.mutex)) + if (g_static_mutex_get_mutex(&gobject_.mutex)) { - gobject_.read_cond = g_cond_new(); + gobject_.read_cond = g_cond_new(); gobject_.write_cond = g_cond_new(); } } @@ -351,51 +371,57 @@ RWLock::~RWLock() g_static_rw_lock_free(&gobject_); } - /**** Glib::Cond ***********************************************************/ -Cond::Cond() -: - gobject_ (g_cond_new()) -{} +Cond::Cond() : gobject_(g_cond_new()) +{ +} Cond::~Cond() { g_cond_free(gobject_); } -void Cond::signal() +void +Cond::signal() { g_cond_signal(gobject_); } -void Cond::broadcast() +void +Cond::broadcast() { g_cond_broadcast(gobject_); } -void Cond::wait(Mutex& mutex) +void +Cond::wait(Mutex& mutex) { g_cond_wait(gobject_, mutex.gobj()); } -bool Cond::timed_wait(Mutex& mutex, const Glib::TimeVal& abs_time) +bool +Cond::timed_wait(Mutex& mutex, const Glib::TimeVal& abs_time) { return g_cond_timed_wait(gobject_, mutex.gobj(), const_cast<Glib::TimeVal*>(&abs_time)); } -void* StaticPrivate_get_helper(GStaticPrivate *private_key) { +void* +StaticPrivate_get_helper(GStaticPrivate* private_key) +{ return g_static_private_get(private_key); } -void StaticPrivate_set_helper(GStaticPrivate *private_key, gpointer data, GDestroyNotify notify) { +void +StaticPrivate_set_helper(GStaticPrivate* private_key, gpointer data, GDestroyNotify notify) +{ return g_static_private_set(private_key, data, notify); } -GPrivate* GPrivate_new_helper(GDestroyNotify notify) { +GPrivate* +GPrivate_new_helper(GDestroyNotify notify) +{ return g_private_new(notify); } - } // namespace Glib - diff --git a/glib/src/threads.ccg b/glib/src/threads.ccg index 5830fae5..274b5a1e 100644 --- a/glib/src/threads.ccg +++ b/glib/src/threads.ccg @@ -35,10 +35,10 @@ namespace { -extern "C" -{ +extern "C" { -static void* call_thread_entry_slot(void* data) +static void* +call_thread_entry_slot(void* data) { const auto slot = reinterpret_cast<sigc::slot_base*>(data); @@ -61,11 +61,10 @@ static void* call_thread_entry_slot(void* data) return nullptr; } -} //extern "C" +} // extern "C" } // anonymous namespace - namespace Glib { @@ -75,14 +74,15 @@ namespace Threads /**** Glib::Threads::Thread ************************************************/ // static -Thread* Thread::create(const sigc::slot<void>& slot, const std::string& name) +Thread* +Thread::create(const sigc::slot<void>& slot, const std::string& name) { // Make a copy of slot on the heap. const auto slot_copy = new sigc::slot<void>(slot); GError* error = nullptr; - auto thread = g_thread_try_new(name.empty() ? nullptr : name.c_str(), - &call_thread_entry_slot, slot_copy, &error); + auto thread = g_thread_try_new( + name.empty() ? nullptr : name.c_str(), &call_thread_entry_slot, slot_copy, &error); if (error) { @@ -97,44 +97,50 @@ Thread* Thread::create(const sigc::slot<void>& slot, const std::string& name) } // static -Thread* Thread::create(const sigc::slot<void>& slot) +Thread* +Thread::create(const sigc::slot<void>& slot) { return create(slot, std::string()); } // static -Thread* Thread::self() +Thread* +Thread::self() { return reinterpret_cast<Thread*>(g_thread_self()); } -void Thread::join() +void +Thread::join() { g_thread_join(reinterpret_cast<GThread*>(this)); } // static -void Thread::yield() +void +Thread::yield() { g_thread_yield(); } -GThread* Thread::gobj() +GThread* +Thread::gobj() { return reinterpret_cast<GThread*>(this); } -const GThread* Thread::gobj() const +const GThread* +Thread::gobj() const { return reinterpret_cast<const GThread*>(this); } -Thread* wrap(GThread* gobject) +Thread* +wrap(GThread* gobject) { return reinterpret_cast<Thread*>(gobject); } - /**** Glib::Threads::Mutex *************************************************/ Mutex::Mutex() @@ -147,22 +153,26 @@ Mutex::~Mutex() g_mutex_clear(&gobject_); } -void Mutex::lock() +void +Mutex::lock() { g_mutex_lock(&gobject_); } -bool Mutex::trylock() +bool +Mutex::trylock() { return g_mutex_trylock(&gobject_); } -void Mutex::unlock() +void +Mutex::unlock() { g_mutex_unlock(&gobject_); } -Mutex* wrap(GMutex* gobject) +Mutex* +wrap(GMutex* gobject) { return reinterpret_cast<Mutex*>(gobject); } @@ -179,54 +189,64 @@ RecMutex::~RecMutex() g_rec_mutex_clear(&gobject_); } -void RecMutex::lock() +void +RecMutex::lock() { g_rec_mutex_lock(&gobject_); } -bool RecMutex::trylock() +bool +RecMutex::trylock() { return g_rec_mutex_trylock(&gobject_); } -void RecMutex::unlock() +void +RecMutex::unlock() { g_rec_mutex_unlock(&gobject_); } -RecMutex* wrap(GRecMutex* gobject) +RecMutex* +wrap(GRecMutex* gobject) { return reinterpret_cast<RecMutex*>(gobject); } /**** Glib::Threads::RWLock ************************************************/ -void RWLock::reader_lock() +void +RWLock::reader_lock() { g_rw_lock_reader_lock(&gobject_); } -bool RWLock::reader_trylock() +bool +RWLock::reader_trylock() { return g_rw_lock_reader_trylock(&gobject_); } -void RWLock::reader_unlock() +void +RWLock::reader_unlock() { g_rw_lock_reader_unlock(&gobject_); } -void RWLock::writer_lock() +void +RWLock::writer_lock() { g_rw_lock_writer_lock(&gobject_); } -bool RWLock::writer_trylock() +bool +RWLock::writer_trylock() { return g_rw_lock_writer_trylock(&gobject_); } -void RWLock::writer_unlock() +void +RWLock::writer_unlock() { g_rw_lock_writer_unlock(&gobject_); } @@ -241,7 +261,6 @@ RWLock::~RWLock() g_rw_lock_clear(&gobject_); } - /**** Glib::Threads::Cond **************************************************/ Cond::Cond() @@ -254,22 +273,26 @@ Cond::~Cond() g_cond_clear(&gobject_); } -void Cond::signal() +void +Cond::signal() { g_cond_signal(&gobject_); } -void Cond::broadcast() +void +Cond::broadcast() { g_cond_broadcast(&gobject_); } -void Cond::wait(Mutex& mutex) +void +Cond::wait(Mutex& mutex) { g_cond_wait(&gobject_, mutex.gobj()); } -bool Cond::wait_until(Mutex& mutex, gint64 end_time) +bool +Cond::wait_until(Mutex& mutex, gint64 end_time) { return g_cond_wait_until(&gobject_, mutex.gobj(), end_time); } @@ -277,4 +300,3 @@ bool Cond::wait_until(Mutex& mutex, gint64 end_time) } // namespace Threads } // namespace Glib - diff --git a/glib/src/timezone.ccg b/glib/src/timezone.ccg index 79957c1e..ad11205c 100644 --- a/glib/src/timezone.ccg +++ b/glib/src/timezone.ccg @@ -20,4 +20,4 @@ namespace Glib { -}// namespace Glib +} // namespace Glib diff --git a/glib/src/unicode.ccg b/glib/src/unicode.ccg index 28b07948..be4c2b5f 100644 --- a/glib/src/unicode.ccg +++ b/glib/src/unicode.ccg @@ -16,4 +16,3 @@ */ #include <glibmm/unicode.h> - diff --git a/glib/src/uriutils.ccg b/glib/src/uriutils.ccg index aeba8c42..c34848bb 100644 --- a/glib/src/uriutils.ccg +++ b/glib/src/uriutils.ccg @@ -21,22 +21,26 @@ namespace Glib { -std::string uri_unescape_string(const std::string& escaped_string, const std::string& illegal_characters) +std::string +uri_unescape_string(const std::string& escaped_string, const std::string& illegal_characters) { gchar* cresult = g_uri_unescape_string(escaped_string.c_str(), illegal_characters.c_str()); return Glib::convert_return_gchar_ptr_to_stdstring(cresult); } -std::string uri_parse_scheme(const std::string& uri) +std::string +uri_parse_scheme(const std::string& uri) { - return Glib::convert_return_gchar_ptr_to_stdstring( g_uri_parse_scheme(uri.c_str()) ); + return Glib::convert_return_gchar_ptr_to_stdstring(g_uri_parse_scheme(uri.c_str())); } -std::string uri_escape_string(const std::string& unescaped, const std::string& reserved_chars_allowed, bool allow_utf8) +std::string +uri_escape_string( + const std::string& unescaped, const std::string& reserved_chars_allowed, bool allow_utf8) { - gchar* cresult = g_uri_escape_string(unescaped.c_str(), reserved_chars_allowed.c_str(), allow_utf8); + gchar* cresult = + g_uri_escape_string(unescaped.c_str(), reserved_chars_allowed.c_str(), allow_utf8); return Glib::convert_return_gchar_ptr_to_stdstring(cresult); } } // namespace Glib - diff --git a/glib/src/valuearray.ccg b/glib/src/valuearray.ccg index 8b82aeda..e50323ff 100644 --- a/glib/src/valuearray.ccg +++ b/glib/src/valuearray.ccg @@ -17,18 +17,17 @@ #include <glibmm/exceptionhandler.h> -static int ValueArray_Compare_glibmm_callback(gconstpointer a, - gconstpointer b, gpointer user_data) +static int +ValueArray_Compare_glibmm_callback(gconstpointer a, gconstpointer b, gpointer user_data) { - Glib::ValueArray::SlotCompare* the_slot = - static_cast<Glib::ValueArray::SlotCompare*>(user_data); + Glib::ValueArray::SlotCompare* the_slot = static_cast<Glib::ValueArray::SlotCompare*>(user_data); try { - return (*the_slot)(*reinterpret_cast<const Glib::ValueBase*>(a), - *reinterpret_cast<const Glib::ValueBase*>(b)); + return (*the_slot)( + *reinterpret_cast<const Glib::ValueBase*>(a), *reinterpret_cast<const Glib::ValueBase*>(b)); } - catch(...) + catch (...) { Glib::exception_handlers_invoke(); } @@ -40,17 +39,19 @@ namespace Glib { ValueArray::ValueArray() : gobject_(g_value_array_new(0)) -{} +{ +} -ValueArray::ValueArray(guint n_preallocated) : - gobject_(g_value_array_new(n_preallocated)) -{} +ValueArray::ValueArray(guint n_preallocated) : gobject_(g_value_array_new(n_preallocated)) +{ +} -bool ValueArray::get_nth(guint index, Glib::ValueBase& value) +bool +ValueArray::get_nth(guint index, Glib::ValueBase& value) { const auto g_value = g_value_array_get_nth(gobj(), index); - if(g_value) + if (g_value) { value.init(g_value); return true; @@ -59,35 +60,39 @@ bool ValueArray::get_nth(guint index, Glib::ValueBase& value) return false; } -Glib::ValueArray& ValueArray::append(const Glib::ValueBase& value) +Glib::ValueArray& +ValueArray::append(const Glib::ValueBase& value) { g_value_array_append(gobj(), value.gobj()); return *this; } -Glib::ValueArray& ValueArray::prepend(const Glib::ValueBase& value) +Glib::ValueArray& +ValueArray::prepend(const Glib::ValueBase& value) { g_value_array_prepend(gobj(), value.gobj()); return *this; } -Glib::ValueArray& ValueArray::insert(guint index, const Glib::ValueBase& value) +Glib::ValueArray& +ValueArray::insert(guint index, const Glib::ValueBase& value) { g_value_array_insert(gobj(), index, value.gobj()); return *this; } -Glib::ValueArray& ValueArray::remove(guint index) +Glib::ValueArray& +ValueArray::remove(guint index) { g_value_array_remove(gobj(), index); return *this; } -Glib::ValueArray& ValueArray::sort(const SlotCompare& compare_func) +Glib::ValueArray& +ValueArray::sort(const SlotCompare& compare_func) { SlotCompare slot_copy(compare_func); - g_value_array_sort_with_data(gobj(), &ValueArray_Compare_glibmm_callback, - &slot_copy); + g_value_array_sort_with_data(gobj(), &ValueArray_Compare_glibmm_callback, &slot_copy); return *this; } diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg index aba6902b..3093dfa2 100644 --- a/glib/src/variant.ccg +++ b/glib/src/variant.ccg @@ -29,34 +29,36 @@ VariantBase::VariantBase(GVariant* castitem, bool make_a_copy /* = false */) { if (g_variant_is_floating(castitem)) { - g_variant_ref_sink (castitem); + g_variant_ref_sink(castitem); } if (make_a_copy) { - g_variant_ref (castitem); + g_variant_ref(castitem); } } gobject_ = castitem; } -void VariantBase::get_normal_form(VariantBase& result) const +void +VariantBase::get_normal_form(VariantBase& result) const { - GVariant* const g_value = - g_variant_get_normal_form(const_cast<GVariant*>(gobj())); + GVariant* const g_value = g_variant_get_normal_form(const_cast<GVariant*>(gobj())); - //The C function never returns NULL, according to its documenation, - //so we don't need a bool return value. + // The C function never returns NULL, according to its documenation, + // so we don't need a bool return value. result.init(g_value); // g_value is already referenced. } -void VariantBase::byteswap(VariantBase& result) const +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. } -bool VariantBase::is_castable_to(const VariantType& supertype) const +bool +VariantBase::is_castable_to(const VariantType& supertype) const { const std::string subtype_string = get_type_string(); const std::string supertype_string = supertype.get_string(); @@ -93,7 +95,7 @@ bool VariantBase::is_castable_to(const VariantType& supertype) const case 'a': if (!(supertype_string[supertype_index] == 'y' && - (subtype_char == 's' || subtype_char == 'o' || subtype_char == 'g'))) + (subtype_char == 's' || subtype_char == 'o' || subtype_char == 'g'))) return false; supertype_index++; break; @@ -110,9 +112,7 @@ bool VariantBase::is_castable_to(const VariantType& supertype) const return true; } - -VariantStringBase::VariantStringBase() -: VariantBase() +VariantStringBase::VariantStringBase() : VariantBase() { } @@ -121,9 +121,9 @@ VariantStringBase::VariantStringBase(GVariant* castitem, bool take_a_reference) { } -//static -void VariantStringBase::create_object_path(VariantStringBase& output, - const std::string& object_path) +// static +void +VariantStringBase::create_object_path(VariantStringBase& output, const std::string& object_path) { GVariant* result = nullptr; result = g_variant_new_object_path(object_path.c_str()); @@ -131,9 +131,9 @@ void VariantStringBase::create_object_path(VariantStringBase& output, output.init(result); } -//static -void VariantStringBase::create_signature(VariantStringBase& output, - const std::string& signature) +// static +void +VariantStringBase::create_signature(VariantStringBase& output, const std::string& signature) { GVariant* result = nullptr; result = g_variant_new_signature(signature.c_str()); @@ -141,9 +141,7 @@ void VariantStringBase::create_signature(VariantStringBase& output, output.init(result); } - -VariantContainerBase::VariantContainerBase() -: VariantBase() +VariantContainerBase::VariantContainerBase() : VariantBase() { } @@ -152,25 +150,25 @@ VariantContainerBase::VariantContainerBase(GVariant* castitem, bool take_a_refer { } -//static +// static VariantContainerBase VariantContainerBase::create_tuple(const std::vector<VariantBase>& children) { typedef GVariant* var_ptr; var_ptr* const var_array = new var_ptr[children.size()]; - for(std::vector<VariantBase>::size_type i = 0; i < children.size(); i++) + for (std::vector<VariantBase>::size_type i = 0; i < children.size(); i++) { var_array[i] = const_cast<GVariant*>(children[i].gobj()); } - VariantContainerBase result = VariantContainerBase(g_variant_new_tuple( - var_array, children.size())); + VariantContainerBase result = + VariantContainerBase(g_variant_new_tuple(var_array, children.size())); delete[] var_array; return result; } -//static +// static VariantContainerBase VariantContainerBase::create_tuple(const VariantBase& child) { @@ -179,53 +177,51 @@ VariantContainerBase::create_tuple(const VariantBase& child) return create_tuple(vec); } -//static +// static VariantContainerBase -VariantContainerBase::create_maybe(const VariantType& child_type, - const VariantBase& child) +VariantContainerBase::create_maybe(const VariantType& child_type, const VariantBase& child) { - GVariant* g_variant = g_variant_new_maybe(child_type.gobj(), - const_cast<GVariant*>(child.gobj())); + GVariant* g_variant = g_variant_new_maybe(child_type.gobj(), const_cast<GVariant*>(child.gobj())); VariantContainerBase result = VariantContainerBase(g_variant); return result; } -void VariantContainerBase::get_child(VariantBase& child, gsize index) const +void +VariantContainerBase::get_child(VariantBase& child, gsize index) const { - if(index >= g_variant_n_children(gobject_)) - throw std::out_of_range( - "VariantContainerBase::get_child(): Index out of bounds."); + if (index >= g_variant_n_children(gobject_)) + throw std::out_of_range("VariantContainerBase::get_child(): Index out of bounds."); GVariant* const gvariant = g_variant_get_child_value(gobject_, index); child.init(gvariant); } // VariantContainerBase has no method variant_type() -template<> -VariantContainerBase VariantBase::cast_dynamic<VariantContainerBase>(const VariantBase& v) -throw(std::bad_cast) +template <> +VariantContainerBase +VariantBase::cast_dynamic<VariantContainerBase>(const VariantBase& v) throw(std::bad_cast) { - if(!v.gobj()) + if (!v.gobj()) { return VariantContainerBase(); } - if(v.get_type().is_container()) + if (v.get_type().is_container()) { return VariantContainerBase(const_cast<GVariant*>(v.gobj()), true); } else { - //std::cerr << "vtype=" << v.get_type_string() << std::endl; + // std::cerr << "vtype=" << v.get_type_string() << std::endl; throw std::bad_cast(); } } -bool VariantContainerBase::get_maybe(VariantBase& maybe) const +bool +VariantContainerBase::get_maybe(VariantBase& maybe) const { - GVariant* const g_value = - g_variant_get_maybe(const_cast<GVariant*>(gobj())); + GVariant* const g_value = g_variant_get_maybe(const_cast<GVariant*>(gobj())); - if(g_value) + if (g_value) { maybe.init(g_value); // g_value is already referenced. return true; @@ -234,7 +230,8 @@ bool VariantContainerBase::get_maybe(VariantBase& maybe) const return false; } -VariantIter VariantContainerBase::get_iter(const VariantType& container_variant_type) const +VariantIter +VariantContainerBase::get_iter(const VariantType& container_variant_type) const { // Get the GVariantIter. // If the underlying GVariant can be cast to the type of the container, @@ -243,8 +240,8 @@ VariantIter VariantContainerBase::get_iter(const VariantType& container_variant_ // otherwise let g_variant_get() report what's wrong with the type. GVariantIter* g_iter = nullptr; g_variant_get(const_cast<GVariant*>(gobj()), - is_castable_to(container_variant_type) ? - get_type_string().c_str() : container_variant_type.get_string().c_str(), + is_castable_to(container_variant_type) ? get_type_string().c_str() + : container_variant_type.get_string().c_str(), &g_iter); return VariantIter(g_iter); @@ -257,20 +254,20 @@ VariantBase::operator const void*() const return gobj() ? GINT_TO_POINTER(1) : nullptr; } -void VariantBase::init(const GVariant* cobject, bool take_a_reference) +void +VariantBase::init(const GVariant* cobject, bool take_a_reference) { - if(gobject_) + if (gobject_) g_variant_unref(gobject_); gobject_ = const_cast<GVariant*>(cobject); - if(take_a_reference) + if (take_a_reference) g_variant_ref(gobject_); } /*--------------------Variant<VariantBase>---------------------*/ -Variant<VariantBase>::Variant() -: VariantContainerBase() +Variant<VariantBase>::Variant() : VariantContainerBase() { } @@ -280,18 +277,21 @@ Variant<VariantBase>::Variant(GVariant* castitem, bool take_a_reference) } // static -const VariantType& Variant<VariantBase>::variant_type() +const VariantType& +Variant<VariantBase>::variant_type() { return VARIANT_TYPE_VARIANT; } -Variant<VariantBase> Variant<VariantBase>::create(const VariantBase& data) +Variant<VariantBase> +Variant<VariantBase>::create(const VariantBase& data) { auto result = Variant<VariantBase>(g_variant_new_variant(const_cast<GVariant*>(data.gobj()))); return result; } -void Variant<VariantBase>::get(VariantBase& variant) const +void +Variant<VariantBase>::get(VariantBase& variant) const { GVariant* const gvariant = g_variant_get_variant(gobject_); variant.init(gvariant); @@ -299,8 +299,7 @@ void Variant<VariantBase>::get(VariantBase& variant) const /*--------------------Variant<Glib::ustring>---------------------*/ -Variant<Glib::ustring>::Variant() -: VariantStringBase() +Variant<Glib::ustring>::Variant() : VariantStringBase() { } @@ -310,7 +309,8 @@ Variant<Glib::ustring>::Variant(GVariant* castitem, bool take_a_reference) } // static -const VariantType& Variant<Glib::ustring>::variant_type() +const VariantType& +Variant<Glib::ustring>::variant_type() { return VARIANT_TYPE_STRING; } @@ -318,45 +318,43 @@ const VariantType& Variant<Glib::ustring>::variant_type() Variant<Glib::ustring> Variant<Glib::ustring>::create(const Glib::ustring& data) { - auto result = - Variant<Glib::ustring>(g_variant_new_string(data.c_str())); + auto result = Variant<Glib::ustring>(g_variant_new_string(data.c_str())); return result; } -Glib::ustring Variant<Glib::ustring>::get() const +Glib::ustring +Variant<Glib::ustring>::get() const { return convert_const_gchar_ptr_to_ustring(g_variant_get_string(gobject_, nullptr)); } // Variant<Glib::ustring> makes sense for multiple types. // See http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-get-string -template<> -Variant<Glib::ustring> VariantBase::cast_dynamic< Variant<Glib::ustring> >(const VariantBase& v) -throw(std::bad_cast) +template <> +Variant<Glib::ustring> +VariantBase::cast_dynamic<Variant<Glib::ustring>>(const VariantBase& v) throw(std::bad_cast) { - if(!v.gobj()) + if (!v.gobj()) { return Variant<Glib::ustring>(); } const VariantType vtype = v.get_type(); - if( vtype.equal(VARIANT_TYPE_STRING) || - vtype.equal(VARIANT_TYPE_OBJECT_PATH) || - vtype.equal(VARIANT_TYPE_SIGNATURE) ) + if (vtype.equal(VARIANT_TYPE_STRING) || vtype.equal(VARIANT_TYPE_OBJECT_PATH) || + vtype.equal(VARIANT_TYPE_SIGNATURE)) { return Variant<Glib::ustring>(const_cast<GVariant*>(v.gobj()), true); } else { - //std::cerr << "vtype=" << v.get_type_string() << std::endl; + // std::cerr << "vtype=" << v.get_type_string() << std::endl; throw std::bad_cast(); } } /*--------------------Variant<std::string>---------------------*/ -Variant<std::string>::Variant() -: VariantStringBase() +Variant<std::string>::Variant() : VariantStringBase() { } @@ -366,7 +364,8 @@ Variant<std::string>::Variant(GVariant* castitem, bool take_a_reference) } // static -const VariantType& Variant<std::string>::variant_type() +const VariantType& +Variant<std::string>::variant_type() { return VARIANT_TYPE_BYTESTRING; } @@ -374,45 +373,43 @@ const VariantType& Variant<std::string>::variant_type() Variant<std::string> Variant<std::string>::create(const std::string& data) { - auto result = - Variant<std::string>(g_variant_new_bytestring(data.c_str())); + auto result = Variant<std::string>(g_variant_new_bytestring(data.c_str())); return result; } // Variant<std::string> makes sense for multiple types. // See http://library.gnome.org/devel/glib/unstable/glib-GVariant.html#g-variant-get-string -template<> -Variant<std::string> VariantBase::cast_dynamic< Variant<std::string> >(const VariantBase& v) -throw(std::bad_cast) +template <> +Variant<std::string> +VariantBase::cast_dynamic<Variant<std::string>>(const VariantBase& v) throw(std::bad_cast) { - if(!v.gobj()) + if (!v.gobj()) { return Variant<std::string>(); } const VariantType vtype = v.get_type(); - if( vtype.equal(VARIANT_TYPE_STRING) || - vtype.equal(VARIANT_TYPE_BYTESTRING) || - vtype.equal(VARIANT_TYPE_OBJECT_PATH) || - vtype.equal(VARIANT_TYPE_SIGNATURE) ) + if (vtype.equal(VARIANT_TYPE_STRING) || vtype.equal(VARIANT_TYPE_BYTESTRING) || + vtype.equal(VARIANT_TYPE_OBJECT_PATH) || vtype.equal(VARIANT_TYPE_SIGNATURE)) { return Variant<std::string>(const_cast<GVariant*>(v.gobj()), true); } else { - //std::cerr << "vtype=" << v.get_type_string() << std::endl; + // std::cerr << "vtype=" << v.get_type_string() << std::endl; throw std::bad_cast(); } } -std::string Variant<std::string>::get() const +std::string +Variant<std::string>::get() const { const VariantType vtype = get_type(); const char* pch = nullptr; - if(vtype.equal(VARIANT_TYPE_BYTESTRING)) + if (vtype.equal(VARIANT_TYPE_BYTESTRING)) pch = g_variant_get_bytestring(gobject_); - else //g_variant_get_string() can handle strings, object paths, and signatures. + else // g_variant_get_string() can handle strings, object paths, and signatures. pch = g_variant_get_string(gobject_, nullptr); return convert_const_gchar_ptr_to_stdstring(pch); @@ -422,8 +419,7 @@ std::string Variant<std::string>::get() const typedef std::vector<Glib::ustring> type_vec_ustring; -Variant<type_vec_ustring>::Variant() -: VariantContainerBase() +Variant<type_vec_ustring>::Variant() : VariantContainerBase() { } @@ -433,7 +429,8 @@ Variant<type_vec_ustring>::Variant(GVariant* castitem, bool take_a_reference) } // static -const VariantType& Variant<type_vec_ustring>::variant_type() +const VariantType& +Variant<type_vec_ustring>::variant_type() { return VARIANT_TYPE_STRING_ARRAY; } @@ -451,35 +448,34 @@ Variant<type_vec_ustring>::create(const type_vec_ustring& data) GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj()); // Add the elements of the vector into the builder. - for(const auto& str : data) + for (const auto& str : data) { - g_variant_builder_add(builder, - element_variant_type.get_string().c_str(), str.c_str()); + g_variant_builder_add(builder, element_variant_type.get_string().c_str(), str.c_str()); } // Create the variant using the builder. auto result = - Variant<type_vec_ustring>(g_variant_new( - array_variant_type.get_string().c_str(), builder)); + Variant<type_vec_ustring>(g_variant_new(array_variant_type.get_string().c_str(), builder)); g_variant_builder_unref(builder); return result; } -Glib::ustring Variant<type_vec_ustring>::get_child(gsize index) const +Glib::ustring +Variant<type_vec_ustring>::get_child(gsize index) const { if (index >= g_variant_n_children(const_cast<GVariant*>(gobj()))) throw std::out_of_range( "Variant< std::vector<Glib::ustring> >::get_child(): Index out of bounds."); - GVariant* gvariant = - g_variant_get_child_value(const_cast<GVariant*>(gobj()), index); + GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), index); return Glib::Variant<Glib::ustring>(gvariant).get(); } -type_vec_ustring Variant<type_vec_ustring>::get() const +type_vec_ustring +Variant<type_vec_ustring>::get() const { // g_variant_get_strv() can be used only if the type is VARIANT_TYPE_STRING_ARRAY, // but the Variant can alternatively hold an array of object paths or DBus type signatures. @@ -489,8 +485,7 @@ type_vec_ustring Variant<type_vec_ustring>::get() const for (gsize i = 0; i < n_children; i++) { - GVariant* gvariant = - g_variant_get_child_value(const_cast<GVariant*>(gobj()), i); + GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), i); result.emplace_back(Glib::Variant<Glib::ustring>(gvariant).get()); } @@ -498,7 +493,8 @@ type_vec_ustring Variant<type_vec_ustring>::get() const return result; } -VariantIter Variant<type_vec_ustring>::get_iter() const +VariantIter +Variant<type_vec_ustring>::get_iter() const { return VariantContainerBase::get_iter(variant_type()); } @@ -507,8 +503,7 @@ VariantIter Variant<type_vec_ustring>::get_iter() const typedef std::vector<std::string> type_vec_string; -Variant<type_vec_string>::Variant() -: VariantContainerBase() +Variant<type_vec_string>::Variant() : VariantContainerBase() { } @@ -518,7 +513,8 @@ Variant<type_vec_string>::Variant(GVariant* castitem, bool take_a_reference) } // static -const VariantType& Variant<type_vec_string>::variant_type() +const VariantType& +Variant<type_vec_string>::variant_type() { return VARIANT_TYPE_BYTESTRING_ARRAY; } @@ -530,7 +526,7 @@ Variant<type_vec_string>::create(const type_vec_string& data) char** str_array = g_new(char*, data.size() + 1); // Add the elements of the vector into the string array. - for(type_vec_string::size_type i = 0; i < data.size(); i++) + for (type_vec_string::size_type i = 0; i < data.size(); i++) { str_array[i] = g_strdup(data[i].c_str()); } @@ -540,9 +536,7 @@ Variant<type_vec_string>::create(const type_vec_string& data) // Create the variant using g_variant_new_bytestring_array() (passing the // newly constructed array. - auto result = - Variant<type_vec_string>(g_variant_new_bytestring_array(str_array, - data.size())); + auto result = Variant<type_vec_string>(g_variant_new_bytestring_array(str_array, data.size())); g_strfreev(str_array); return result; @@ -555,7 +549,7 @@ Variant<type_vec_string>::create_from_object_paths(const type_vec_string& data) char** str_array = g_new(char*, data.size() + 1); // Add the elements of the vector into the string array. - for(type_vec_string::size_type i = 0; i < data.size(); i++) + for (type_vec_string::size_type i = 0; i < data.size(); i++) { str_array[i] = g_strdup(data[i].c_str()); } @@ -565,37 +559,37 @@ Variant<type_vec_string>::create_from_object_paths(const type_vec_string& data) // Create the variant using g_variant_new_objv() (passing the // newly constructed array. - auto result = - Variant<type_vec_string>(g_variant_new_objv(str_array, data.size())); + auto result = Variant<type_vec_string>(g_variant_new_objv(str_array, data.size())); g_strfreev(str_array); return result; } -std::string Variant<type_vec_string>::get_child(gsize index) const +std::string +Variant<type_vec_string>::get_child(gsize index) const { if (index >= g_variant_n_children(const_cast<GVariant*>(gobj()))) throw std::out_of_range( "Variant< std::vector<std::string> >::get_child(): Index out of bounds."); - GVariant* gvariant = - g_variant_get_child_value(const_cast<GVariant*>(gobj()), index); + GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), index); return Glib::Variant<std::string>(gvariant).get(); } -type_vec_string Variant<type_vec_string>::get() const +type_vec_string +Variant<type_vec_string>::get() const { // g_variant_get_bytestring_array() can be used only if the type is VARIANT_TYPE_BYTESTRING_ARRAY, - // but the Variant can alternatively hold an array of strings, object paths or DBus type signatures. + // but the Variant can alternatively hold an array of strings, object paths or DBus type + // signatures. type_vec_string result; gsize n_children = g_variant_n_children(const_cast<GVariant*>(gobj())); for (gsize i = 0; i < n_children; i++) { - GVariant* gvariant = - g_variant_get_child_value(const_cast<GVariant*>(gobj()), i); + GVariant* gvariant = g_variant_get_child_value(const_cast<GVariant*>(gobj()), i); result.emplace_back(Glib::Variant<std::string>(gvariant).get()); } @@ -603,7 +597,8 @@ type_vec_string Variant<type_vec_string>::get() const return result; } -VariantIter Variant<type_vec_string>::get_iter() const +VariantIter +Variant<type_vec_string>::get_iter() const { return VariantContainerBase::get_iter(variant_type()); } diff --git a/glib/src/variantdict.ccg b/glib/src/variantdict.ccg index ddc061dd..6e069a30 100644 --- a/glib/src/variantdict.ccg +++ b/glib/src/variantdict.ccg @@ -21,19 +21,17 @@ namespace Glib { -bool VariantDict::lookup_value_variant(const Glib::ustring& key, const VariantType& expected_type, VariantBase& value) const +bool +VariantDict::lookup_value_variant( + const Glib::ustring& key, const VariantType& expected_type, VariantBase& value) const { - GVariant* const g_value = - g_variant_dict_lookup_value(const_cast<GVariantDict*>(gobj()), - key.c_str(), - expected_type.gobj()); - if(!g_value) - return false; + GVariant* const g_value = g_variant_dict_lookup_value( + const_cast<GVariantDict*>(gobj()), key.c_str(), expected_type.gobj()); + if (!g_value) + return false; value.init(g_value); // g_value is already referenced. return true; } -} //namespace Glib - - +} // namespace Glib diff --git a/glib/src/variantiter.ccg b/glib/src/variantiter.ccg index 6c20ac9d..ca83053a 100644 --- a/glib/src/variantiter.ccg +++ b/glib/src/variantiter.ccg @@ -26,12 +26,12 @@ VariantIter::VariantIter(const VariantBase& variant) { } -bool VariantIter::next_value(VariantBase& value) +bool +VariantIter::next_value(VariantBase& value) { - GVariant* const g_value = - g_variant_iter_next_value(gobj()); + GVariant* const g_value = g_variant_iter_next_value(gobj()); - if(g_value) + if (g_value) { value.init(g_value); // g_value is already referenced. return true; @@ -40,4 +40,4 @@ bool VariantIter::next_value(VariantBase& value) return false; } -} //namespace Glib +} // namespace Glib diff --git a/glib/src/varianttype.ccg b/glib/src/varianttype.ccg index d75306b3..4f43b569 100644 --- a/glib/src/varianttype.ccg +++ b/glib/src/varianttype.ccg @@ -24,7 +24,7 @@ namespace Glib VariantType::VariantType(const GVariantType* castitem) { - if(castitem) + if (castitem) gobject_ = g_variant_type_copy(castitem); else gobject_ = nullptr; @@ -35,14 +35,15 @@ VariantType::VariantType(const std::string& type_string) { } -VariantType& VariantType::operator=(const GVariantType* castitem) +VariantType& +VariantType::operator=(const GVariantType* castitem) { - if(gobject_) + if (gobject_) { - g_variant_type_free (gobject_); + g_variant_type_free(gobject_); } - if(castitem) + if (castitem) gobject_ = g_variant_type_copy(castitem); else gobject_ = nullptr; @@ -50,13 +51,13 @@ VariantType& VariantType::operator=(const GVariantType* castitem) return *this; } - -VariantType VariantType::create_tuple(const std::vector<VariantType>& items) +VariantType +VariantType::create_tuple(const std::vector<VariantType>& items) { typedef GVariantType* var_ptr; const auto var_array = new var_ptr[items.size()]; - for(std::vector<VariantType>::size_type i = 0; i < items.size(); i++) + for (std::vector<VariantType>::size_type i = 0; i < items.size(); i++) { var_array[i] = const_cast<GVariantType*>(items[i].gobj()); } @@ -116,9 +117,9 @@ const VariantType VARIANT_TYPE_BYTESTRING(G_VARIANT_TYPE_BYTESTRING); const VariantType VARIANT_TYPE_BYTESTRING_ARRAY(G_VARIANT_TYPE_BYTESTRING_ARRAY); -std::string VariantType::get_string() const +std::string +VariantType::get_string() const { return std::string(g_variant_type_peek_string(gobj()), g_variant_type_get_string_length(gobj())); } - } |