Commit cd56987e authored by Murray Cumming's avatar Murray Cumming

C++11: examples: Use nullptr.

parent 2b31a608
......@@ -40,7 +40,7 @@ void ChildWatch::run()
{
auto pid = fork();
if(pid==0)
if(!pid)
{
sleep(5);
exit(0);
......
......@@ -280,8 +280,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 +289,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);
......
......@@ -400,7 +400,7 @@ do_connectable (const std::string& arg, gboolean synchronous)
{
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;
......
......@@ -13,15 +13,15 @@ int cancel_timeout = 0;
static GOptionEntry cmd_entries[] = {
{"cancel", 'c', 0, G_OPTION_ARG_INT, &cancel_timeout,
"Cancel any op after the specified amount of seconds", NULL},
"Cancel any op after the specified amount of seconds", nullptr},
{"udp", 'u', 0, G_OPTION_ARG_NONE, &use_udp,
"Use udp instead of tcp", NULL},
"Use udp instead of tcp", nullptr},
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Be verbose", NULL},
"Be verbose", nullptr},
{"non-blocking", 'n', 0, G_OPTION_ARG_NONE, &non_blocking,
"Enable non-blocking i/o", NULL},
"Enable non-blocking i/o", nullptr},
{"use-source", 's', 0, G_OPTION_ARG_NONE, &use_source,
"Use GSource to wait for non-blocking i/o", NULL},
"Use GSource to wait for non-blocking i/o", nullptr},
{0, 0, 0, G_OPTION_ARG_NONE, 0, 0, 0}
};
......@@ -63,8 +63,8 @@ ensure_condition (const Glib::RefPtr<Gio::Socket>& socket,
cancellable->gobj ());
g_source_set_callback (source,
(GSourceFunc) source_ready,
NULL, NULL);
g_source_attach (source, NULL);
nullptr, nullptr);
g_source_attach (source, nullptr);
loop->run ();
}
else
......@@ -96,14 +96,14 @@ main (int argc,
Glib::RefPtr<Gio::SocketAddress> src_address;
Glib::RefPtr<Gio::SocketAddress> address;
Gio::SocketType socket_type;
GError *error = NULL;
GError *error = nullptr;
Glib::RefPtr<Gio::Cancellable> cancellable;
Glib::RefPtr<Gio::SocketConnectable> connectable;
Gio::init ();
auto context = g_option_context_new (" <hostname>[:port] - Test GSocket client stuff");
g_option_context_add_main_entries (context, cmd_entries, NULL);
g_option_context_add_main_entries (context, cmd_entries, nullptr);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
std::cerr << Glib::ustring::compose ("%1: %2\n", argv[0], error->message);
......
......@@ -14,19 +14,19 @@ int cancel_timeout = 0;
static GOptionEntry cmd_entries[] = {
{"port", 'p', 0, G_OPTION_ARG_INT, &port,
"Local port to bind to", NULL},
"Local port to bind to", nullptr},
{"cancel", 'c', 0, G_OPTION_ARG_INT, &cancel_timeout,
"Cancel any op after the specified amount of seconds", NULL},
"Cancel any op after the specified amount of seconds", nullptr},
{"udp", 'u', 0, G_OPTION_ARG_NONE, &use_udp,
"Use udp instead of tcp", NULL},
"Use udp instead of tcp", nullptr},
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Be verbose", NULL},
"Be verbose", nullptr},
{"no-reuse", 0, 0, G_OPTION_ARG_NONE, &dont_reuse_address,
"Don't SOADDRREUSE", NULL},
"Don't SOADDRREUSE", nullptr},
{"non-blocking", 'n', 0, G_OPTION_ARG_NONE, &non_blocking,
"Enable non-blocking i/o", NULL},
"Enable non-blocking i/o", nullptr},
{"use-source", 's', 0, G_OPTION_ARG_NONE, &use_source,
"Use GSource to wait for non-blocking i/o", NULL},
"Use GSource to wait for non-blocking i/o", nullptr},
{0, 0, 0, G_OPTION_ARG_NONE, 0, 0, 0}
};
......@@ -72,8 +72,8 @@ ensure_condition (const Glib::RefPtr<Gio::Socket>& socket,
cancellable->gobj ());
g_source_set_callback (source,
(GSourceFunc) source_ready,
NULL, NULL);
g_source_attach (source, NULL);
nullptr, nullptr);
g_source_attach (source, nullptr);
loop->run ();
}
else
......@@ -105,12 +105,12 @@ main (int argc,
Glib::RefPtr<Gio::SocketAddress> address;
Gio::SocketType socket_type;
Glib::RefPtr<Gio::Cancellable> cancellable;
GError *error = NULL;
GError *error = nullptr;
Gio::init ();
auto context = g_option_context_new (" - Test GSocket server stuff");
g_option_context_add_main_entries (context, cmd_entries, NULL);
g_option_context_add_main_entries (context, cmd_entries, nullptr);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
std::cerr << Glib::ustring::compose ("%1: %1\n", argv[0], error->message);
......
......@@ -80,7 +80,7 @@ public:
ThreadProgress::ThreadProgress(int id)
:
thread_ (0),
thread_ (nullptr),
id_ (id),
progress_ (0)
{
......@@ -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
......
......@@ -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
......@@ -190,7 +190,7 @@ ThreadTimer::type_signal_end ThreadTimer::signal_end_;
ThreadDispatcher::ThreadDispatcher()
:
timer_ (NULL)
timer_ (nullptr)
{
std::cout << "Thread Dispatcher Example #2" << std::endl;
......
......@@ -30,7 +30,7 @@
* GLIBMM_INITIALIZE_STRUCT(Var, Type) is provided. It even avoids creating
* a temporary if the compiler is GCC.
*/
#if ((__GNUC__ >= 3) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) && !defined(__STRICT_ANSI__)
#if ((__GNUC__ >= 3) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#define GLIBMM_INITIALIZE_STRUCT(Var, Type) __builtin_memset(&(Var), 0, sizeof(Type))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment