Skip to content

Commit

Permalink
Merge pull request #63 from robotology/feature/clang-format
Browse files Browse the repository at this point in the history
Apply clang-format
  • Loading branch information
xela-95 authored Jan 12, 2024
2 parents 4bd3301 + 06c17b9 commit 25216f1
Show file tree
Hide file tree
Showing 25 changed files with 1,787 additions and 1,664 deletions.
105 changes: 105 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 10
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 5
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .git-blame-ignore-revs
# Refactored all source code files with clang-format
c053fb04719221a796132bfc73b3d09bb4e5bab2
82 changes: 42 additions & 40 deletions libraries/singleton-devices/Handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
#include <yarp/os/Log.h>
#include <yarp/os/LogStream.h>

namespace gzyarp
namespace gzyarp
{

Handler* Handler::getHandler()
{
std::lock_guard<std::mutex> lock(mutex());
if (!s_handle)
if (!s_handle)
{
s_handle = new Handler();
if (!s_handle)
yError() << "Error while calling gzyarp::Handler constructor";
}

return s_handle;
}


bool Handler::getDevicesAsPolyDriverList(const std::string& modelScopedName, yarp::dev::PolyDriverList& list,
std::vector<std::string>& deviceScopedNames/*, const std::string& worldName*/)
bool Handler::getDevicesAsPolyDriverList(
const std::string& modelScopedName,
yarp::dev::PolyDriverList& list,
std::vector<std::string>& deviceScopedNames /*, const std::string& worldName*/)
{
deviceScopedNames.resize(0);

Expand All @@ -30,34 +31,35 @@ bool Handler::getDevicesAsPolyDriverList(const std::string& modelScopedName, yar
// to the returned yarp::dev::PolyDriverList
std::unordered_map<std::string, std::string> inserted_yarpDeviceName2deviceDatabaseKey;

for (auto&& devicesMapElem: m_devicesMap)
for (auto&& devicesMapElem : m_devicesMap)
{
std::string deviceDatabaseKey = devicesMapElem.first;
std::string yarpDeviceName;

// If the deviceDatabaseKey starts with the modelScopedName (device spawned by model plugins),
// then it is eligible for insertion in the returned list
if ((deviceDatabaseKey.rfind(modelScopedName, 0) == 0) /*|| (deviceDatabaseKey.rfind(worldName + "/" + modelScopedName, 0) == 0)*/)

// If the deviceDatabaseKey starts with the modelScopedName (device spawned by model
// plugins), then it is eligible for insertion in the returned list
if ((deviceDatabaseKey.rfind(modelScopedName, 0)
== 0) /*|| (deviceDatabaseKey.rfind(worldName + "/" + modelScopedName, 0) == 0)*/)
{
// Extract yarpDeviceName from deviceDatabaseKey
yarpDeviceName = deviceDatabaseKey.substr(deviceDatabaseKey.find_last_of("/")+1);
yarpDeviceName = deviceDatabaseKey.substr(deviceDatabaseKey.find_last_of("/") + 1);

// Check if a device with the same yarpDeviceName was already inserted
auto got = inserted_yarpDeviceName2deviceDatabaseKey.find(yarpDeviceName);

// If not found, insert and continue
if (got == inserted_yarpDeviceName2deviceDatabaseKey.end())
if (got == inserted_yarpDeviceName2deviceDatabaseKey.end())
{
// If no name collision is found, insert and continue
inserted_yarpDeviceName2deviceDatabaseKey.insert({yarpDeviceName, deviceDatabaseKey});
inserted_yarpDeviceName2deviceDatabaseKey.insert(
{yarpDeviceName, deviceDatabaseKey});
list.push(devicesMapElem.second, yarpDeviceName.c_str());
deviceScopedNames.push_back(deviceDatabaseKey);
}
else
} else
{
// If a name collision is found, print a clear error and return
yError() << "gzyarp::Handler robotinterface getDevicesAsPolyDriverList error: ";
yError() << "two YARP devices with yarpDeviceName " << yarpDeviceName
yError() << "two YARP devices with yarpDeviceName " << yarpDeviceName
<< " found in model " << modelScopedName;
yError() << "First instance: " << got->second;
yError() << "Second instance: " << deviceDatabaseKey;
Expand All @@ -75,26 +77,29 @@ bool Handler::setDevice(std::string deviceDatabaseKey, yarp::dev::PolyDriver* de
{
bool ret = false;
DevicesMap::iterator device = m_devicesMap.find(deviceDatabaseKey);
if (device != m_devicesMap.end())
if (device != m_devicesMap.end())
{
if(device->second == device2add)
if (device->second == device2add)
ret = true;
else
{
yError() << " Error in gzyarp::Handler while inserting a new yarp device pointer!";
yError() << " The name of the device is already present but the pointer does not match with the one already registered!";
yError() << " This should not happen, check the names are correct in your config file. Fatal error.";
yError() << " The name of the device is already present but the pointer does not match "
"with the one already registered!";
yError() << " This should not happen, check the names are correct in your config file. "
"Fatal error.";
}
}
else
} else
{
//device does not exists. Add to map
if (!m_devicesMap.insert(std::pair<std::string, yarp::dev::PolyDriver*>(deviceDatabaseKey, device2add)).second)
// device does not exists. Add to map
if (!m_devicesMap
.insert(
std::pair<std::string, yarp::dev::PolyDriver*>(deviceDatabaseKey, device2add))
.second)
{
yError() << " Error in gzyarp::Handler while inserting a new device pointer!";
ret = false;
}
else
} else
ret = true;
}
return ret;
Expand All @@ -105,43 +110,40 @@ yarp::dev::PolyDriver* Handler::getDevice(const std::string& deviceDatabaseKey)
yarp::dev::PolyDriver* tmp = NULL;

DevicesMap::const_iterator device = m_devicesMap.find(deviceDatabaseKey);
if (device != m_devicesMap.end())
if (device != m_devicesMap.end())
tmp = device->second;
else
else
tmp = NULL;

return tmp;
}

void Handler::removeDevice(const std::string &deviceDatabaseKey)
void Handler::removeDevice(const std::string& deviceDatabaseKey)
{
DevicesMap::iterator device = m_devicesMap.find(deviceDatabaseKey);
if (device != m_devicesMap.end())
{
if (device != m_devicesMap.end())
{
device->second->close();
m_devicesMap.erase(device);
}
else
} else
{
yError() << "Could not remove device " << deviceDatabaseKey << ". Device was not found";
}
return;
}

Handler::Handler() : m_devicesMap()
Handler::Handler()
: m_devicesMap()
{
m_devicesMap.clear();
}

Handler* Handler::s_handle = NULL;


std::mutex& Handler::mutex()
{
static std::mutex s_mutex;
return s_mutex;
}

}


} // namespace gzyarp
47 changes: 23 additions & 24 deletions libraries/singleton-devices/Handler.hh
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
#include <gz/common/Event.hh>
#include <mutex>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/PolyDriverList.h>
#include <gz/common/Event.hh>

namespace gzyarp
namespace gzyarp
{

class Handler
{
public:
static Handler* getHandler();

bool getDevicesAsPolyDriverList(const std::string& modelScopedName, yarp::dev::PolyDriverList& list,
std::vector<std::string>& deviceScopedNames/*, const std::string& worldName*/);

bool setDevice(std::string deviceDatabaseKey, yarp::dev::PolyDriver* device2add);

yarp::dev::PolyDriver* getDevice(const std::string& deviceDatabaseKey) const;

void removeDevice(const std::string& deviceDatabaseKey);

private:
Handler();
static Handler* s_handle;
static std::mutex& mutex();
typedef std::map<std::string, yarp::dev::PolyDriver*> DevicesMap;
DevicesMap m_devicesMap; // map of known yarp devices
{
public:
static Handler* getHandler();

};
bool getDevicesAsPolyDriverList(
const std::string& modelScopedName,
yarp::dev::PolyDriverList& list,
std::vector<std::string>& deviceScopedNames /*, const std::string& worldName*/);

bool setDevice(std::string deviceDatabaseKey, yarp::dev::PolyDriver* device2add);

}
yarp::dev::PolyDriver* getDevice(const std::string& deviceDatabaseKey) const;

void removeDevice(const std::string& deviceDatabaseKey);

private:
Handler();
static Handler* s_handle;
static std::mutex& mutex();
typedef std::map<std::string, yarp::dev::PolyDriver*> DevicesMap;
DevicesMap m_devicesMap; // map of known yarp devices
};

} // namespace gzyarp
Loading

0 comments on commit 25216f1

Please sign in to comment.