summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/child_watch/main.cc4
-rw-r--r--examples/dbus/client_bus_listnames.cc16
-rw-r--r--examples/dbus/server_without_bus.cc8
-rw-r--r--examples/dbus/session_bus_service.cc6
-rw-r--r--examples/iochannel_stream/fdstream.cc11
-rw-r--r--examples/iochannel_stream/fdstream.h10
-rw-r--r--examples/iochannel_stream/main.cc2
-rw-r--r--examples/keyfile/main.cc6
-rw-r--r--examples/markup/parser.cc16
-rw-r--r--examples/network/resolver.cc67
-rw-r--r--examples/network/socket-client.cc6
-rw-r--r--examples/network/socket-server.cc35
-rw-r--r--examples/options/main.cc17
-rw-r--r--examples/regex/main.cc2
-rw-r--r--examples/settings/settings.cc16
-rw-r--r--examples/thread/dispatcher.cc12
-rw-r--r--examples/thread/dispatcher2.cc14
-rw-r--r--examples/thread/thread.cc2
-rw-r--r--examples/thread/threadpool.cc4
19 files changed, 129 insertions, 125 deletions
diff --git a/examples/child_watch/main.cc b/examples/child_watch/main.cc
index 3bbc368b..010992e3 100644
--- a/examples/child_watch/main.cc
+++ b/examples/child_watch/main.cc
@@ -40,7 +40,7 @@ void ChildWatch::run()
{
GPid pid = fork();
- if(pid==0)
+ if(!pid)
{
sleep(5);
exit(0);
@@ -59,7 +59,7 @@ void ChildWatch::on_child_exited(GPid pid, int status)
int main()
{
- Glib::RefPtr<Glib::MainLoop> mainLoop = Glib::MainLoop::create();
+ auto mainLoop = Glib::MainLoop::create();
ChildWatch cwatch(mainLoop);
cwatch.run();
diff --git a/examples/dbus/client_bus_listnames.cc b/examples/dbus/client_bus_listnames.cc
index b46fdcf8..7b9adad6 100644
--- a/examples/dbus/client_bus_listnames.cc
+++ b/examples/dbus/client_bus_listnames.cc
@@ -34,7 +34,7 @@ bool on_main_loop_idle()
// method.
void on_dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result)
{
- Glib::RefPtr<Gio::DBus::Proxy> proxy = Gio::DBus::Proxy::create_finish(result);
+ const auto proxy = Gio::DBus::Proxy::create_finish(result);
if(!proxy)
{
@@ -48,20 +48,20 @@ void on_dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result)
{
// The proxy's call method returns a tuple of the value(s) that the method
// call produces so just get the tuple as a VariantContainerBase.
- const Glib::VariantContainerBase result = proxy->call_sync("ListNames");
+ const auto call_result = proxy->call_sync("ListNames");
// Now extract the single item in the variant container which is the
// array of strings (the names).
- Glib::Variant< std::vector<Glib::ustring> > names_variant;
- result.get_child(names_variant);
+ Glib::Variant< std::vector<Glib::ustring>> names_variant;
+ call_result.get_child(names_variant);
// Get the vector of strings.
- std::vector<Glib::ustring> names = names_variant.get();
+ auto names = names_variant.get();
std::cout << "The names on the message bus are:" << std::endl;
- for(unsigned i = 0; i < names.size(); i++)
- std::cout << names[i] << "." << std::endl;
+ for(const auto& i : names)
+ std::cout << i << "." << std::endl;
}
catch(const Glib::Error& error)
{
@@ -81,7 +81,7 @@ int main(int, char**)
loop = Glib::MainLoop::create();
// Get the user session bus connection.
- Glib::RefPtr<Gio::DBus::Connection> connection =
+ auto connection =
Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION);
// Check for an unavailable connection.
diff --git a/examples/dbus/server_without_bus.cc b/examples/dbus/server_without_bus.cc
index d50632dc..6002c149 100644
--- a/examples/dbus/server_without_bus.cc
+++ b/examples/dbus/server_without_bus.cc
@@ -68,7 +68,7 @@ static void on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connect
curr_time.assign_current_time();
const Glib::ustring time_str = curr_time.as_iso8601();
- const Glib::Variant<Glib::ustring> time_var =
+ const auto time_var =
Glib::Variant<Glib::ustring>::create(time_str);
// Create the tuple.
@@ -114,7 +114,7 @@ const Gio::DBus::InterfaceVTable interface_vtable(sigc::ptr_fun(&on_method_call)
bool on_server_new_connection(const Glib::RefPtr<Gio::DBus::Connection>& connection)
{
- Glib::RefPtr<Gio::Credentials> credentials =
+ auto credentials =
connection->get_peer_credentials();
std::string credentials_str;
@@ -166,7 +166,7 @@ int main(int, char**)
std::locale::global(std::locale(""));
Gio::init();
- try
+ try
{
introspection_data = Gio::DBus::NodeInfo::create_for_xml(introspection_xml);
}
@@ -200,7 +200,7 @@ int main(int, char**)
server->signal_new_connection().connect(sigc::ptr_fun(&on_server_new_connection));
//Keep the server running until the process is killed:
- Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create();
+ auto loop = Glib::MainLoop::create();
loop->run();
return EXIT_SUCCESS;
diff --git a/examples/dbus/session_bus_service.cc b/examples/dbus/session_bus_service.cc
index 0f0bd01d..ed320b8b 100644
--- a/examples/dbus/session_bus_service.cc
+++ b/examples/dbus/session_bus_service.cc
@@ -66,7 +66,7 @@ static void on_method_call(const Glib::RefPtr<Gio::DBus::Connection>& /* connect
curr_time.assign_current_time();
const Glib::ustring time_str = curr_time.as_iso8601();
- const Glib::Variant<Glib::ustring> time_var =
+ const auto time_var =
Glib::Variant<Glib::ustring>::create(time_str);
// Create the tuple.
@@ -156,14 +156,14 @@ int main(int, char**)
return 1;
}
- const guint id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SESSION,
+ const auto id = Gio::DBus::own_name(Gio::DBus::BUS_TYPE_SESSION,
"org.glibmm.DBusExample",
sigc::ptr_fun(&on_bus_acquired),
sigc::ptr_fun(&on_name_acquired),
sigc::ptr_fun(&on_name_lost));
//Keep the service running until the process is killed:
- Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create();
+ auto loop = Glib::MainLoop::create();
loop->run();
Gio::DBus::unown_name(id);
diff --git a/examples/iochannel_stream/fdstream.cc b/examples/iochannel_stream/fdstream.cc
index be97676f..3764546a 100644
--- a/examples/iochannel_stream/fdstream.cc
+++ b/examples/iochannel_stream/fdstream.cc
@@ -265,7 +265,8 @@ std::streamsize fdstreambuf::xsgetn(char* dest, std::streamsize num)
*putback_buffer = *(gptr() - 1);
putback_count = 2;
}
- else putback_count = 1;
+ else
+ putback_count = 1;
}
*(putback_buffer + 1) = *(dest + (chars_read - 1));
@@ -280,8 +281,8 @@ std::streamsize fdstreambuf::xsgetn(char* dest, std::streamsize num)
}
fdstream::fdstream(int fd, bool manage)
-: std::istream(0),
- std::ostream(0),
+: std::istream(nullptr),
+ std::ostream(nullptr),
buf(fd, manage)
{
std::istream::rdbuf(&buf);
@@ -289,8 +290,8 @@ fdstream::fdstream(int fd, bool manage)
}
fdstream::fdstream()
-: std::istream(0),
- std::ostream(0)
+: std::istream(nullptr),
+ std::ostream(nullptr)
{
std::istream::rdbuf(&buf);
std::ostream::rdbuf(&buf);
diff --git a/examples/iochannel_stream/fdstream.h b/examples/iochannel_stream/fdstream.h
index 8c7f45dc..80f46757 100644
--- a/examples/iochannel_stream/fdstream.h
+++ b/examples/iochannel_stream/fdstream.h
@@ -77,11 +77,11 @@ public:
fdstream_error get_error() const;
protected:
- virtual int_type underflow();
- virtual std::streamsize xsgetn(char* dest, std::streamsize num);
- virtual int sync();
- virtual int_type overflow(int_type c);
- virtual std::streamsize xsputn(const char* source, std::streamsize num);
+ int_type underflow() override;
+ std::streamsize xsgetn(char* dest, std::streamsize num) override;
+ int sync() override;
+ int_type overflow(int_type c) override;
+ std::streamsize xsputn(const char* source, std::streamsize num) override;
private:
Glib::RefPtr<Glib::IOChannel> iochannel_;
diff --git a/examples/iochannel_stream/main.cc b/examples/iochannel_stream/main.cc
index aaebbdda..e2e670f0 100644
--- a/examples/iochannel_stream/main.cc
+++ b/examples/iochannel_stream/main.cc
@@ -81,7 +81,7 @@ int main( /* int argc, char *argv[] */)
}
}
- int read_fd = open("testfifo", O_RDONLY);
+ const auto read_fd = open("testfifo", O_RDONLY);
if(read_fd == -1)
{
std::cerr << "error opening fifo" << std::endl;
diff --git a/examples/keyfile/main.cc b/examples/keyfile/main.cc
index 533bc532..33e90677 100644
--- a/examples/keyfile/main.cc
+++ b/examples/keyfile/main.cc
@@ -66,10 +66,10 @@ int main(int, char**)
// An exception will be thrown if the value is not in the file:
try
{
- const std::vector<int> values = keyfile.get_integer_list("Another Group", "Numbers");
+ const auto values = keyfile.get_integer_list("Another Group", "Numbers");
- for(std::vector<int>::const_iterator p = values.begin(); p != values.end(); ++p)
- std::cout << "Number list value: item=" << *p << std::endl;
+ for(const auto& p : values)
+ std::cout << "Number list value: item=" << p << std::endl;
}
catch(const Glib::KeyFileError& ex)
{
diff --git a/examples/markup/parser.cc b/examples/markup/parser.cc
index 30423a66..b954a671 100644
--- a/examples/markup/parser.cc
+++ b/examples/markup/parser.cc
@@ -26,7 +26,7 @@ namespace
void file_get_contents(const std::string& filename, Glib::ustring& contents)
{
- const Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_file(filename, "r");
+ const auto channel = Glib::IOChannel::create_from_file(filename, "r");
channel->read_to_end(contents);
}
@@ -54,14 +54,14 @@ public:
virtual ~DumpParser();
protected:
- virtual void on_start_element(Glib::Markup::ParseContext& context,
+ void on_start_element(Glib::Markup::ParseContext& context,
const Glib::ustring& element_name,
- const AttributeMap& attributes);
+ const AttributeMap& attributes) override;
- virtual void on_end_element(Glib::Markup::ParseContext& context,
- const Glib::ustring& element_name);
+ void on_end_element(Glib::Markup::ParseContext& context,
+ const Glib::ustring& element_name) override;
- virtual void on_text(Glib::Markup::ParseContext& context, const Glib::ustring& text);
+ void on_text(Glib::Markup::ParseContext& context, const Glib::ustring& text) override;
private:
int parse_depth_;
@@ -84,9 +84,9 @@ void DumpParser::on_start_element(Glib::Markup::ParseContext&,
indent();
std::cout << '<' << element_name;
- for(AttributeMap::const_iterator p = attributes.begin(); p != attributes.end(); ++p)
+ for(const auto& p : attributes)
{
- std::cout << ' ' << p->first << "=\"" << p->second << '"';
+ std::cout << ' ' << p.first << "=\"" << p.second << '"';
}
std::cout << ">\n";
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index 4112c146..42f36a63 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -91,14 +91,13 @@ print_resolved_name (const Glib::ustring& phys,
static void
print_resolved_addresses (const Glib::ustring& name,
- const std::list<Glib::RefPtr<Gio::InetAddress> >& addresses)
+ const std::list<Glib::RefPtr<Gio::InetAddress>>& addresses)
{
G_LOCK (response);
std::cout << Glib::ustring::compose ("Name: %1\n", name);
- for (std::list<Glib::RefPtr<Gio::InetAddress> >::const_iterator iter = addresses.begin ();
- iter != addresses.end (); ++iter)
+ for (const auto& i : addresses)
{
- std::cout << Glib::ustring::compose ("Address: %1\n", (*iter)->to_string ());
+ std::cout << Glib::ustring::compose ("Address: %1\n", i->to_string ());
}
std::cout << std::endl;
@@ -112,15 +111,14 @@ print_resolved_service (const Glib::ustring& service,
{
G_LOCK (response);
std::cout << Glib::ustring::compose ("Service: %1\n", service);
- for (std::list<Gio::SrvTarget>::const_iterator iter = targets.begin ();
- iter != targets.end (); ++iter)
+ for (const auto& i : targets)
{
std::cout <<
Glib::ustring::compose ("%1:%2 (pri %3, weight %4)\n",
- iter->get_hostname (),
- iter->get_port (),
- iter->get_priority (),
- iter->get_weight ());
+ i.get_hostname (),
+ i.get_port (),
+ i.get_priority (),
+ i.get_weight ());
}
std::cout << std::endl;
@@ -152,9 +150,8 @@ lookup_one_sync (const Glib::ustring& arg)
{
if (arg.find ('/') != std::string::npos)
{
- std::list<Gio::SrvTarget> targets;
/* service/protocol/domain */
- std::vector<Glib::ustring> parts = split_service_parts (arg);
+ const auto parts = split_service_parts (arg);
if (parts.size () != 3) {
usage ();
return;
@@ -162,7 +159,7 @@ lookup_one_sync (const Glib::ustring& arg)
try
{
- targets = resolver->lookup_service (parts[0], parts[1], parts[2],
+ const auto targets = resolver->lookup_service (parts[0], parts[1], parts[2],
cancellable);
print_resolved_service (arg, targets);
}
@@ -173,7 +170,7 @@ lookup_one_sync (const Glib::ustring& arg)
}
else if (Gio::hostname_is_ip_address (arg))
{
- Glib::RefPtr<Gio::InetAddress> addr = Gio::InetAddress::create (arg);
+ auto addr = Gio::InetAddress::create (arg);
try
{
Glib::ustring name = resolver->lookup_by_address (addr, cancellable);
@@ -209,13 +206,11 @@ lookup_thread (const Glib::ustring& arg)
static void
start_threaded_lookups (char **argv, int argc)
{
- int i;
-
- for (i = 0; i < argc; i++)
- {
- Glib::Threads::Thread::create (sigc::bind (sigc::ptr_fun (lookup_thread),
- argv[i]));
- }
+ for (auto i = 0; i < argc; i++)
+ {
+ Glib::Threads::Thread::create (sigc::bind (sigc::ptr_fun (lookup_thread),
+ argv[i]));
+ }
}
static void
@@ -265,13 +260,13 @@ lookup_service_callback (Glib::RefPtr<Gio::AsyncResult> result,
static void
start_async_lookups (char **argv, int argc)
{
- for (int i = 0; i < argc; i++)
+ for (auto i = 0; i < argc; i++)
{
Glib::ustring arg (argv[i]);
if (arg.find ('/') != std::string::npos)
{
/* service/protocol/domain */
- std::vector<Glib::ustring> parts = split_service_parts (arg);
+ auto parts = split_service_parts (arg);
if (parts.size () != 3) {
usage ();
return;
@@ -286,7 +281,7 @@ start_async_lookups (char **argv, int argc)
}
else if (Gio::hostname_is_ip_address (argv[i]))
{
- Glib::RefPtr<Gio::InetAddress> addr = Gio::InetAddress::create (argv[i]);
+ auto addr = Gio::InetAddress::create (argv[i]);
resolver->lookup_by_address_async (addr,
sigc::bind (sigc::ptr_fun
@@ -312,7 +307,7 @@ static void
print_connectable_sockaddr (Glib::RefPtr<Gio::SocketAddress> sockaddr)
{
Glib::ustring phys;
- Glib::RefPtr<Gio::InetSocketAddress> isa =
+ auto isa =
Glib::RefPtr<Gio::InetSocketAddress>::cast_dynamic (sockaddr);
if (!isa)
@@ -351,7 +346,7 @@ got_next_async (Glib::RefPtr<Gio::AsyncResult> result,
{
try
{
- Glib::RefPtr<Gio::SocketAddress> sockaddr = enumerator->next_finish (result);
+ const auto sockaddr = enumerator->next_finish (result);
if (sockaddr)
{
print_connectable_sockaddr (sockaddr);
@@ -384,7 +379,6 @@ do_connectable (const std::string& arg, gboolean synchronous)
{
std::vector<Glib::ustring> parts;
Glib::RefPtr<Gio::SocketConnectable> connectable;
- Glib::RefPtr<Gio::SocketAddressEnumerator> enumerator;
if (arg.find ('/') != std::string::npos)
{
@@ -402,27 +396,26 @@ do_connectable (const std::string& arg, gboolean synchronous)
std::string host, port_str;
guint16 port;
- std::size_t pos = arg.find (':');
+ const auto pos = arg.find (':');
if (pos != std::string::npos)
{
host = arg.substr (0, pos);
port_str = arg.substr(pos);
- port = strtoul (port_str.c_str (), NULL, 10);
+ port = strtoul (port_str.c_str (), nullptr, 10);
}
else
port = 0;
if (Gio::hostname_is_ip_address (host))
{
- Glib::RefPtr<Gio::InetAddress> addr = Gio::InetAddress::create (host);
+ const auto addr = Gio::InetAddress::create (host);
connectable = Gio::InetSocketAddress::create (addr, port);
}
else
connectable = Gio::NetworkAddress::create (arg, port);
}
- enumerator = connectable->enumerate ();
-
+ const auto enumerator = connectable->enumerate ();
if (synchronous)
do_sync_connectable (enumerator);
else
@@ -442,9 +435,9 @@ interrupted (int /*sig*/)
}
static bool
-async_cancel (Glib::IOCondition /*cond*/, Glib::RefPtr<Gio::Cancellable> cancellable)
+async_cancel (Glib::IOCondition /*cond*/, Glib::RefPtr<Gio::Cancellable> the_cancellable)
{
- cancellable->cancel ();
+ the_cancellable->cancel ();
return false;
}
#endif
@@ -452,8 +445,8 @@ async_cancel (Glib::IOCondition /*cond*/, Glib::RefPtr<Gio::Cancellable> cancell
int
main (int argc, char **argv)
{
- bool synchronous = false;
- bool use_connectable = false;
+ auto synchronous = false;
+ auto use_connectable = false;
#ifdef G_OS_UNIX
Glib::RefPtr<Glib::IOChannel> chan;
sigc::connection watch_conn;
@@ -497,7 +490,7 @@ main (int argc, char **argv)
signal (SIGINT, interrupted);
chan = Glib::IOChannel::create_from_fd (cancel_fds[0]);
- Glib::RefPtr<Glib::IOSource> source = chan->create_watch (Glib::IO_IN);
+ const auto source = chan->create_watch (Glib::IO_IN);
watch_conn = source->connect (sigc::bind (sigc::ptr_fun (async_cancel), cancellable));
#endif
diff --git a/examples/network/socket-client.cc b/examples/network/socket-client.cc
index c7df51e8..44fd94ce 100644
--- a/examples/network/socket-client.cc
+++ b/examples/network/socket-client.cc
@@ -61,7 +61,7 @@ socket_address_to_string (const Glib::RefPtr<Gio::SocketAddress>& address)
Glib::ustring str, res;
int port;
- Glib::RefPtr<Gio::InetSocketAddress> isockaddr =
+ auto isockaddr =
Glib::RefPtr<Gio::InetSocketAddress>::cast_dynamic (address);
if (!isockaddr)
return Glib::ustring ();
@@ -90,7 +90,7 @@ ensure_condition (const Glib::RefPtr<Gio::Socket>& socket,
if (use_source)
{
- Glib::RefPtr<Gio::SocketSource> source = socket->create_source(condition, cancellable);
+ auto source = socket->create_source(condition, cancellable);
source->connect(sigc::ptr_fun(&source_ready));
source->attach();
loop->run();
@@ -154,7 +154,7 @@ main (int argc,
if (argc != 2)
{
- const char* error_message = "Need to specify hostname";
+ const auto error_message = "Need to specify hostname";
std::cerr << Glib::ustring::compose ("%1: %2\n", argv[0], error_message);
return 1;
}
diff --git a/examples/network/socket-server.cc b/examples/network/socket-server.cc
index b9e1a837..897c5d14 100644
--- a/examples/network/socket-server.cc
+++ b/examples/network/socket-server.cc
@@ -68,19 +68,16 @@ public:
Glib::ustring
socket_address_to_string (const Glib::RefPtr<Gio::SocketAddress>& address)
{
- Glib::RefPtr<Gio::InetAddress> inet_address;
- Glib::ustring str, res;
- int port;
-
- Glib::RefPtr<Gio::InetSocketAddress> isockaddr =
- Glib::RefPtr<Gio::InetSocketAddress>::cast_dynamic (address);
- if (!isockaddr)
- return Glib::ustring ();
- inet_address = isockaddr->get_address ();
- str = inet_address->to_string ();
- port = isockaddr->get_port ();
- res = Glib::ustring::compose ("%1:%2", str, port);
- return res;
+ auto isockaddr =
+ Glib::RefPtr<Gio::InetSocketAddress>::cast_dynamic (address);
+ if (!isockaddr)
+ return Glib::ustring ();
+
+ auto inet_address = isockaddr->get_address ();
+ auto str = inet_address->to_string ();
+ auto the_port = isockaddr->get_port ();
+ auto res = Glib::ustring::compose ("%1:%2", str, the_port);
+ return res;
}
static bool
@@ -132,10 +129,7 @@ main (int argc,
char *argv[])
{
Glib::RefPtr<Gio::Socket> socket, new_socket, recv_socket;
- Glib::RefPtr<Gio::SocketAddress> src_address;
Glib::RefPtr<Gio::SocketAddress> address;
- Gio::SocketType socket_type;
- Gio::SocketFamily socket_family;
Glib::RefPtr<Gio::Cancellable> cancellable;
Gio::init ();
@@ -161,8 +155,8 @@ main (int argc,
loop = Glib::MainLoop::create ();
- socket_type = use_udp ? Gio::SOCKET_TYPE_DATAGRAM : Gio::SOCKET_TYPE_STREAM;
- socket_family = use_ipv6 ? Gio::SOCKET_FAMILY_IPV6 : Gio::SOCKET_FAMILY_IPV4;
+ auto socket_type = use_udp ? Gio::SOCKET_TYPE_DATAGRAM : Gio::SOCKET_TYPE_STREAM;
+ auto socket_family = use_ipv6 ? Gio::SOCKET_FAMILY_IPV6 : Gio::SOCKET_FAMILY_IPV4;
try {
socket = Gio::Socket::create (socket_family, socket_type, Gio::SOCKET_PROTOCOL_DEFAULT);
@@ -175,7 +169,7 @@ main (int argc,
if (non_blocking)
socket->set_blocking (false);
- src_address = Gio::InetSocketAddress::create (Gio::InetAddress::create_any (socket_family), port);
+ auto src_address = Gio::InetSocketAddress::create (Gio::InetAddress::create_any (socket_family), port);
try {
socket->bind (src_address, !dont_reuse_address);
} catch (const Gio::Error& error) {
@@ -234,7 +228,6 @@ main (int argc,
{
gchar buffer[4096] = { };
gssize size;
- gsize to_send;
ensure_condition (recv_socket, "receive", cancellable, Glib::IO_IN);
try {
@@ -266,7 +259,7 @@ main (int argc,
"-------------------------\n",
(int)size, buffer);
- to_send = size;
+ auto to_send = size;
while (to_send > 0)
{
diff --git a/examples/options/main.cc b/examples/options/main.cc
index 1ef290b1..fcda4a98 100644
--- a/examples/options/main.cc
+++ b/examples/options/main.cc
@@ -25,15 +25,17 @@ class ExampleOptionGroup : public Glib::OptionGroup
public:
ExampleOptionGroup();
- virtual bool on_pre_parse(Glib::OptionContext& context, Glib::OptionGroup& group);
- virtual bool on_post_parse(Glib::OptionContext& context, Glib::OptionGroup& group);
- virtual void on_error(Glib::OptionContext& context, Glib::OptionGroup& group);
+private:
+ bool on_pre_parse(Glib::OptionContext& context, Glib::OptionGroup& group) override;
+ bool on_post_parse(Glib::OptionContext& context, Glib::OptionGroup& group) override;
+ void on_error(Glib::OptionContext& context, Glib::OptionGroup& group) override;
bool on_option_arg_string(const Glib::ustring& option_name,
const Glib::ustring& value, bool has_value);
bool on_option_arg_filename(const Glib::ustring& option_name,
const std::string& value, bool has_value);
+public:
//These members should live as long as the OptionGroup to which they are added,
//and as long as the OptionContext to which that OptionGroup is added.
int m_arg_foo;
@@ -221,17 +223,18 @@ int main(int argc, char** argv)
//This one shows the results of multiple instance of the same option, such as --list=1 --list=a --list=b
std::cout << " list = ";
- for(Glib::OptionGroup::vecustrings::const_iterator iter = group.m_arg_list.begin(); iter != group.m_arg_list.end(); ++iter)
+ for(const auto& i : group.m_arg_list)
+
{
- std::cout << *iter << ", ";
+ std::cout << i << ", ";
}
std::cout << std::endl;
//This one shows the remaining arguments on the command line, which had no name= form:
std::cout << " remaining = ";
- for(Glib::OptionGroup::vecustrings::const_iterator iter = group.m_remaining_list.begin(); iter != group.m_remaining_list.end(); ++iter)
+ for(const auto& i : group.m_remaining_list)
{
- std::cout << *iter << ", ";
+ std::cout << i << ", ";
}
std::cout << std::endl;
diff --git a/examples/regex/main.cc b/examples/regex/main.cc
index cc128ab2..ed6ac567 100644
--- a/examples/regex/main.cc
+++ b/examples/regex/main.cc
@@ -24,7 +24,7 @@ int main(int, char**)
Glib::init();
/* Reusing one regex pattern: */
- Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("(a)?(b)");
+ const auto regex = Glib::Regex::create("(a)?(b)");
std::cout << "Pattern=" << regex->get_pattern()
<< ", with string=abcd, result="
<< std::boolalpha << regex->match("abcd")
diff --git a/examples/settings/settings.cc b/examples/settings/settings.cc
index b7ce0ca5..84df7a0e 100644
--- a/examples/settings/settings.cc
+++ b/examples/settings/settings.cc
@@ -50,6 +50,18 @@ static void on_key_changed(const Glib::ustring& key, const Glib::RefPtr<Gio::Set
std::cerr << "Unknown key\n";
}
+static void on_key_changed_all(const Glib::ustring& key)
+{
+ std::cout << "on_key_changed_all(" << key << ")\n";
+}
+
+static void on_key_changed_int(const Glib::ustring& key)
+{
+ std::cout << "on_key_changed_int(" << key << ")\n";
+ if (key != INT_KEY)
+ std::cerr << "Unexpected key\n";
+}
+
int main(int, char**)
{
std::locale::global(std::locale(""));
@@ -63,10 +75,12 @@ int main(int, char**)
Glib::setenv("GSETTINGS_SCHEMA_DIR", ".", true);
Glib::setenv("GSETTINGS_BACKEND", "memory", true);
- const Glib::RefPtr<Gio::Settings> settings =
+ const auto settings =
Gio::Settings::create("org.gtkmm.demo");
settings->signal_changed().connect(sigc::bind(sigc::ptr_fun(&on_key_changed), settings));
+ settings->signal_changed("").connect(sigc::ptr_fun(&on_key_changed_all));
+ settings->signal_changed(INT_KEY).connect(sigc::ptr_fun(&on_key_changed_int));
std::cout << Glib::ustring::compose("Initial value of '%1': '%2'\n",
STRING_KEY, settings->get_string(STRING_KEY));
diff --git a/examples/thread/dispatcher.cc b/examples/thread/dispatcher.cc
index 21833e7f..e58cb227 100644
--- a/examples/thread/dispatcher.cc
+++ b/examples/thread/dispatcher.cc
@@ -29,7 +29,7 @@ namespace
class ThreadProgress
{
public:
- explicit ThreadProgress(int id);
+ explicit ThreadProgress(int the_id);
virtual ~ThreadProgress();
int id() const;
@@ -78,10 +78,10 @@ public:
void operator()(T ptr) const { delete ptr; }
};
-ThreadProgress::ThreadProgress(int id)
+ThreadProgress::ThreadProgress(int the_id)
:
- thread_ (0),
- id_ (id),
+ thread_ (nullptr),
+ id_ (the_id),
progress_ (0)
{
// Connect to the cross-thread signal.
@@ -91,7 +91,7 @@ ThreadProgress::ThreadProgress(int id)
ThreadProgress::~ThreadProgress()
{
// It is an error if the thread is still running at this point.
- g_return_if_fail(thread_ == 0);
+ g_return_if_fail(thread_ == nullptr);
}
int ThreadProgress::id() const
@@ -134,7 +134,7 @@ void ThreadProgress::thread_function()
{
Glib::Rand rand;
- for (int i = 0; i < ITERATIONS; ++i)
+ for (auto i = 0; i < ITERATIONS; ++i)
{
Glib::usleep(rand.get_int_range(2000, 20000));
diff --git a/examples/thread/dispatcher2.cc b/examples/thread/dispatcher2.cc
index dd7d7de8..cd0faf26 100644
--- a/examples/thread/dispatcher2.cc
+++ b/examples/thread/dispatcher2.cc
@@ -77,7 +77,7 @@ ThreadTimer::ThreadTimer()
// Create a new Glib::Dispatcher that is attached to the default main context,
signal_increment_ (),
// This pointer will be initialized later by the 2nd thread.
- signal_finished_ptr_ (NULL)
+ signal_finished_ptr_ (nullptr)
{
// Connect the cross-thread signal.
signal_increment_.connect(sigc::mem_fun(*this, &ThreadTimer::timer_increment));
@@ -99,7 +99,7 @@ void ThreadTimer::launch()
sigc::mem_fun(*this, &ThreadTimer::thread_function));
// Wait for the 2nd thread's startup notification.
- while(signal_finished_ptr_ == NULL)
+ while(!signal_finished_ptr_)
startup_cond_.wait(startup_mutex_);
}
@@ -109,10 +109,10 @@ void ThreadTimer::signal_finished_emit()
signal_finished_ptr_->emit();
// wait for the thread to join
- if(thread_ != NULL)
+ if(thread_)
thread_->join();
- signal_finished_ptr_ = NULL;
+ signal_finished_ptr_ = nullptr;
}
void ThreadTimer::print() const
@@ -156,9 +156,9 @@ bool ThreadTimer::timeout_handler()
void ThreadTimer::thread_function()
{
// create a new Main Context
- Glib::RefPtr<Glib::MainContext> context = Glib::MainContext::create();
+ auto context = Glib::MainContext::create();
// create a new Main Loop
- Glib::RefPtr<Glib::MainLoop> mainloop = Glib::MainLoop::create(context, true);
+ auto mainloop = Glib::MainLoop::create(context, true);
// attach a timeout handler, that is called every second, to the
// newly created MainContext
@@ -189,7 +189,7 @@ ThreadTimer::type_signal_end ThreadTimer::signal_end_;
ThreadDispatcher::ThreadDispatcher()
:
- timer_ (NULL)
+ timer_ (nullptr)
{
std::cout << "Thread Dispatcher Example #2" << std::endl;
diff --git a/examples/thread/thread.cc b/examples/thread/thread.cc
index ad7cfebd..6fb546c1 100644
--- a/examples/thread/thread.cc
+++ b/examples/thread/thread.cc
@@ -36,7 +36,7 @@ void MessageQueue::producer()
{
Glib::Rand rand (1234);
- for(int i = 0; i < 200; ++i)
+ for(auto i = 0; i < 200; ++i)
{
{
Glib::Threads::Mutex::Lock lock (mutex_);
diff --git a/examples/thread/threadpool.cc b/examples/thread/threadpool.cc
index 632a77af..557997f4 100644
--- a/examples/thread/threadpool.cc
+++ b/examples/thread/threadpool.cc
@@ -15,7 +15,7 @@ void print_char(char c)
{
Glib::Rand rand;
- for(int i = 0; i < 100; ++i)
+ for(auto i = 0; i < 100; ++i)
{
{
Glib::Threads::Mutex::Lock lock (mutex);
@@ -33,7 +33,7 @@ int main(int, char**)
{
Glib::ThreadPool pool (10);
- for(char c = 'a'; c <= 'z'; ++c)
+ for(auto c = 'a'; c <= 'z'; ++c)
{
pool.push(sigc::bind<1>(sigc::ptr_fun(&print_char), c));
}