From b8f87a5b55387ad7b698742dcfcc1bc93538a053 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 5 Feb 2010 21:19:56 +0000 Subject: Convert C-style casts to C++ style casts. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2432 a436a847-0d15-0410-975c-d299462d15a1 --- raul/Atom.hpp | 6 +++--- raul/AtomicInt.hpp | 11 +++++------ raul/AtomicPtr.hpp | 8 ++++---- raul/List.hpp | 2 +- raul/SRSWQueue.hpp | 2 +- raul/TimeStamp.hpp | 4 ++-- src/Configuration.cpp | 2 +- src/SMFReader.cpp | 4 ++-- src/SMFWriter.cpp | 2 +- src/Thread.cpp | 2 +- test/midi_ringbuffer_test.cpp | 9 ++++++--- test/queue_test.cpp | 2 +- test/smf_test.cpp | 2 +- test/table_test.cpp | 4 ++-- test/time_test.cpp | 4 ++-- 15 files changed, 33 insertions(+), 31 deletions(-) diff --git a/raul/Atom.hpp b/raul/Atom.hpp index 04ff4cb..46e93ad 100644 --- a/raul/Atom.hpp +++ b/raul/Atom.hpp @@ -203,7 +203,7 @@ private: , _buf(malloc(_type_length + _size)) { memcpy(_buf, type, _type_length); - memcpy((char*)_buf + _type_length, data, size); + memcpy(static_cast(_buf) + _type_length, data, size); } BlobValue(const BlobValue& copy) @@ -217,8 +217,8 @@ private: ~BlobValue() { free(_buf); } - inline const char* type() const { return (const char*)_buf; } - inline const void* data() const { return (const char*)_buf + _type_length; } + inline const char* type() const { return static_cast(_buf); } + inline const void* data() const { return static_cast(_buf) + _type_length; } inline size_t size() const { return _size; } private: size_t _type_length; ///< Length of type string (first part of buffer, inc. \0) diff --git a/raul/AtomicInt.hpp b/raul/AtomicInt.hpp index e7fe5ac..c2aa3c1 100644 --- a/raul/AtomicInt.hpp +++ b/raul/AtomicInt.hpp @@ -25,24 +25,23 @@ namespace Raul { class AtomicInt { public: - inline AtomicInt(int val) - { g_atomic_int_set(static_cast(&_val), (gint)val); } + { g_atomic_int_set(static_cast(&_val), val); } inline AtomicInt(const AtomicInt& copy) - { g_atomic_int_set(static_cast(&_val), (gint)copy.get()); } + { g_atomic_int_set(static_cast(&_val), copy.get()); } inline int get() const { return g_atomic_int_get(static_cast(&_val)); } inline void operator=(int val) - { g_atomic_int_set(static_cast(&_val), (gint)val); } + { g_atomic_int_set(static_cast(&_val), val); } inline void operator+=(int val) - { g_atomic_int_add(static_cast(&_val), (gint)val); } + { g_atomic_int_add(static_cast(&_val), val); } inline void operator-=(int val) - { g_atomic_int_add(static_cast(&_val), (gint)-val); } + { g_atomic_int_add(static_cast(&_val), -val); } inline bool operator==(int val) const { return get() == val; } diff --git a/raul/AtomicPtr.hpp b/raul/AtomicPtr.hpp index 089b54c..0e086c2 100644 --- a/raul/AtomicPtr.hpp +++ b/raul/AtomicPtr.hpp @@ -26,15 +26,15 @@ namespace Raul { template class AtomicPtr { public: - inline AtomicPtr() - { g_atomic_pointer_set((volatile gpointer*)&_val, NULL); } + { g_atomic_pointer_set(static_cast(&_val), NULL); } inline AtomicPtr(const AtomicPtr& copy) - { g_atomic_pointer_set((volatile gpointer*)(&_val), (gpointer)copy.get()); } + { g_atomic_pointer_set(static_cast(&_val), + static_cast(copy.get())); } inline T* get() const - { return (T*)g_atomic_pointer_get((volatile gpointer*)(&_val)); } + { return static_cast(g_atomic_pointer_get(static_cast(&_val))); } inline void operator=(T* val) { g_atomic_pointer_set(&_val, static_cast(val)); } diff --git a/raul/List.hpp b/raul/List.hpp index 764d684..3a55136 100644 --- a/raul/List.hpp +++ b/raul/List.hpp @@ -90,7 +90,7 @@ public: void clear(); /// Valid only in the write thread - unsigned size() const { return (unsigned)_size.get(); } + unsigned size() const { return static_cast(_size.get()); } /// Valid for any thread bool empty() { return (_head.get() == NULL); } diff --git a/raul/SRSWQueue.hpp b/raul/SRSWQueue.hpp index a36efd9..c40738a 100644 --- a/raul/SRSWQueue.hpp +++ b/raul/SRSWQueue.hpp @@ -72,7 +72,7 @@ SRSWQueue::SRSWQueue(size_t size) : _front(0) , _back(0) , _size(size+1) - , _objects((T*)calloc(_size, sizeof(T))) + , _objects(static_cast(calloc(_size, sizeof(T)))) { assert(size > 1); } diff --git a/raul/TimeStamp.hpp b/raul/TimeStamp.hpp index 7e6529b..6b1bf19 100644 --- a/raul/TimeStamp.hpp +++ b/raul/TimeStamp.hpp @@ -85,7 +85,7 @@ public: {} inline TimeStamp(TimeUnit unit, double dec) - : _ticks((uint32_t)floor(dec)) + : _ticks(static_cast(floor(dec))) , _subticks((dec - floor(dec)) * unit.ppt()) , _unit(unit) { @@ -98,7 +98,7 @@ public: inline uint32_t subticks() const { return _subticks; } inline double to_double() const { - return _ticks + (_subticks / (double)_unit.ppt()); + return _ticks + (_subticks / static_cast(_unit.ppt())); } inline bool is_zero() const { diff --git a/src/Configuration.cpp b/src/Configuration.cpp index bc6cfbd..d8cbfbe 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -76,7 +76,7 @@ Configuration::set_value_from_string(Configuration::Option& option, const std::s char* endptr = NULL; switch (option.type) { case Atom::INT: - intval = (int)strtol(value.c_str(), &endptr, 10); + intval = static_cast(strtol(value.c_str(), &endptr, 10)); if (endptr && *endptr == '\0') { option.value = intval; } else { diff --git a/src/SMFReader.cpp b/src/SMFReader.cpp index 55d4020..e7dbcf0 100644 --- a/src/SMFReader.cpp +++ b/src/SMFReader.cpp @@ -244,7 +244,7 @@ SMFReader::read_event(size_t buf_len, last_size = *ev_size; } - buf[0] = (uint8_t)status; + buf[0] = static_cast(status); if (status == 0xFF) { *ev_size = 0; @@ -253,7 +253,7 @@ SMFReader::read_event(size_t buf_len, uint8_t type = fgetc(_fd); const uint32_t size = read_var_len(_fd); - if ((uint8_t)type == 0x2F) { + if (type == 0x2F) { return -1; // we hit the logical EOF anyway... } else { fseek(_fd, size, SEEK_CUR); diff --git a/src/SMFWriter.cpp b/src/SMFWriter.cpp index e07555b..6bf5444 100644 --- a/src/SMFWriter.cpp +++ b/src/SMFWriter.cpp @@ -124,7 +124,7 @@ SMFWriter::write_event(Raul::TimeStamp time, } assert(delta_ticks <= VAR_LEN_MAX); - stamp_size = write_var_len((uint32_t)delta_ticks); + stamp_size = write_var_len(static_cast(delta_ticks)); fwrite(ev, 1, ev_size, _fd); _last_ev_time = time; diff --git a/src/Thread.cpp b/src/Thread.cpp index 00bc616..9c1a920 100644 --- a/src/Thread.cpp +++ b/src/Thread.cpp @@ -74,7 +74,7 @@ Thread::get() void* Thread::_static_run(void* thread) { - Thread* me = (Thread*)thread; + Thread* me = static_cast(thread); pthread_setspecific(me->_thread_key, thread); me->_run(); me->_pthread_exists = false; diff --git a/test/midi_ringbuffer_test.cpp b/test/midi_ringbuffer_test.cpp index f75cfd5..a5173b4 100644 --- a/test/midi_ringbuffer_test.cpp +++ b/test/midi_ringbuffer_test.cpp @@ -17,15 +17,18 @@ read_write_test(EventRingBuffer& rb, unsigned offset) unsigned char write_buf[5]; unsigned char read_buf[5]; - snprintf((char*)write_buf, 5, "%d", offset); - size = strlen((char*)write_buf); + snprintf(static_cast(write_buf), 5, "%d", offset); + size = strlen(static_cast(write_buf)); const size_t written = rb.write(t, size, write_buf); assert(written == size); rb.read(&t, &size, read_buf); - return (strncmp((const char*)write_buf, (const char*)read_buf, size)); + return strncmp( + static_cast(write_buf), + static_cast(read_buf), + size); } diff --git a/test/queue_test.cpp b/test/queue_test.cpp index 49ba6f2..329ec60 100644 --- a/test/queue_test.cpp +++ b/test/queue_test.cpp @@ -135,7 +135,7 @@ main() vector writers(NUM_WRITERS, new WriteThread()); for (unsigned i=0; i < NUM_WRITERS; ++i) { - writers[i]->set_name(string("Writer ") + (char)('0' + i)); + writers[i]->set_name(string("Writer ") + static_cast('0' + i)); writers[i]->start(); } diff --git a/test/smf_test.cpp b/test/smf_test.cpp index 9ff27f5..e848f15 100644 --- a/test/smf_test.cpp +++ b/test/smf_test.cpp @@ -55,7 +55,7 @@ main(int argc, char** argv) cout << ":\t"; cout.flags(ios::hex); for (uint32_t i=0; i < ev_size; ++i) { - cout << "0x" << (int)buf[i] << " "; + cout << "0x" << static_cast(buf[i]) << " "; } cout.flags(ios::dec); cout << endl; diff --git a/test/table_test.cpp b/test/table_test.cpp index 882873a..41d13c2 100644 --- a/test/table_test.cpp +++ b/test/table_test.cpp @@ -186,7 +186,7 @@ main(int argc, char** argv) t.insert(make_pair(val, ((val + 3) * 17))); } - for (int i=0; i < (int)table_size; ++i) { + for (size_t i=0; i < table_size; ++i) { int val = rand()%100; Table::iterator iter = t.find(val); assert(iter == t.end() || iter->second == (val + 3) * 17); @@ -281,7 +281,7 @@ benchmark(size_t n) gettimeofday(&t1, NULL); for (size_t i=0; i < n; ++i) - useless_accumulator += (int)(*s.find(values[i]))[0]; + useless_accumulator += static_cast((*s.find(values[i]))[0]); gettimeofday(&t2, NULL); diff --git a/test/time_test.cpp b/test/time_test.cpp index a7479be..b48e3f1 100644 --- a/test/time_test.cpp +++ b/test/time_test.cpp @@ -14,8 +14,8 @@ main() double in_double = 2.5; - TimeStamp t(unit, (uint32_t)in_double, - (uint32_t)((in_double - (uint32_t)in_double) * unit.ppt())); + TimeStamp t(unit, static_cast(in_double), + static_cast((in_double - static_cast(in_double)) * unit.ppt())); cout << "\tSeconds: "; cout << ts.beats_to_seconds(t); -- cgit v1.2.1