From ec9006381b9ed0848eb12704a2beb9e74aea74bf Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 21 Mar 2015 14:08:37 +0300 Subject: [PATCH] Removing all dirty 'using namespace std' that were used as C++ library compatibility work-around --- libuavcan/include/uavcan/build_config.hpp | 1 - libuavcan/include/uavcan/data_type.hpp | 2 +- libuavcan/include/uavcan/driver/can.hpp | 2 +- libuavcan/include/uavcan/driver/system_clock.hpp | 2 +- libuavcan/include/uavcan/dynamic_memory.hpp | 3 +-- libuavcan/include/uavcan/error.hpp | 2 +- .../uavcan/helpers/component_status_manager.hpp | 2 +- libuavcan/include/uavcan/marshal/array.hpp | 4 ++-- libuavcan/include/uavcan/marshal/bit_stream.hpp | 2 +- libuavcan/include/uavcan/marshal/float_spec.hpp | 2 +- libuavcan/include/uavcan/marshal/integer_spec.hpp | 2 +- libuavcan/include/uavcan/marshal/scalar_codec.hpp | 2 +- .../uavcan/node/global_data_type_registry.hpp | 2 +- libuavcan/include/uavcan/node/timer.hpp | 2 +- libuavcan/include/uavcan/{stdint.hpp => std.hpp} | 12 ++++++++---- libuavcan/include/uavcan/time.hpp | 4 +--- .../uavcan/transport/abstract_transfer_buffer.hpp | 2 +- libuavcan/include/uavcan/transport/can_io.hpp | 2 +- libuavcan/include/uavcan/transport/crc.hpp | 2 +- libuavcan/include/uavcan/transport/dispatcher.hpp | 2 +- .../uavcan/transport/outgoing_transfer_registry.hpp | 2 +- libuavcan/include/uavcan/transport/perf_counter.hpp | 2 +- libuavcan/include/uavcan/transport/transfer.hpp | 2 +- .../include/uavcan/transport/transfer_buffer.hpp | 2 +- .../include/uavcan/transport/transfer_listener.hpp | 2 +- libuavcan/src/driver/uc_can.cpp | 2 -- libuavcan/src/transport/uc_frame.cpp | 1 - .../src/transport/uc_outgoing_transfer_registry.cpp | 1 - libuavcan/src/transport/uc_transfer_buffer.cpp | 1 - libuavcan/src/uc_data_type.cpp | 1 - 30 files changed, 32 insertions(+), 38 deletions(-) rename libuavcan/include/uavcan/{stdint.hpp => std.hpp} (76%) diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index fac52be812..eab0e386fe 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -123,7 +123,6 @@ #if UAVCAN_TOSTRING # include -# include #endif /** diff --git a/libuavcan/include/uavcan/data_type.hpp b/libuavcan/include/uavcan/data_type.hpp index 8e47751647..323b6f8a18 100644 --- a/libuavcan/include/uavcan/data_type.hpp +++ b/libuavcan/include/uavcan/data_type.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include diff --git a/libuavcan/include/uavcan/driver/can.hpp b/libuavcan/include/uavcan/driver/can.hpp index ad77abfcf7..3fca51c9ed 100644 --- a/libuavcan/include/uavcan/driver/can.hpp +++ b/libuavcan/include/uavcan/driver/can.hpp @@ -7,7 +7,7 @@ #define UAVCAN_DRIVER_CAN_HPP_INCLUDED #include -#include +#include #include #include diff --git a/libuavcan/include/uavcan/driver/system_clock.hpp b/libuavcan/include/uavcan/driver/system_clock.hpp index 22055b457e..1939e5d553 100644 --- a/libuavcan/include/uavcan/driver/system_clock.hpp +++ b/libuavcan/include/uavcan/driver/system_clock.hpp @@ -6,7 +6,7 @@ #ifndef UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED #define UAVCAN_DRIVER_SYSTEM_CLOCK_HPP_INCLUDED -#include +#include #include #include diff --git a/libuavcan/include/uavcan/dynamic_memory.hpp b/libuavcan/include/uavcan/dynamic_memory.hpp index 7c0ffb2038..813d5480be 100644 --- a/libuavcan/include/uavcan/dynamic_memory.hpp +++ b/libuavcan/include/uavcan/dynamic_memory.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -157,7 +157,6 @@ bool PoolManager::addPool(IPoolAllocator* pool) } } // We need to keep the pools in order, so that smallest blocks go first - using namespace std; // for qsort() qsort(pools_, MaxPools, sizeof(IPoolAllocator*), &PoolManager::qsortComparePoolAllocators); return retval; } diff --git a/libuavcan/include/uavcan/error.hpp b/libuavcan/include/uavcan/error.hpp index 1cbeafcc22..bce8b4ed00 100644 --- a/libuavcan/include/uavcan/error.hpp +++ b/libuavcan/include/uavcan/error.hpp @@ -6,7 +6,7 @@ #define UAVCAN_ERROR_HPP_INCLUDED #include -#include +#include namespace uavcan { diff --git a/libuavcan/include/uavcan/helpers/component_status_manager.hpp b/libuavcan/include/uavcan/helpers/component_status_manager.hpp index 78d700b758..f33da0a583 100644 --- a/libuavcan/include/uavcan/helpers/component_status_manager.hpp +++ b/libuavcan/include/uavcan/helpers/component_status_manager.hpp @@ -6,7 +6,7 @@ #define UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED #include -#include +#include #include namespace uavcan diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index 2248a161bd..67d5ee41d0 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef UAVCAN_CPP_VERSION # error UAVCAN_CPP_VERSION @@ -729,10 +730,9 @@ public: const SizeType max_size = SizeType(capacity() - size()); // We have one extra byte for the null terminator, hence +1 - using namespace std; // For snprintf() const int ret = snprintf(reinterpret_cast(ptr), SizeType(max_size + 1U), format, value); - for (int i = 0; i < ::uavcan::min(ret, int(max_size)); i++) + for (int i = 0; i < min(ret, int(max_size)); i++) { Base::grow(); } diff --git a/libuavcan/include/uavcan/marshal/bit_stream.hpp b/libuavcan/include/uavcan/marshal/bit_stream.hpp index b7504112ec..1ac9fe400c 100644 --- a/libuavcan/include/uavcan/marshal/bit_stream.hpp +++ b/libuavcan/include/uavcan/marshal/bit_stream.hpp @@ -6,7 +6,7 @@ #define UAVCAN_MARSHAL_BIT_STREAM_HPP_INCLUDED #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/marshal/float_spec.hpp b/libuavcan/include/uavcan/marshal/float_spec.hpp index ab0063056a..2ee680f184 100644 --- a/libuavcan/include/uavcan/marshal/float_spec.hpp +++ b/libuavcan/include/uavcan/marshal/float_spec.hpp @@ -6,7 +6,7 @@ #define UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/marshal/integer_spec.hpp b/libuavcan/include/uavcan/marshal/integer_spec.hpp index 2a74218581..b7424310db 100644 --- a/libuavcan/include/uavcan/marshal/integer_spec.hpp +++ b/libuavcan/include/uavcan/marshal/integer_spec.hpp @@ -5,7 +5,7 @@ #ifndef UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED #define UAVCAN_MARSHAL_INTEGER_SPEC_HPP_INCLUDED -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/marshal/scalar_codec.hpp b/libuavcan/include/uavcan/marshal/scalar_codec.hpp index b46c1b16bb..2690f6e1d6 100644 --- a/libuavcan/include/uavcan/marshal/scalar_codec.hpp +++ b/libuavcan/include/uavcan/marshal/scalar_codec.hpp @@ -6,7 +6,7 @@ #define UAVCAN_MARSHAL_SCALAR_CODEC_HPP_INCLUDED #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 7e27d92886..d7f837c199 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/node/timer.hpp b/libuavcan/include/uavcan/node/timer.hpp index 1521489f99..13fc4f5ed9 100644 --- a/libuavcan/include/uavcan/node/timer.hpp +++ b/libuavcan/include/uavcan/node/timer.hpp @@ -5,7 +5,7 @@ #ifndef UAVCAN_NODE_TIMER_HPP_INCLUDED #define UAVCAN_NODE_TIMER_HPP_INCLUDED -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/stdint.hpp b/libuavcan/include/uavcan/std.hpp similarity index 76% rename from libuavcan/include/uavcan/stdint.hpp rename to libuavcan/include/uavcan/std.hpp index 4fc668a2a7..9e1cbc9a84 100644 --- a/libuavcan/include/uavcan/stdint.hpp +++ b/libuavcan/include/uavcan/std.hpp @@ -6,6 +6,7 @@ #define UAVCAN_STDINT_HPP_INCLUDED #include +#include #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) # error UAVCAN_CPP_VERSION @@ -14,10 +15,13 @@ #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 # include +# include namespace uavcan { +using std::snprintf; // Can be used to replace standard snprintf() with a user-provided one. + typedef std::uint8_t uint8_t; typedef std::uint16_t uint16_t; typedef std::uint32_t uint32_t; @@ -32,14 +36,14 @@ typedef std::int64_t int64_t; #else -/* - * C++03 doesn't define standard integer types, so we pull it from the C library as a workaround. - */ -# include +# include // Standard integer types from C library +# include // snprintf() from the C library namespace uavcan { +using ::snprintf; + typedef ::uint8_t uint8_t; typedef ::uint16_t uint16_t; typedef ::uint32_t uint32_t; diff --git a/libuavcan/include/uavcan/time.hpp b/libuavcan/include/uavcan/time.hpp index 094016fb35..39528b045b 100644 --- a/libuavcan/include/uavcan/time.hpp +++ b/libuavcan/include/uavcan/time.hpp @@ -6,7 +6,7 @@ #define UAVCAN_TIME_HPP_INCLUDED #include -#include +#include #include #include #include @@ -223,7 +223,6 @@ const unsigned TimeBase::StringBufSize; template void DurationBase::toString(char buf[StringBufSize]) const { - using namespace std; // For snprintf() char* ptr = buf; if (isNegative()) { @@ -238,7 +237,6 @@ void DurationBase::toString(char buf[StringBufSize]) const template void TimeBase::toString(char buf[StringBufSize]) const { - using namespace std; // For snprintf() (void)snprintf(buf, StringBufSize, "%llu.%06lu", static_cast(toUSec() / 1000000UL), static_cast(toUSec() % 1000000UL)); diff --git a/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp b/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp index 7cc703c4c2..e4a276d1ce 100644 --- a/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp +++ b/libuavcan/include/uavcan/transport/abstract_transfer_buffer.hpp @@ -6,7 +6,7 @@ #define UAVCAN_TRANSPORT_ABSTRACT_TRANSFER_BUFFER_HPP_INCLUDED #include -#include +#include namespace uavcan { diff --git a/libuavcan/include/uavcan/transport/can_io.hpp b/libuavcan/include/uavcan/transport/can_io.hpp index cee418569d..867407d056 100644 --- a/libuavcan/include/uavcan/transport/can_io.hpp +++ b/libuavcan/include/uavcan/transport/can_io.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/transport/crc.hpp b/libuavcan/include/uavcan/transport/crc.hpp index abee099522..aae2c4d964 100644 --- a/libuavcan/include/uavcan/transport/crc.hpp +++ b/libuavcan/include/uavcan/transport/crc.hpp @@ -6,7 +6,7 @@ #define UAVCAN_TRANSPORT_CRC_HPP_INCLUDED #include -#include +#include #include namespace uavcan diff --git a/libuavcan/include/uavcan/transport/dispatcher.hpp b/libuavcan/include/uavcan/transport/dispatcher.hpp index a34789bf36..ac12bbd2b7 100644 --- a/libuavcan/include/uavcan/transport/dispatcher.hpp +++ b/libuavcan/include/uavcan/transport/dispatcher.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp b/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp index 9d91ac1955..114cecee22 100644 --- a/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp +++ b/libuavcan/include/uavcan/transport/outgoing_transfer_registry.hpp @@ -6,7 +6,7 @@ #define UAVCAN_TRANSPORT_OUTGOING_TRANSFER_REGISTRY_HPP_INCLUDED #include -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/transport/perf_counter.hpp b/libuavcan/include/uavcan/transport/perf_counter.hpp index 009dfeec81..58861897bd 100644 --- a/libuavcan/include/uavcan/transport/perf_counter.hpp +++ b/libuavcan/include/uavcan/transport/perf_counter.hpp @@ -5,7 +5,7 @@ #ifndef UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED #define UAVCAN_TRANSPORT_PERF_COUNTER_HPP_INCLUDED -#include +#include #include namespace uavcan diff --git a/libuavcan/include/uavcan/transport/transfer.hpp b/libuavcan/include/uavcan/transport/transfer.hpp index d5c3f8268f..50255fe37c 100644 --- a/libuavcan/include/uavcan/transport/transfer.hpp +++ b/libuavcan/include/uavcan/transport/transfer.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace uavcan { diff --git a/libuavcan/include/uavcan/transport/transfer_buffer.hpp b/libuavcan/include/uavcan/transport/transfer_buffer.hpp index d29bcce9ed..0911f106e4 100644 --- a/libuavcan/include/uavcan/transport/transfer_buffer.hpp +++ b/libuavcan/include/uavcan/transport/transfer_buffer.hpp @@ -5,7 +5,7 @@ #ifndef UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED #define UAVCAN_TRANSPORT_TRANSFER_BUFFER_HPP_INCLUDED -#include +#include #include #include #include diff --git a/libuavcan/include/uavcan/transport/transfer_listener.hpp b/libuavcan/include/uavcan/transport/transfer_listener.hpp index a8210821ce..e71d50f1e3 100644 --- a/libuavcan/include/uavcan/transport/transfer_listener.hpp +++ b/libuavcan/include/uavcan/transport/transfer_listener.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/libuavcan/src/driver/uc_can.cpp b/libuavcan/src/driver/uc_can.cpp index ed5723eecd..739740343b 100644 --- a/libuavcan/src/driver/uc_can.cpp +++ b/libuavcan/src/driver/uc_can.cpp @@ -59,8 +59,6 @@ bool CanFrame::priorityHigherThan(const CanFrame& rhs) const #if UAVCAN_TOSTRING std::string CanFrame::toString(StringRepresentation mode) const { - using namespace std; // For snprintf() - UAVCAN_ASSERT(mode == StrTight || mode == StrAligned); static const unsigned AsciiColumnOffset = 36U; diff --git a/libuavcan/src/transport/uc_frame.cpp b/libuavcan/src/transport/uc_frame.cpp index 510b60e6e3..3a3938a01b 100644 --- a/libuavcan/src/transport/uc_frame.cpp +++ b/libuavcan/src/transport/uc_frame.cpp @@ -198,7 +198,6 @@ bool Frame::operator==(const Frame& rhs) const #if UAVCAN_TOSTRING std::string Frame::toString() const { - using namespace std; // For snprintf() /* * Frame ID fields, according to UAVCAN specs: * - Data Type ID diff --git a/libuavcan/src/transport/uc_outgoing_transfer_registry.cpp b/libuavcan/src/transport/uc_outgoing_transfer_registry.cpp index 8054b7f9e0..66cb4a5ad8 100644 --- a/libuavcan/src/transport/uc_outgoing_transfer_registry.cpp +++ b/libuavcan/src/transport/uc_outgoing_transfer_registry.cpp @@ -12,7 +12,6 @@ namespace uavcan #if UAVCAN_TOSTRING std::string OutgoingTransferRegistryKey::toString() const { - using namespace std; char buf[40]; (void)snprintf(buf, sizeof(buf), "dtid=%u tt=%u dnid=%u", int(data_type_id_.get()), int(transfer_type_), int(destination_node_id_.get())); diff --git a/libuavcan/src/transport/uc_transfer_buffer.cpp b/libuavcan/src/transport/uc_transfer_buffer.cpp index 4a56b75632..fb3774c7d9 100644 --- a/libuavcan/src/transport/uc_transfer_buffer.cpp +++ b/libuavcan/src/transport/uc_transfer_buffer.cpp @@ -14,7 +14,6 @@ namespace uavcan #if UAVCAN_TOSTRING std::string TransferBufferManagerKey::toString() const { - using namespace std; // For snprintf() char buf[24]; (void)snprintf(buf, sizeof(buf), "nid=%i tt=%i", int(node_id_.get()), int(transfer_type_)); return std::string(buf); diff --git a/libuavcan/src/uc_data_type.cpp b/libuavcan/src/uc_data_type.cpp index bfe12e8b2c..184d6dc610 100644 --- a/libuavcan/src/uc_data_type.cpp +++ b/libuavcan/src/uc_data_type.cpp @@ -111,7 +111,6 @@ std::string DataTypeDescriptor::toString() const } } - using namespace std; // For snprintf() char buf[128]; (void)snprintf(buf, sizeof(buf), "%s:%u%c:%016llx", full_name_, static_cast(id_.get()), kindch,