Functions from <algorithm> reimplemented in libuavcan

This commit is contained in:
Pavel Kirienko
2014-05-04 23:13:38 +04:00
parent cf3d6e2c08
commit 7608e4ca08
19 changed files with 152 additions and 46 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ std::string CanFrame::toString(StringRepresentation mode) const
char buf[50];
char* wpos = buf;
char* const epos = buf + sizeof(buf);
std::fill(buf, buf + sizeof(buf), 0);
fill(buf, buf + sizeof(buf), 0);
if (id & FlagEFF)
{
+2 -2
View File
@@ -22,7 +22,7 @@ int BitStream::write(const uint8_t* bytes, const int bitlen)
assert(MaxBytesPerRW >= bytelen);
tmp[0] = tmp[bytelen - 1] = 0;
std::fill(tmp, tmp + bytelen, 0);
fill(tmp, tmp + bytelen, 0);
copyBitArray(bytes, 0, bitlen, tmp, bit_offset_ % 8);
const int new_bit_offset = bit_offset_ + bitlen;
@@ -69,7 +69,7 @@ int BitStream::read(uint8_t* bytes, const int bitlen)
return ResultOutOfBuffer;
}
std::fill(bytes, bytes + bitlenToBytelen(bitlen), 0);
fill(bytes, bytes + bitlenToBytelen(bitlen), 0);
copyBitArray(tmp, bit_offset_ % 8, bitlen, bytes, 0);
bit_offset_ += bitlen;
return ResultOk;
+1 -1
View File
@@ -83,7 +83,7 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
}
const int32_t ival = static_cast<int32_t>(value);
hbits |= static_cast<uint16_t>(((ival < 0) ? (-ival) : ival) & 0x3FFU);
float diff = std::abs(value - static_cast<float>(ival));
float diff = std::fabs(value - static_cast<float>(ival));
hbits += diff >= 0.5F;
return hbits;
}
+2 -2
View File
@@ -64,8 +64,8 @@ TransferSender* GenericPublisherBase::getTransferSender()
void GenericPublisherBase::setTxTimeout(MonotonicDuration tx_timeout)
{
tx_timeout = std::max(tx_timeout, getMinTxTimeout());
tx_timeout = std::min(tx_timeout, getMaxTxTimeout());
tx_timeout = max(tx_timeout, getMinTxTimeout());
tx_timeout = min(tx_timeout, getMaxTxTimeout());
tx_timeout_ = tx_timeout;
}
+1 -1
View File
@@ -128,7 +128,7 @@ MonotonicTime DeadlineScheduler::getEarliestDeadline() const
*/
MonotonicTime Scheduler::computeDispatcherSpinDeadline(MonotonicTime spin_deadline) const
{
const MonotonicTime earliest = std::min(deadline_scheduler_.getEarliestDeadline(), spin_deadline);
const MonotonicTime earliest = min(deadline_scheduler_.getEarliestDeadline(), spin_deadline);
const MonotonicTime ts = getMonotonicTime();
if (earliest > ts)
{
+7 -7
View File
@@ -40,8 +40,8 @@ int Frame::setPayload(const uint8_t* data, unsigned len)
{
return maxlen;
}
len = std::min(unsigned(maxlen), len);
(void)std::copy(data, data + len, payload_);
len = min(unsigned(maxlen), len);
(void)copy(data, data + len, payload_);
payload_len_ = len;
return len;
}
@@ -85,7 +85,7 @@ bool Frame::parse(const CanFrame& can_frame)
{
dst_node_id_ = NodeID::Broadcast;
payload_len_ = can_frame.dlc;
(void)std::copy(can_frame.data, can_frame.data + can_frame.dlc, payload_);
(void)copy(can_frame.data, can_frame.data + can_frame.dlc, payload_);
break;
}
case TransferTypeServiceResponse:
@@ -102,7 +102,7 @@ bool Frame::parse(const CanFrame& can_frame)
}
dst_node_id_ = can_frame.data[0] & 0x7F;
payload_len_ = can_frame.dlc - 1;
(void)std::copy(can_frame.data + 1, can_frame.data + can_frame.dlc, payload_);
(void)copy(can_frame.data + 1, can_frame.data + can_frame.dlc, payload_);
break;
}
default:
@@ -142,7 +142,7 @@ bool Frame::compile(CanFrame& out_can_frame) const
case TransferTypeMessageBroadcast:
{
out_can_frame.dlc = payload_len_;
(void)std::copy(payload_, payload_ + payload_len_, out_can_frame.data);
(void)copy(payload_, payload_ + payload_len_, out_can_frame.data);
break;
}
case TransferTypeServiceResponse:
@@ -152,7 +152,7 @@ bool Frame::compile(CanFrame& out_can_frame) const
assert((payload_len_ + 1) <= sizeof(out_can_frame.data));
out_can_frame.data[0] = dst_node_id_.get();
out_can_frame.dlc = payload_len_ + 1;
(void)std::copy(payload_, payload_ + payload_len_, out_can_frame.data + 1);
(void)copy(payload_, payload_ + payload_len_, out_can_frame.data + 1);
break;
}
default:
@@ -192,7 +192,7 @@ bool Frame::operator==(const Frame& rhs) const
(transfer_id_ == rhs.transfer_id_) &&
(last_frame_ == rhs.last_frame_) &&
(payload_len_ == rhs.payload_len_) &&
std::equal(payload_, payload_ + payload_len_, rhs.payload_);
equal(payload_, payload_ + payload_len_, rhs.payload_);
}
#if UAVCAN_TOSTRING
@@ -216,7 +216,7 @@ int DynamicTransferBufferManagerEntry::write(unsigned offset, const uint8_t* dat
}
const int actually_written = len - left_to_write;
max_write_pos_ = std::max(offset + actually_written, unsigned(max_write_pos_));
max_write_pos_ = max(offset + actually_written, unsigned(max_write_pos_));
return actually_written;
}
@@ -239,7 +239,7 @@ int StaticTransferBufferImpl::read(unsigned offset, uint8_t* data, unsigned len)
len = max_write_pos_ - offset;
}
assert((offset + len) <= max_write_pos_);
(void)std::copy(data_ + offset, data_ + offset + len, data);
(void)copy(data_ + offset, data_ + offset + len, data);
return len;
}
@@ -259,8 +259,8 @@ int StaticTransferBufferImpl::write(unsigned offset, const uint8_t* data, unsign
len = size_ - offset;
}
assert((offset + len) <= size_);
(void)std::copy(data, data + len, data_ + offset);
max_write_pos_ = std::max(offset + len, unsigned(max_write_pos_));
(void)copy(data, data + len, data_ + offset);
max_write_pos_ = max(offset + len, unsigned(max_write_pos_));
return len;
}
@@ -268,7 +268,7 @@ void StaticTransferBufferImpl::reset()
{
max_write_pos_ = 0;
#if UAVCAN_DEBUG
std::fill(data_, data_ + size_, 0);
fill(data_, data_ + size_, 0);
#endif
}
@@ -46,7 +46,7 @@ int SingleFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned l
len = payload_len_ - offset;
}
assert((offset + len) <= payload_len_);
(void)std::copy(payload_ + offset, payload_ + offset + len, data);
(void)copy(payload_ + offset, payload_ + offset + len, data);
return len;
}
@@ -52,8 +52,8 @@ void TransferReceiver::updateTransferTimings()
if ((!prev_prev_ts.isZero()) && (!prev_transfer_ts_.isZero()) && (prev_transfer_ts_ >= prev_prev_ts))
{
uint64_t interval_usec = (prev_transfer_ts_ - prev_prev_ts).toUSec();
interval_usec = std::min(interval_usec, uint64_t(MaxTransferIntervalUSec));
interval_usec = std::max(interval_usec, uint64_t(MinTransferIntervalUSec));
interval_usec = min(interval_usec, uint64_t(MaxTransferIntervalUSec));
interval_usec = max(interval_usec, uint64_t(MinTransferIntervalUSec));
transfer_interval_usec_ = static_cast<uint32_t>((uint64_t(transfer_interval_usec_) * 7 + interval_usec) / 8);
}
}
@@ -49,7 +49,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
buf[0] = crc.get() & 0xFF; // Transfer CRC, little endian
buf[1] = (crc.get() >> 8) & 0xFF;
(void)std::copy(payload, payload + BUFLEN - 2, buf + 2);
(void)copy(payload, payload + BUFLEN - 2, buf + 2);
const int write_res = frame.setPayload(buf, BUFLEN);
if (write_res < 2)
+1 -1
View File
@@ -45,7 +45,7 @@ std::size_t LimitedPoolAllocator::getBlockSize() const
std::size_t LimitedPoolAllocator::getNumBlocks() const
{
return std::min(max_blocks_, allocator_.getNumBlocks());
return min(max_blocks_, allocator_.getNumBlocks());
}
}