Permalink
Browse files

clang format

  • Loading branch information...
jlblancoc committed Dec 7, 2017
1 parent 91f1df7 commit 0354934a19508566bf014022583387d13700ef56
@@ -8,14 +8,17 @@
+------------------------------------------------------------------------+ */
#pragma once
#include <mrpt/config.h> // MRPT_WORD_SIZE
#include <mrpt/config.h> // MRPT_WORD_SIZE
#include <mrpt/io/CStream.h>
#include <cstdint>
#include <string>
namespace mrpt
{
namespace serialization { class CMessage; }
namespace serialization
{
class CMessage;
}
/** Serial and networking devices and utilities */
namespace comms
{
@@ -184,7 +187,8 @@ class CClientTCPSocket : public mrpt::io::CStream
* goes fine.
*/
bool receiveMessage(
mrpt::serialization::CMessage& inMsg, const unsigned int timeoutStart_ms = 100,
mrpt::serialization::CMessage& inMsg,
const unsigned int timeoutStart_ms = 100,
const unsigned int timeoutBetween_ms = 1000);
/** Return the number of bytes already in the receive queue (they can be
@@ -141,7 +141,8 @@ class CSerialPort : public mrpt::utils::CStream
// See base class docs
size_t Write(const void* Buffer, size_t Count) override;
/** not applicable in a serial port */
uint64_t Seek(uint64_t off, CStream::TSeekOrigin o = sFromBeginning) override;
uint64_t Seek(
uint64_t off, CStream::TSeekOrigin o = sFromBeginning) override;
/** not applicable in a serial port */
uint64_t getTotalBytesCount() override;
/** not applicable in a serial port */
@@ -926,7 +926,8 @@ void CSerialPort::purgeBuffers()
MRPT_END
}
uint64_t CSerialPort::Seek(uint64_t off, CStream::TSeekOrigin o = sFromBeginning)
uint64_t CSerialPort::Seek(
uint64_t off, CStream::TSeekOrigin o = sFromBeginning)
{
MRPT_START
MRPT_UNUSED_PARAM(Origin);
@@ -66,8 +66,8 @@ ERRORCODE_HTTP mrpt::comms::net::http_get(
ERRORCODE_HTTP mrpt::comms::net::http_request(
const string& http_method, const string& http_send_content,
const string& url, std::vector<uint8_t>& out_content, string& out_errormsg, int port,
const string& auth_user, const string& auth_pass,
const string& url, std::vector<uint8_t>& out_content, string& out_errormsg,
int port, const string& auth_user, const string& auth_pass,
int* out_http_responsecode, mrpt::utils::TParameters<string>* extra_headers,
mrpt::utils::TParameters<string>* out_headers, int timeout_ms)
{
@@ -381,8 +381,8 @@ ERRORCODE_HTTP mrpt::comms::net::http_request(
http_get
---------------------------------------------------------------*/
ERRORCODE_HTTP mrpt::comms::net::http_get(
const string& url, std::vector<uint8_t>& out_content, string& out_errormsg, int port,
const string& auth_user, const string& auth_pass,
const string& url, std::vector<uint8_t>& out_content, string& out_errormsg,
int port, const string& auth_user, const string& auth_pass,
int* out_http_responsecode, mrpt::utils::TParameters<string>* extra_headers,
mrpt::utils::TParameters<string>* out_headers, int timeout_ms)
{
@@ -71,37 +71,47 @@ std::shared_ptr<T> make_aligned_shared(Args&&... args)
mrpt::aligned_allocator_cpp11<T_nc>(), std::forward<Args>(args)...);
}
void * aligned_malloc(size_t size, size_t alignment);
void aligned_free(void * ptr);
void* aligned_malloc(size_t size, size_t alignment);
void aligned_free(void* ptr);
/** Put this macro inside any class with members that require 16-byte memory
* alignment (e.g. Eigen matrices), to override default new()/delete().
* Obviously, this macro is only *required* if the class is to be instantiated
* in dynamic memory.
*/
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW \
void* operator new(size_t size) { return mrpt::aligned_malloc(size,16); } \
void* operator new[](size_t size) { return mrpt::aligned_malloc(size,16); }\
void* operator new(size_t size) { return mrpt::aligned_malloc(size, 16); } \
void* operator new[](size_t size) \
{ \
return mrpt::aligned_malloc(size, 16); \
} \
void operator delete(void* ptr) noexcept { mrpt::aligned_free(ptr); } \
void operator delete[](void* ptr) noexcept { mrpt::aligned_free(ptr); } \
/* in-place new and delete. since (at least afaik) there is no actual */ \
/* memory allocated we can safely let the default implementation handle */ \
/* this particular case. */ \
static void* operator new(size_t size, void* ptr) { \
static void* operator new(size_t size, void* ptr) \
{ \
return ::operator new(size, ptr); \
} \
void operator delete(void* memory, void* ptr) noexcept { \
void operator delete(void* memory, void* ptr) noexcept \
{ \
return ::operator delete(memory, ptr); \
} \
/* nothrow-new (returns zero instead of std::bad_alloc) */ \
void* operator new(size_t size, const std::nothrow_t&) noexcept \
{ \
try { return mrpt::aligned_malloc(size,16); } \
catch (...) { return nullptr; } \
try \
{ \
return mrpt::aligned_malloc(size, 16); \
} \
catch (...) \
{ \
return nullptr; \
} \
} \
void operator delete(void* ptr, const std::nothrow_t&) noexcept { \
void operator delete(void* ptr, const std::nothrow_t&)noexcept \
{ \
mrpt::aligned_free(ptr); \
}
}
@@ -13,18 +13,18 @@
#include <cstdlib> // for free, posix_memalign, realloc
#if defined(_MSC_VER)
#include <malloc.h> // _aligned_malloc()
#include <malloc.h> // _aligned_malloc()
#endif
void * mrpt::aligned_malloc(size_t size, size_t alignment)
void* mrpt::aligned_malloc(size_t size, size_t alignment)
{
#if defined(__GNUC__) && !defined(__MINGW32__)
return ::aligned_malloc(size, alignment);
#else
return _aligned_malloc(size, alignment);
#endif
}
void mrpt::aligned_free(void * ptr)
void mrpt::aligned_free(void* ptr)
{
#if defined(__GNUC__) && !defined(__MINGW32__)
return ::aligned_free(ptr);
@@ -17,7 +17,7 @@ namespace mrpt
namespace rtti
{
/** A list (actually based on a std::set) of MRPT classes, capable of keeping
* any class registered by the mechanism of CObject classes. Access to "data"
* any class registered by the mechanism of CObject classes. Access to "data"
* for the actual content, or use any of the helper methods in this class.
* \ingroup mrpt_rtti_grp
*/
@@ -15,7 +15,7 @@ using namespace mrpt::rtti;
bool CListOfClasses::containsDerivedFrom(
const mrpt::rtti::TRuntimeClassId* id) const
{
for (const auto &i: data)
for (const auto& i : data)
if (i->derivedFrom(id)) return true;
return false;
}
@@ -24,11 +24,10 @@ std::string CListOfClasses::toString() const
{
std::string s;
unsigned int cnt = 0;
for (const auto &i:data)
for (const auto& i : data)
{
if (cnt++!=0) s += ", ";
if (cnt++ != 0) s += ", ";
s += std::string(i->className);
}
return s;
}
View
@@ -80,10 +80,11 @@ CObject* TRuntimeClassId::createObject() const
{
if (!ptrCreateObject)
{
fprintf(stderr,
fprintf(
stderr,
"[TRuntimeClassId::createObject] Trying to create an object with "
"not dynamic constructor. classname=`%s`\n",
className!=nullptr ? className : "nullptr");
className != nullptr ? className : "nullptr");
return nullptr;
}
@@ -102,8 +103,8 @@ CObject* TRuntimeClassId::createObject() const
// since it has no base class. These methods are defined
// automatically for derived classes.
TRuntimeClassId* CObject::_GetBaseClass() { return nullptr; }
const struct TRuntimeClassId CObject::runtimeClassId = {
"CObject", nullptr, nullptr };
const struct TRuntimeClassId CObject::runtimeClassId = {"CObject", nullptr,
nullptr};
mrpt::rtti::CObject* mrpt::rtti::classFactory(const std::string& className)
{
@@ -112,7 +113,8 @@ mrpt::rtti::CObject* mrpt::rtti::classFactory(const std::string& className)
return pR->createObject();
}
mrpt::rtti::CObject::Ptr mrpt::rtti::classFactoryPtr(const std::string& className)
mrpt::rtti::CObject::Ptr mrpt::rtti::classFactoryPtr(
const std::string& className)
{
mrpt::rtti::CObject::Ptr ret;
auto pR = findRegisteredClass(className);
@@ -175,13 +175,14 @@ void mrpt::rtti::registerClassCustomName(
registerAllPendingClasses();
}
std::vector<const TRuntimeClassId*>mrpt::rtti::getAllRegisteredClasses()
std::vector<const TRuntimeClassId*> mrpt::rtti::getAllRegisteredClasses()
{
return CClassRegistry::Instance().getListOfAllRegisteredClasses();
}
std::vector<const TRuntimeClassId*>mrpt::rtti::getAllRegisteredClassesChildrenOf(
const TRuntimeClassId* parent_id)
std::vector<const TRuntimeClassId*>
mrpt::rtti::getAllRegisteredClassesChildrenOf(
const TRuntimeClassId* parent_id)
{
std::vector<const TRuntimeClassId*> res;
const auto lst = mrpt::rtti::getAllRegisteredClasses();
@@ -26,7 +26,7 @@ struct queue_register_functions_t
/** Retrieve the next message in the queue, or nullptr if there is no
* message. The user MUST call "delete" with the returned object after use.
*/
inline bool get(TRegisterFunction &ret)
inline bool get(TRegisterFunction& ret)
{
std::lock_guard<std::mutex> lock(funcs_cs);
if (funcs.empty())
@@ -38,7 +38,6 @@ struct queue_register_functions_t
return true;
}
}
};
// Use a queue for the pending register issues, but also an atomic counter,
@@ -12,12 +12,12 @@
namespace MyNS
{
class MyDerived1 : public mrpt::rtti::CObject
{
public:
MyDerived1() {}
DEFINE_MRPT_OBJECT(MyDerived1);
};
class MyDerived1 : public mrpt::rtti::CObject
{
public:
MyDerived1() {}
DEFINE_MRPT_OBJECT(MyDerived1);
};
}
IMPLEMENTS_MRPT_OBJECT(MyDerived1, mrpt::rtti::CObject, MyNS)
@@ -29,7 +29,9 @@ void do_register()
TEST(rtti, CObject_CLASSID)
{
EXPECT_TRUE(CLASS_ID(mrpt::rtti::CObject) == &mrpt::rtti::CObject::GetRuntimeClassIdStatic());
EXPECT_TRUE(
CLASS_ID(mrpt::rtti::CObject) ==
&mrpt::rtti::CObject::GetRuntimeClassIdStatic());
}
TEST(rtti, MyDerived1_CLASSID)
@@ -39,7 +41,7 @@ TEST(rtti, MyDerived1_CLASSID)
EXPECT_TRUE(std::string(cid_myd1->className) == std::string("MyDerived1"));
const auto cid_cobj = CLASS_ID(mrpt::rtti::CObject);
EXPECT_TRUE(cid_myd1->getBaseClass()==cid_cobj);
EXPECT_TRUE(cid_myd1->getBaseClass() == cid_cobj);
// RTTI IS_DERIVED()
{

0 comments on commit 0354934

Please sign in to comment.