Added config macro UAVCAN_TOSTRING

This commit is contained in:
Pavel Kirienko
2014-04-10 13:32:35 +04:00
parent 29138214dc
commit d0b541e22d
20 changed files with 62 additions and 21 deletions
+4 -3
View File
@@ -6,7 +6,6 @@
#include <cassert>
#include <cstring>
#include <string>
#include <algorithm>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>
@@ -155,10 +154,12 @@ public:
bool match(DataTypeKind kind, const char* name) const;
bool match(DataTypeKind kind, DataTypeID id) const;
std::string toString() const;
bool operator!=(const DataTypeDescriptor& rhs) const { return !operator==(rhs); }
bool operator==(const DataTypeDescriptor& rhs) const;
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
}
+2 -1
View File
@@ -7,7 +7,6 @@
#include <cassert>
#include <algorithm>
#include <string>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>
#include <uavcan/driver/system_clock.hpp>
@@ -58,8 +57,10 @@ struct UAVCAN_EXPORT CanFrame
bool isRemoteTransmissionRequest() const { return id & FlagRTR; }
bool isErrorFrame() const { return id & FlagERR; }
#if UAVCAN_TOSTRING
enum StringRepresentation { StrTight, StrAligned };
std::string toString(StringRepresentation mode = StrTight) const;
#endif
/**
* CAN frames arbitration rules, particularly STD vs EXT:
@@ -11,6 +11,7 @@
#include <limits>
#include <uavcan/stdint.hpp>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/impl_constants.hpp>
namespace uavcan
{
@@ -60,6 +60,18 @@
# define UAVCAN_EXPORT
#endif
/**
* It might make sense to remove toString() methods for an embedded system
*/
#ifndef UAVCAN_TOSTRING
# define UAVCAN_TOSTRING 1
#endif
#if UAVCAN_TOSTRING
# include <string>
# include <cstdio>
#endif
namespace uavcan
{
@@ -5,7 +5,6 @@
#pragma once
#include <cassert>
#include <string>
#include <uavcan/stdint.hpp>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/impl_constants.hpp>
@@ -65,7 +64,9 @@ public:
int write(const uint8_t* bytes, const int bitlen);
int read(uint8_t* bytes, const int bitlen);
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
}
+9 -2
View File
@@ -4,10 +4,9 @@
#pragma once
#include <uavcan/stdint.hpp>
#include <algorithm>
#include <limits>
#include <cstdio>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/Timestamp.hpp>
@@ -83,7 +82,9 @@ public:
enum { StringBufSize = 32 };
void toString(char buf[StringBufSize]) const;
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
@@ -164,7 +165,9 @@ public:
enum { StringBufSize = 32 };
void toString(char buf[StringBufSize]) const;
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
/*
@@ -230,6 +233,8 @@ void TimeBase<T, D>::toString(char buf[StringBufSize]) const
}
#if UAVCAN_TOSTRING
template <typename D>
std::string DurationBase<D>::toString() const
{
@@ -246,6 +251,8 @@ std::string TimeBase<T, D>::toString() const
return std::string(buf);
}
#endif
template <typename Stream, typename D>
UAVCAN_EXPORT
@@ -31,7 +31,9 @@ struct UAVCAN_EXPORT CanRxFrame : public CanFrame
: iface_index(0)
{ }
#if UAVCAN_TOSTRING
std::string toString(StringRepresentation mode = StrTight) const;
#endif
};
@@ -66,7 +68,9 @@ public:
bool qosHigherThan(const Entry& rhs) const { return qosHigherThan(rhs.frame, Qos(rhs.qos)); }
bool qosLowerThan(const Entry& rhs) const { return qosLowerThan(rhs.frame, Qos(rhs.qos)); }
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
private:
+4 -1
View File
@@ -6,7 +6,6 @@
#include <cassert>
#include <algorithm>
#include <string>
#include <uavcan/transport/transfer.hpp>
#include <uavcan/transport/can_io.hpp>
#include <uavcan/impl_constants.hpp>
@@ -82,7 +81,9 @@ public:
bool operator!=(const Frame& rhs) const { return !operator==(rhs); }
bool operator==(const Frame& rhs) const;
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
@@ -112,7 +113,9 @@ public:
uint8_t getIfaceIndex() const { return iface_index_; }
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
}
@@ -5,7 +5,6 @@
#pragma once
#include <cassert>
#include <string>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>
#include <uavcan/map.hpp>
@@ -52,7 +51,9 @@ public:
(destination_node_id_ == rhs.destination_node_id_);
}
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
UAVCAN_PACKED_END
@@ -61,7 +61,9 @@ public:
NodeID getNodeID() const { return node_id_; }
TransferType getTransferType() const { return TransferType(transfer_type_); }
#if UAVCAN_TOSTRING
std::string toString() const;
#endif
};
/**