1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-28 21:19:10 +00:00

Revert "Use "using namespace std;" and remove all std::'s"

This reverts commit 41e80b9833.
This commit is contained in:
Nikolas Garofil 2010-02-24 20:10:26 +01:00
parent 41e80b9833
commit e7ed9a5060
23 changed files with 145 additions and 149 deletions

View File

@ -259,7 +259,7 @@ int compare(const char *expr)
int check_if_match(struct text_object *obj)
{
unique_ptr<char []> expression(new char[max_user_text]);
std::unique_ptr<char []> expression(new char[max_user_text]);
int val;
int result = 1;

View File

@ -75,7 +75,7 @@ void update_audacious(void)
}
}
lock_guard<mutex> lock(info.audacious.p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(info.audacious.p_timed_thread->mutex());
memcpy(&info.audacious.items, audacious_items, sizeof(audacious_items));
}
@ -88,8 +88,8 @@ int create_audacious_thread(void)
{
if (!info.audacious.p_timed_thread) {
info.audacious.p_timed_thread =
timed_thread::create(bind(audacious_thread_func,
placeholders::_1), info.music_player_interval *
timed_thread::create(std::bind(audacious_thread_func,
std::placeholders::_1), info.music_player_interval *
1000000);
}
@ -237,7 +237,7 @@ void audacious_thread_func(thread_handle &handle)
} while (0);
{
/* Deliver the refreshed items array to audacious_items. */
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
memcpy(&audacious_items, items, sizeof(items));
}

View File

@ -119,7 +119,7 @@ void ccurl_fetch_data(thread_handle &handle, ccurl_location_ptr &curloc)
long http_status_code;
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) {
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
curloc->process_function(curloc->result, chunk.memory);
} else {
NORM_ERR("curl: no data from server");
@ -142,8 +142,8 @@ void ccurl_init_thread(ccurl_location_ptr curloc, int interval)
#ifdef DEBUG
assert(curloc->result);
#endif /* DEBUG */
curloc->p_timed_thread = timed_thread::create(bind(ccurl_thread,
placeholders::_1, curloc), interval * 1000000);
curloc->p_timed_thread = timed_thread::create(std::bind(ccurl_thread,
std::placeholders::_1, curloc), interval * 1000000);
if (!curloc->p_timed_thread) {
NORM_ERR("curl thread: error creating timed thread");
@ -194,8 +194,8 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
if (!curloc->p_timed_thread) {
curloc->result = (char*)malloc(max_user_text);
memset(curloc->result, 0, max_user_text);
curloc->process_function = bind(ccurl_parse_data,
placeholders::_1, placeholders::_2);
curloc->process_function = std::bind(ccurl_parse_data,
std::placeholders::_1, std::placeholders::_2);
ccurl_init_thread(curloc, interval);
if (!curloc->p_timed_thread) {
NORM_ERR("error setting up curl thread");
@ -203,7 +203,7 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
}
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
strncpy(p, curloc->result, p_max_size);
}

View File

@ -43,11 +43,11 @@ struct ccurl_location_t {
/* function to call when data is ready to be processed, the first argument
* will be the result pointer, and the second argument is an internal
* buffer that shouldn't be mangled */
function<void(char *, const char *)> process_function;
std::function<void(char *, const char *)> process_function;
};
typedef shared_ptr<ccurl_location_t> ccurl_location_ptr;
typedef list<ccurl_location_ptr> ccurl_location_list;
typedef std::shared_ptr<ccurl_location_t> ccurl_location_ptr;
typedef std::list<ccurl_location_ptr> ccurl_location_list;
/* find an existing location for the uri specified */
ccurl_location_ptr ccurl_find_location(ccurl_location_list &locations, char *uri);

View File

@ -96,7 +96,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_c
void print_combine(struct text_object *obj, char *p, int p_max_size)
{
struct combine_data *cd = (struct combine_data *)obj->data.opaque;
vector<vector<char>> buf;
std::vector<std::vector<char>> buf;
buf.resize(2);
buf[0].resize(max_user_text);
buf[1].resize(max_user_text);

View File

@ -638,7 +638,7 @@ void print_evaluate(struct text_object *obj, char *p, int p_max_size)
int if_empty_iftest(struct text_object *obj)
{
vector<char> buf(max_user_text);
std::vector<char> buf(max_user_text);
int result = 1;
generate_text_internal(&(buf[0]), max_user_text, *obj->sub);
@ -769,7 +769,7 @@ void print_battery_short(struct text_object *obj, char *p, int p_max_size)
void print_blink(struct text_object *obj, char *p, int p_max_size)
{
//blinking like this can look a bit ugly if the chars in the font don't have the same width
vector<char> buf(max_user_text);
std::vector<char> buf(max_user_text);
static int visible = 1;
static int last_len = 0;
int i;
@ -788,7 +788,7 @@ void print_blink(struct text_object *obj, char *p, int p_max_size)
void print_include(struct text_object *obj, char *p, int p_max_size)
{
vector<char> buf(max_user_text);
std::vector<char> buf(max_user_text);
if (!obj->sub)
return;
@ -799,7 +799,7 @@ void print_include(struct text_object *obj, char *p, int p_max_size)
void print_to_bytes(struct text_object *obj, char *p, int p_max_size)
{
vector<char> buf(max_user_text);
std::vector<char> buf(max_user_text);
long long bytes;
char unit[16]; // 16 because we can also have long names (like mega-bytes)

View File

@ -31,8 +31,6 @@
#ifndef _conky_h_
#define _conky_h_
using namespace std;
#include <config.h> /* defines */
#include "common.h" /* at least for struct dns_data */
#include <sys/utsname.h> /* struct uname_s */

View File

@ -58,7 +58,7 @@ void clear_diskio_stats(void)
struct diskio_stat *prepare_diskio_stat(const char *s)
{
struct stat sb;
vector<char> stat_name(text_buffer_size), device_name(text_buffer_size);
std::vector<char> stat_name(text_buffer_size), device_name(text_buffer_size);
struct diskio_stat *cur = &stats;
if (!s)

View File

@ -162,7 +162,7 @@ static inline void read_exec(const char *data, char *buf, const int size)
length = fread(buf, 1, size, fp);
pclose(fp);
buf[min(length, size-1)] = '\0';
buf[std::min(length, size-1)] = '\0';
if (length > 0 && buf[length - 1] == '\n') {
buf[length - 1] = '\0';
}
@ -203,7 +203,7 @@ static void threaded_exec(thread_handle &handle, struct text_object *obj)
}
{
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
free_and_zero(ed->buffer);
ed->buffer = buff;
}
@ -323,13 +323,13 @@ void print_execi(struct text_object *obj, char *p, int p_max_size)
* note that we don't register this thread with the
* timed_thread list, because we destroy it manually
*/
ed->p_timed_thread = timed_thread::create(bind(threaded_exec, placeholders::_1, obj), ed->interval * 1000000, false);
ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false);
if (!ed->p_timed_thread) {
NORM_ERR("Error creating texeci timed thread");
}
fillbuffer = false;
} else {
lock_guard<mutex> lock(ed->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(ed->p_timed_thread->mutex());
}
} else {
if (time_to_update(ed)) {

View File

@ -26,7 +26,6 @@
#include <config.h>
#endif
#include "conky.h"
#include "libtcp-portmon.h"
#include <cstdio>
@ -76,8 +75,8 @@ namespace {
bool operator==(const tcp_connection_t &a, const tcp_connection_t &b)
{
return a.local_port == b.local_port && a.remote_port == b.remote_port &&
! memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) &&
! memcmp(&a.remote_addr.s6_addr, &b.remote_addr, sizeof(a.remote_addr));
! std::memcmp(&a.local_addr, &b.local_addr, sizeof(a.local_addr)) &&
! std::memcmp(&a.remote_addr.s6_addr, &b.remote_addr, sizeof(a.remote_addr));
}
/* ------------------------------------------------------------------------
@ -86,10 +85,10 @@ namespace {
* The second parameter provides the mechanism for removing connections if
* they are not seen again in subsequent update cycles.
* ------------------------------------------------------------------------ */
typedef unordered_map<tcp_connection_t, int, tcp_connection_hash> connection_hash_t;
typedef std::unordered_map<tcp_connection_t, int, tcp_connection_hash> connection_hash_t;
/* start and end of port monitor range. Set start=end to monitor a single port */
typedef pair<in_port_t, in_port_t> port_range_t;
typedef std::pair<in_port_t, in_port_t> port_range_t;
/* hash function for port ranges */
struct port_range_hash {
@ -99,7 +98,7 @@ namespace {
}
};
typedef unordered_map<port_range_t,
typedef std::unordered_map<port_range_t,
tcp_port_monitor_t,
port_range_hash> monitor_hash_t;
@ -113,7 +112,7 @@ struct _tcp_port_monitor_t {
connection_hash_t hash;
/* array of connection pointers for O(1) peeking
* these point into the hash table*/
vector<const tcp_connection_t *> p_peek;
std::vector<const tcp_connection_t *> p_peek;
_tcp_port_monitor_t(int max_connections)
: hash(), p_peek(max_connections, static_cast<const tcp_connection_t *>(NULL))
@ -133,7 +132,7 @@ struct _tcp_port_monitor_t {
* done in O(1) time instead of O(n) time for each peek. */
/* zero out the peek array */
fill(p_peek.begin(), p_peek.end(), static_cast<tcp_connection_t *>(NULL));
std::fill(p_peek.begin(), p_peek.end(), static_cast<tcp_connection_t *>(NULL));
size_t i = 0;
for (connection_hash_t::iterator j = hash.begin(); j != hash.end(); ++j, ++i ) {
@ -276,7 +275,7 @@ namespace {
/* checks whether the address is a IPv4-mapped IPv6 address */
bool is_4on6(const struct in6_addr *addr)
{
return ! memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6));
return ! std::memcmp(&addr->s6_addr, prefix_4on6, sizeof(prefix_4on6));
}
@ -286,15 +285,15 @@ namespace {
union sockaddr_in46 sa;
socklen_t slen;
memset(&sa, 0, sizeof(sa));
std::memset(&sa, 0, sizeof(sa));
if(is_4on6(addr)) {
sa.sa4.sin_family = AF_INET;
memcpy(&sa.sa4.sin_addr.s_addr, &addr->s6_addr[12], 4);
std::memcpy(&sa.sa4.sin_addr.s_addr, &addr->s6_addr[12], 4);
slen = sizeof(sa.sa4);
} else {
sa.sa6.sin6_family = AF_INET6;
memcpy(&sa.sa6.sin6_addr, addr, sizeof(struct in6_addr));
std::memcpy(&sa.sa6.sin6_addr, addr, sizeof(struct in6_addr));
slen = sizeof(sa.sa6);
}
@ -306,48 +305,48 @@ namespace {
{
size_t i;
if(strlen(p_buffer) < 32) { //IPv4 address
if(std::strlen(p_buffer) < 32) { //IPv4 address
i = sizeof(prefix_4on6);
memcpy(addr->s6_addr, prefix_4on6, i);
std::memcpy(addr->s6_addr, prefix_4on6, i);
} else {
i = 0;
}
for( ; i < sizeof(addr->s6_addr); i+=4, p_buffer+=8) {
sscanf(p_buffer, "%8x", (unsigned *)&addr->s6_addr[i]);
std::sscanf(p_buffer, "%8x", (unsigned *)&addr->s6_addr[i]);
}
}
/* adds connections from file to the collection */
void process_file(tcp_port_monitor_collection_t *p_collection, const char *file)
{
FILE *fp;
std::FILE *fp;
char buf[256];
char local_addr[40];
char remote_addr[40];
tcp_connection_t conn;
unsigned long inode, uid, state;
if ((fp = fopen(file, "r")) == NULL) {
if ((fp = std::fopen(file, "r")) == NULL) {
return;
}
/* ignore field name line */
if(fgets(buf, 255, fp) == NULL) {
fclose(fp);
if(std::fgets(buf, 255, fp) == NULL) {
std::fclose(fp);
return;
}
/* read all tcp connections */
while (fgets(buf, sizeof(buf), fp) != NULL) {
while (std::fgets(buf, sizeof(buf), fp) != NULL) {
if (sscanf(buf,
if (std::sscanf(buf,
"%*d: %39[0-9a-fA-F]:%hx %39[0-9a-fA-F]:%hx %lx %*x:%*x %*x:%*x %*x %lu %*d %lu",
local_addr, &conn.local_port,
remote_addr, &conn.remote_port,
(unsigned long *) &state, (unsigned long *) &uid,
(unsigned long *) &inode) != 7) {
fprintf(stderr, "%s: bad file format\n", file);
std::fprintf(stderr, "%s: bad file format\n", file);
}
/** TCP_ESTABLISHED equals 1, but is not (always??) included **/
//if ((inode == 0) || (state != TCP_ESTABLISHED)) {
@ -363,7 +362,7 @@ namespace {
&show_connection_to_tcp_port_monitor, (void *) &conn);
}
fclose(fp);
std::fclose(fp);
}
}
@ -390,8 +389,8 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
return -1;
}
memset(p_buffer, 0, buffer_size);
memset(&sa, 0, sizeof(sa));
std::memset(p_buffer, 0, buffer_size);
std::memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
@ -405,7 +404,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
case COUNT:
snprintf(p_buffer, buffer_size, "%u", unsigned(p_monitor->hash.size()));
std::snprintf(p_buffer, buffer_size, "%u", unsigned(p_monitor->hash.size()));
break;
case REMOTEIP:
@ -420,7 +419,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
case REMOTEPORT:
snprintf(p_buffer, buffer_size, "%d",
std::snprintf(p_buffer, buffer_size, "%d",
p_monitor->p_peek[connection_index]->remote_port);
break;
@ -442,7 +441,7 @@ int peek_tcp_port_monitor(const tcp_port_monitor_t *p_monitor, int item,
case LOCALPORT:
snprintf(p_buffer, buffer_size, "%d",
std::snprintf(p_buffer, buffer_size, "%d",
p_monitor->p_peek[connection_index]->local_port);
break;

View File

@ -616,7 +616,7 @@ int imap_check_status(char *recvbuf, struct mail_s *mail, thread_handle &handle)
NORM_ERR("Error parsing IMAP response: %s", recvbuf);
return -1;
} else {
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
&mail->unseen);
}
@ -635,12 +635,12 @@ void imap_unseen_command(struct mail_s *mail, unsigned long old_unseen, unsigned
}
static void ensure_mail_thread(struct mail_s *mail,
const function<void(thread_handle &, struct mail_s *mail)> &func, const char *text)
const std::function<void(thread_handle &, struct mail_s *mail)> &func, const char *text)
{
if (mail->p_timed_thread)
return;
mail->p_timed_thread = timed_thread::create(bind(func, placeholders::_1, mail), mail->interval * 1000000);
mail->p_timed_thread = timed_thread::create(std::bind(func, std::placeholders::_1, mail), mail->interval * 1000000);
if (!mail->p_timed_thread) {
NORM_ERR("Error creating %s timed thread", text);
}
@ -832,7 +832,7 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail)
buf--;
}
if (sscanf(buf, "* %lu EXISTS\r\n", &messages) == 1) {
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
if (mail->messages != messages) {
force_check = 1;
mail->messages = messages;
@ -947,10 +947,10 @@ void print_imap_unseen(struct text_object *obj, char *p, int p_max_size)
if (!mail)
return;
ensure_mail_thread(mail, bind(imap_thread, placeholders::_1, placeholders::_2), "imap");
ensure_mail_thread(mail, std::bind(imap_thread, std::placeholders::_1, std::placeholders::_2), "imap");
if (mail && mail->p_timed_thread) {
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
snprintf(p, p_max_size, "%lu", mail->unseen);
}
}
@ -962,10 +962,10 @@ void print_imap_messages(struct text_object *obj, char *p, int p_max_size)
if (!mail)
return;
ensure_mail_thread(mail, bind(imap_thread, placeholders::_1, placeholders::_2), "imap");
ensure_mail_thread(mail, std::bind(imap_thread, std::placeholders::_1, std::placeholders::_2), "imap");
if (mail && mail->p_timed_thread) {
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
snprintf(p, p_max_size, "%lu", mail->messages);
}
}
@ -1115,7 +1115,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail)
fail++;
break;
} else {
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
}
@ -1154,10 +1154,10 @@ void print_pop3_unseen(struct text_object *obj, char *p, int p_max_size)
if (!mail)
return;
ensure_mail_thread(mail, bind(pop3_thread, placeholders::_1, placeholders::_2), "pop3");
ensure_mail_thread(mail, std::bind(pop3_thread, std::placeholders::_1, std::placeholders::_2), "pop3");
if (mail && mail->p_timed_thread) {
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
snprintf(p, p_max_size, "%lu", mail->unseen);
}
}
@ -1169,10 +1169,10 @@ void print_pop3_used(struct text_object *obj, char *p, int p_max_size)
if (!mail)
return;
ensure_mail_thread(mail, bind(pop3_thread, placeholders::_1, placeholders::_2), "pop3");
ensure_mail_thread(mail, std::bind(pop3_thread, std::placeholders::_1, std::placeholders::_2), "pop3");
if (mail && mail->p_timed_thread) {
lock_guard<mutex> lock(mail->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(mail->p_timed_thread->mutex());
snprintf(p, p_max_size, "%.1f",
mail->used / 1024.0 / 1024.0);
}

View File

@ -65,7 +65,7 @@ static void mbox_scan(char *args, char *output, size_t max_len)
{
int i, u, flag;
int force_rescan = 0;
unique_ptr<char []> buf_(new char[text_buffer_size]);
std::unique_ptr<char []> buf_(new char[text_buffer_size]);
char *buf = buf_.get();
struct stat statbuf;
struct ring_list *curr = 0, *prev = 0, *startlist = 0;

View File

@ -116,7 +116,7 @@ static void update_moc_loop(thread_handle &handle)
{
while (1) {
{
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
update_infos();
}
if (handle.test(0)) {
@ -131,7 +131,7 @@ static int run_moc_thread(double interval)
if (moc_thread)
return 0;
moc_thread = timed_thread::create(bind(update_moc_loop, placeholders::_1), interval);
moc_thread = timed_thread::create(std::bind(update_moc_loop, std::placeholders::_1), interval);
if (!moc_thread) {
NORM_ERR("Failed to create MOC timed thread");
return 1;

View File

@ -136,7 +136,7 @@ void update_mpd(void)
return;
interval = info.music_player_interval * 1000000;
thread = timed_thread::create(bind(update_mpd_thread, placeholders::_1), interval);
thread = timed_thread::create(std::bind(update_mpd_thread, std::placeholders::_1), interval);
if (!thread) {
NORM_ERR("Failed to create MPD timed thread");
return;
@ -171,7 +171,7 @@ bool mpd_process(thread_handle &handle)
}
{
lock_guard<mutex> lock(handle.mutex());
std::lock_guard<std::mutex> lock(handle.mutex());
if (conn->error || conn == NULL) {
NORM_ERR("MPD error: %s\n", conn->errorStr);

View File

@ -60,7 +60,7 @@ char* readfile(char* filename, int* total_read, char showerror) {
void pid_readlink(char *file, char *p, int p_max_size)
{
unique_ptr<char []> buf(new char[p_max_size]);
std::unique_ptr<char []> buf(new char[p_max_size]);
memset(buf.get(), 0, p_max_size);
if(readlink(file, buf.get(), p_max_size) >= 0) {
@ -106,7 +106,7 @@ int inlist(struct ll_string* front, char* string) {
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
unique_ptr<char []> buf(new char[max_user_text]);
std::unique_ptr<char []> buf(new char[max_user_text]);
generate_text_internal(buf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/root", buf.get());
@ -118,7 +118,7 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
char* buf;
int i, bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -141,10 +141,10 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
{
unique_ptr<char []> buf(new char[p_max_size]);
std::unique_ptr<char []> buf(new char[p_max_size]);
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf.get());
@ -162,7 +162,7 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
int i, total_read;
pid_t pid;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
char *buf, *var=strdup(obj->data.s);;
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -195,7 +195,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
int bytes_read, total_read;
int i = 0;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf.get());
@ -217,7 +217,7 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf.get());
@ -229,7 +229,7 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
int bytes_read;
long int nice_value;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -249,11 +249,11 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
DIR* dir;
struct dirent *entry;
unique_ptr<char []> buf(new char[p_max_size]);
std::unique_ptr<char []> buf(new char[p_max_size]);
int length, totallength = 0;
struct ll_string* files_front = NULL;
struct ll_string* files_back = NULL;
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -288,7 +288,7 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -315,7 +315,7 @@ void print_pid_priority(struct text_object *obj, char *p, int p_max_size) {
int bytes_read;
long int priority;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -338,7 +338,7 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -364,7 +364,7 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
char *begin, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -384,7 +384,7 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -393,7 +393,7 @@ void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
}
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
char pathbuf[64];
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -404,7 +404,7 @@ void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -414,7 +414,7 @@ void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
unsigned int i;
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
/* FIXME */
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -472,7 +472,7 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -499,7 +499,7 @@ void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) {
struct dirent *entry;
int totallength = 0;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf.get());
@ -524,7 +524,7 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p, int p_max_size)
int bytes_read;
unsigned long int umtime;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -546,7 +546,7 @@ void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) {
int bytes_read;
unsigned long int kmtime;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -568,7 +568,7 @@ void print_pid_time(struct text_object *obj, char *p, int p_max_size) {
int bytes_read;
unsigned long int umtime, kmtime;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -591,7 +591,7 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -618,7 +618,7 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -646,7 +646,7 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -675,7 +675,7 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -706,7 +706,7 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -733,7 +733,7 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -761,7 +761,7 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -790,7 +790,7 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -819,7 +819,7 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size, con
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
@ -890,7 +890,7 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
@ -917,7 +917,7 @@ void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL;
int bytes_read;
char pathbuf[64];
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());

View File

@ -61,15 +61,15 @@ static void rss_process_info(char *p, int p_max_size, char *uri, char *action, i
if (!curloc->p_timed_thread) {
curloc->result = (char*)malloc(sizeof(PRSS));
memset(curloc->result, 0, sizeof(PRSS));
curloc->process_function = bind(prss_parse_data,
placeholders::_1, placeholders::_2);
curloc->process_function = std::bind(prss_parse_data,
std::placeholders::_1, std::placeholders::_2);
ccurl_init_thread(curloc, interval);
if (!curloc->p_timed_thread) {
NORM_ERR("error setting up RSS thread");
}
}
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
data = (PRSS*)curloc->result;
if (data == NULL || data->item_count < 1) {

View File

@ -109,7 +109,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size)
struct scroll_data *sd = (struct scroll_data *)obj->data.opaque;
unsigned int j, colorchanges = 0, frontcolorchanges = 0, visibcolorchanges = 0, strend;
char *pwithcolors;
vector<char> buf(max_user_text);
std::vector<char> buf(max_user_text);
if (!sd)
return;

View File

@ -358,7 +358,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
graph->graph[0] = f; /* add new data */
if(graph->scaled) {
graph->scale = *max_element(graph->graph + 0, graph->graph + graph->graph_width);
graph->scale = *std::max_element(graph->graph + 0, graph->graph + graph->graph_width);
if(graph->scale < 1e-47) {
/* avoid NaN's when the graph is all-zero (e.g. before the first update)
* there is nothing magical about 1e-47 here */

View File

@ -41,25 +41,25 @@
/* Abstraction layer for timed threads */
typedef struct chrono::system_clock clk;
typedef struct std::chrono::system_clock clk;
/* private */
struct _timed_thread {
auto_ptr<thread> the_thread; /* thread itself */
mutex cs_mutex; /* critical section mutex */
mutex runnable_mutex; /* runnable section mutex */
condition_variable runnable_cond; /* signalled to stop the thread */
std::auto_ptr<std::thread> thread; /* thread itself */
std::mutex cs_mutex; /* critical section mutex */
std::mutex runnable_mutex; /* runnable section mutex */
std::condition_variable runnable_cond; /* signalled to stop the thread */
clk::time_point last_time; /* last time interval */
int pipefd[2];
int die;
_timed_thread() : die(0) {}
};
typedef list<timed_thread_ptr> thread_list_t;
typedef std::list<timed_thread_ptr> thread_list_t;
thread_list_t thread_list;
/* create a timed thread (object creation only) */
timed_thread::timed_thread(const function<void(thread_handle &)> start_routine, unsigned
timed_thread::timed_thread(const std::function<void(thread_handle &)> start_routine, unsigned
int interval_usecs) :
p_timed_thread(new _timed_thread), p_thread_handle(this),
interval_usecs(interval_usecs), running(false)
@ -71,7 +71,7 @@ timed_thread::timed_thread(const function<void(thread_handle &)> start_routine,
/* create thread pipe (used to tell threads to die) */
if (pipe(p_timed_thread->pipefd)) {
throw runtime_error("couldn't create pipe");
throw std::runtime_error("couldn't create pipe");
}
/* set initialize to current time */
@ -81,11 +81,11 @@ timed_thread::timed_thread(const function<void(thread_handle &)> start_routine,
p_timed_thread->interval_time.tv_sec,
p_timed_thread->interval_time.tv_nsec); */
p_timed_thread->the_thread = auto_ptr<thread>(
new thread(start_routine, p_thread_handle)
p_timed_thread->thread = std::auto_ptr<std::thread>(
new std::thread(start_routine, p_thread_handle)
);
DBGP("created thread %ld", (long)p_timed_thread->the_thread.get());
DBGP("created thread %ld", (long)p_timed_thread->thread.get());
running = true;
}
@ -93,13 +93,13 @@ timed_thread::timed_thread(const function<void(thread_handle &)> start_routine,
/* destroy a timed thread. */
void timed_thread::destroy(bool deregister_this)
{
DBGP("destroying thread %ld", (long)p_timed_thread->the_thread.get());
DBGP("destroying thread %ld", (long)p_timed_thread->thread.get());
#ifdef DEBUG
assert(running && p_timed_thread->the_thread->joinable());
assert(running && p_timed_thread->thread->joinable());
#endif /* DEBUG */
{
/* signal thread to stop */
lock_guard<std::mutex> l(p_timed_thread->runnable_mutex);
std::lock_guard<std::mutex> l(p_timed_thread->runnable_mutex);
p_timed_thread->runnable_cond.notify_one();
p_timed_thread->die = 1;
}
@ -108,7 +108,7 @@ void timed_thread::destroy(bool deregister_this)
perror("write()");
/* join the terminating thread */
p_timed_thread->the_thread->join();
p_timed_thread->thread->join();
close(p_timed_thread->pipefd[0]);
close(p_timed_thread->pipefd[1]);
@ -137,7 +137,7 @@ void timed_thread::unlock(void)
p_timed_thread->cs_mutex.unlock();
}
mutex &timed_thread::mutex()
std::mutex &timed_thread::mutex()
{
#ifdef DEBUG
assert(running);
@ -176,7 +176,7 @@ int timed_thread::test(int override_wait_time)
/* acquire runnable_cond mutex */
{
unique_lock<std::mutex> lock(p_timed_thread->runnable_mutex);
std::unique_lock<std::mutex> lock(p_timed_thread->runnable_mutex);
if (p_timed_thread->die) {
/* if we were kindly asked to die, then die */
@ -250,7 +250,7 @@ int thread_handle::test(int override_wait_time) {
return thread->test(override_wait_time);
}
mutex &thread_handle::mutex()
std::mutex &thread_handle::mutex()
{
#ifdef DEBUG
assert(thread->running);

View File

@ -25,7 +25,6 @@
#ifndef _TIMED_THREAD_H_
#define _TIMED_THREAD_H_
#include "conky.h"
#include <stdlib.h>
#include <functional>
#include <memory>
@ -37,7 +36,7 @@ const unsigned int MINIMUM_INTERVAL_USECS = 10000;
typedef struct _timed_thread _timed_thread;
class timed_thread;
typedef shared_ptr<timed_thread> timed_thread_ptr;
typedef std::shared_ptr<timed_thread> timed_thread_ptr;
namespace std { class mutex; }
@ -60,9 +59,9 @@ class thread_handle {
class timed_thread {
public:
/* create a timed thread (object creation only) */
static timed_thread_ptr create(const function<void(thread_handle &)> start_routine, const unsigned int
static timed_thread_ptr create(const std::function<void(thread_handle &)> start_routine, const unsigned int
interval_usecs, bool register_for_destruction = true) {
timed_thread_ptr ptr(new timed_thread(cref(start_routine), interval_usecs));
timed_thread_ptr ptr(new timed_thread(std::cref(start_routine), interval_usecs));
if (register_for_destruction) {
register_(ptr);
}
@ -93,7 +92,7 @@ class timed_thread {
private:
/* create a timed thread (object creation only) */
timed_thread(const function<void(thread_handle &)> start_routine, unsigned int
timed_thread(const std::function<void(thread_handle &)> start_routine, unsigned int
interval_usecs);
/* waits required interval (unless override_wait_time is non-zero) for
@ -111,7 +110,7 @@ class timed_thread {
static void deregister(const timed_thread *timed_thread);
/* private internal data */
auto_ptr<_timed_thread> p_timed_thread;
std::auto_ptr<_timed_thread> p_timed_thread;
thread_handle p_thread_handle;
unsigned int interval_usecs;
bool running;

View File

@ -317,7 +317,7 @@ static void do_format_time(struct text_object *obj, char *p, unsigned int p_max_
void print_format_time(struct text_object *obj, char *p, int p_max_size)
{
unique_ptr<char []> buf(new char[max_user_text]);
std::unique_ptr<char []> buf(new char[max_user_text]);
generate_text_internal(buf.get(), max_user_text, *obj->sub);
obj->data.s = buf.get();

View File

@ -39,7 +39,7 @@ void print_uid_name(struct text_object *obj, char *p, int p_max_size) {
struct passwd *pw;
uid_t uid;
char* firstinvalid;
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
@ -61,7 +61,7 @@ void print_gid_name(struct text_object *obj, char *p, int p_max_size) {
struct group *grp;
gid_t gid;
char* firstinvalid;
unique_ptr<char []> objbuf(new char[max_user_text]);
std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf.get(), max_user_text, *obj->sub);

View File

@ -717,15 +717,15 @@ static void weather_forecast_process_info(char *p, int p_max_size, char *uri, un
if (!curloc->p_timed_thread) {
curloc->result = (char*)malloc(sizeof(PWEATHER_FORECAST));
memset(curloc->result, 0, sizeof(PWEATHER_FORECAST));
curloc->process_function = bind(parse_weather_forecast,
placeholders::_1, placeholders::_2);
curloc->process_function = std::bind(parse_weather_forecast,
std::placeholders::_1, std::placeholders::_2);
ccurl_init_thread(curloc, interval);
if (!curloc->p_timed_thread) {
NORM_ERR("error setting up weather_forecast thread");
}
}
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
data = (PWEATHER_FORECAST*)curloc->result;
if (strcmp(data_type, "hi") == EQUAL) {
temp_print(p, p_max_size, data->hi[day], TEMP_CELSIUS);
@ -768,15 +768,15 @@ static void weather_process_info(char *p, int p_max_size, char *uri, char *data_
if (!curloc->p_timed_thread) {
curloc->result = (char*)malloc(sizeof(PWEATHER));
memset(curloc->result, 0, sizeof(PWEATHER));
curloc->process_function = bind(parse_weather,
placeholders::_1, placeholders::_2);
curloc->process_function = std::bind(parse_weather,
std::placeholders::_1, std::placeholders::_2);
ccurl_init_thread(curloc, interval);
if (!curloc->p_timed_thread) {
NORM_ERR("error setting up weather thread");
}
}
lock_guard<mutex> lock(curloc->p_timed_thread->mutex());
std::lock_guard<std::mutex> lock(curloc->p_timed_thread->mutex());
data = (PWEATHER*)curloc->result;
if (strcmp(data_type, "last_update") == EQUAL) {
strncpy(p, data->lastupd, p_max_size);
@ -832,8 +832,8 @@ static void weather_process_info(char *p, int p_max_size, char *uri, char *data_
#ifdef BUILD_WEATHER_XOAP
/* xoap suffix for weather from weather.com */
namespace {
string xoap_cc;
string xoap_df;
std::string xoap_cc;
std::string xoap_df;
}
#endif /* BUILD_WEATHER_XOAP */
@ -888,11 +888,11 @@ void load_xoap_keys(void)
fp = fopen(xoap, "r");
if (fp != NULL) {
if (fscanf(fp, "%10s %16s", par, key) == 2) {
xoap_cc = string("?cc=*&link=xoap&prod=xoap&par=")
xoap_cc = std::string("?cc=*&link=xoap&prod=xoap&par=")
+ par + "&key=" + key + "&unit=m";
/* TODO: Use FORECAST_DAYS instead of 5 */
xoap_df = string("?dayf=5&link=xoap&prod=xoap&par=")
xoap_df = std::string("?dayf=5&link=xoap&prod=xoap&par=")
+ par + "&key=" + key + "&unit=m";
}
fclose(fp);