Permalink
Browse files

clang format fixes

  • Loading branch information...
jlblancoc committed Nov 3, 2018
1 parent fd7cb90 commit d7a35e145837523676a7a3541196dc84924c74bf
@@ -113,7 +113,8 @@ void CLogFileRecord::serializeTo(mrpt::serialization::CArchive& out) const
// Version 3 ----------
for (i = 0; i < infoPerPTG.size(); i++)
{
out << infoPerPTG[i].evalFactors.base; // v22: this is now a TParameters
out << infoPerPTG[i]
.evalFactors.base; // v22: this is now a TParameters
}

out << nPTGs; // v4
@@ -392,46 +392,47 @@ template <class T, class... Ts>
using is_any = std::disjunction<std::is_same<T, Ts>...>;

template <typename T>
using is_simple_type = is_any<T, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, long double>;
using is_simple_type = is_any<
T, bool, uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t,
int64_t, float, double, long double>;

#if MRPT_IS_BIG_ENDIAN
// Big endian system: Convert into little-endian for streaming
template <typename T, std::enable_if_t<is_simple_type<T>::value, int> = 0>
CArchive& mrpt::serialization::operator<<(CArchive& out, const T a)
{
mrpt::reverseBytesInPlace(a);
out.WriteBuffer((void*)&a, sizeof(a));
return out;
mrpt::reverseBytesInPlace(a);
out.WriteBuffer((void*)&a, sizeof(a));
return out;
}

template <typename T, std::enable_if_t<is_simple_type<T>::value, int> = 0>
CArchive& mrpt::serialization::operator>>(CArchive& in, T& a)
{
T b;
in.ReadBuffer((void*)&b, sizeof(a));
mrpt::reverseBytesInPlace(b);
::memcpy(&a, &b, sizeof(b));
return in;
T b;
in.ReadBuffer((void*)&b, sizeof(a));
mrpt::reverseBytesInPlace(b);
::memcpy(&a, &b, sizeof(b));
return in;
}

#else
// Little endian system:
template <typename T, std::enable_if_t<is_simple_type<T>::value, int> = 0>
CArchive& operator<<(CArchive& out, const T& a)
{
out.WriteBuffer((void*)&a, sizeof(a));
return out;
out.WriteBuffer((void*)&a, sizeof(a));
return out;
}

template <typename T, std::enable_if_t<is_simple_type<T>::value, int> = 0>
CArchive& operator>> (CArchive& in, T& a)
CArchive& operator>>(CArchive& in, T& a)
{
in.ReadBuffer((void*)&a, sizeof(a));
return in;
in.ReadBuffer((void*)&a, sizeof(a));
return in;
}
#endif


CArchive& operator<<(CArchive& out, const mrpt::Clock::time_point& a);
CArchive& operator>>(CArchive& in, mrpt::Clock::time_point& a);

@@ -65,74 +65,89 @@ namespace mrpt::serialization
}

template <typename T>
using is_map_like = std::is_same<typename T::value_type,
std::pair<const typename T::key_type, typename T::mapped_type>>;
using is_map_like = std::is_same<
typename T::value_type,
std::pair<const typename T::key_type, typename T::mapped_type>>;

template <typename T>
using is_map = std::is_same<T, typename std::map<typename T::key_type, typename T::mapped_type,
typename T::key_compare, typename T::allocator_type>>;
using is_map = std::is_same<
T, typename std::map<
typename T::key_type, typename T::mapped_type,
typename T::key_compare, typename T::allocator_type>>;

template <typename T>
using is_multimap = std::is_same<T, typename std::multimap<typename T::key_type, typename T::mapped_type,
typename T::key_compare, typename T::allocator_type>>;
using is_multimap = std::is_same<
T, typename std::multimap<
typename T::key_type, typename T::mapped_type,
typename T::key_compare, typename T::allocator_type>>;

template <typename T, std::enable_if_t<is_map<T>::value, int> = 0>
std::string containerName(){ return "std::map";}
std::string containerName()
{
return "std::map";
}
template <typename T, std::enable_if_t<is_multimap<T>::value, int> = 0>
std::string containerName(){ return "std::multimap";}
std::string containerName()
{
return "std::multimap";
}

/** Template method to serialize an associative STL container */
/** Template method to serialize an associative STL container */
template <class T, std::enable_if_t<is_map_like<T>::value, int> = 0>
CArchive& operator<<(CArchive& out, const T& obj)
{
out << containerName<T>() << mrpt::typemeta::TTypeName<typename T::key_type>::get()
<< mrpt::typemeta::TTypeName<std::decay_t<typename T::mapped_type>>::get();
out << static_cast<uint32_t>(obj.size());
for (typename T::const_iterator it =
obj.begin();
it != obj.end(); ++it)
out << it->first << it->second;
return out;
}
/** Template method to deserialize an associative STL container */
out << containerName<T>()
<< mrpt::typemeta::TTypeName<typename T::key_type>::get()
<< mrpt::typemeta::TTypeName<
std::decay_t<typename T::mapped_type>>::get();
out << static_cast<uint32_t>(obj.size());
for (typename T::const_iterator it = obj.begin(); it != obj.end(); ++it)
out << it->first << it->second;
return out;
}
/** Template method to deserialize an associative STL container */
template <class T, std::enable_if_t<is_map_like<T>::value, int> = 0>
CArchive& operator>>(CArchive& in, T& obj)
{
CArchive& operator>>(CArchive& in, T& obj)
{
obj.clear();
std::string pref, stored_K, stored_V;
in >> pref;
if (pref != containerName<T>())
THROW_EXCEPTION(format(
"Error: serialized container %s<%s,%s>'s preamble is "
"wrong: '%s'",
containerName<T>().c_str(), mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str(),
mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str(), pref.c_str()))
"Error: serialized container %s<%s,%s>'s preamble is "
"wrong: '%s'",
containerName<T>().c_str(),
mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str(),
mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str(),
pref.c_str()))
in >> stored_K;
if (stored_K !=
std::string(mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str()))
THROW_EXCEPTION(format(
"Error: serialized container %s key type %s != %s",
containerName<T>().c_str(), stored_K.c_str(),
mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str()))
in >> stored_V;
if (stored_V !=
std::string(mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str()))
THROW_EXCEPTION(format(
"Error: serialized container %s value type %s != %s",
containerName<T>().c_str(), stored_V.c_str(),
mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str()))
uint32_t n;
in >> n;
if (stored_K !=
std::string(
mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str()))
THROW_EXCEPTION(format(
"Error: serialized container %s key type %s != %s",
containerName<T>().c_str(), stored_K.c_str(),
mrpt::typemeta::TTypeName<typename T::key_type>::get().c_str()))
in >> stored_V;
if (stored_V !=
std::string(
mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str()))
THROW_EXCEPTION(format(
"Error: serialized container %s value type %s != %s",
containerName<T>().c_str(), stored_V.c_str(),
mrpt::typemeta::TTypeName<typename T::mapped_type>::get().c_str()))
uint32_t n;
in >> n;
for (uint32_t i = 0; i < n; i++)
{
typename T::key_type key_obj;
in >> key_obj;
/* Create an pair (Key, empty), then read directly into the
* ".second": */
typename T::iterator it_new =
obj.insert(obj.end(), std::make_pair(key_obj, typename T::mapped_type()));
{
typename T::key_type key_obj;
in >> key_obj;
/* Create an pair (Key, empty), then read directly into the
* ".second": */
typename T::iterator it_new = obj.insert(
obj.end(), std::make_pair(key_obj, typename T::mapped_type()));
in >> it_new->second;
}
}
return in;
}

@@ -184,7 +199,6 @@ MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std::vector)
MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std::deque)
MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std::list)


MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(std::set)
MRPTSTL_SERIALIZABLE_SIMPLE_ASSOC_CONTAINER(std::multiset)

@@ -62,7 +62,8 @@ struct TParameters
TParameters() {}
/** Constructor with a list of initial values (see the description and use
* example in mrpt::system::TParameters) */
TParameters(std::initializer_list<typename BASE::value_type> init) : base(init)
TParameters(std::initializer_list<typename BASE::value_type> init)
: base(init)
{
}
inline bool has(const std::string& s) const
@@ -125,41 +126,19 @@ struct TParameters
s = str.str();
}

inline void clear()
{
base.clear();
}
inline void clear() { base.clear(); }

iterator find( const std::string& key )
{
return base.find(key);
}
iterator find(const std::string& key) { return base.find(key); }

const_iterator find( const std::string& key ) const
{
return base.find(key);
}
const_iterator find(const std::string& key) const { return base.find(key); }

iterator begin() noexcept
{
return base.begin();
}
iterator begin() noexcept { return base.begin(); }

const_iterator begin() const noexcept
{
return base.begin();
}
const_iterator begin() const noexcept { return base.begin(); }

iterator end() noexcept
{
return base.end();
}

const_iterator end() const noexcept
{
return base.end();
}
iterator end() noexcept { return base.end(); }

const_iterator end() const noexcept { return base.end(); }
};

/** See the generic template mrpt::system::TParameters */
@@ -41,12 +41,15 @@ void TestParameters()
{
// Call #2
cout << "CALL #2 ================================\n";
// clang-format off
TParametersDouble p(
{
{"threshold", 3.05},
{"altitude", 100.0},
{"level", -1.0}
});
}
);
// clang-format on

MyCoolFunction(p);
}

0 comments on commit d7a35e1

Please sign in to comment.