Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 3d78081

Browse files
committed
Formatting bindings code with clang-format
Signed-off-by: Thomas Cahuzac <[email protected]>
1 parent 4141855 commit 3d78081

File tree

3 files changed

+114
-113
lines changed

3 files changed

+114
-113
lines changed

bindings/c/ParameterFramework.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ using std::string;
4747
/** Rename long pfw types to short ones in pfw namespace. */
4848
namespace pfw
4949
{
50-
typedef ISelectionCriterionInterface Criterion;
51-
typedef std::map<string, Criterion *> Criteria;
52-
typedef CParameterMgrPlatformConnector Pfw;
50+
typedef ISelectionCriterionInterface Criterion;
51+
typedef std::map<string, Criterion *> Criteria;
52+
typedef CParameterMgrPlatformConnector Pfw;
5353
}
5454

5555
/** Class to abstract the boolean+string status api. */
@@ -59,16 +59,27 @@ class Status
5959
/** Fail without an instance of status. */
6060
static bool failure() { return false; }
6161
/** Fail with the given error msg. */
62-
bool failure(const string &msg) { mMsg = msg; return false; }
62+
bool failure(const string &msg)
63+
{
64+
mMsg = msg;
65+
return false;
66+
}
6367
/** Success (no error message). */
64-
bool success() { mMsg.clear(); return true; }
68+
bool success()
69+
{
70+
mMsg.clear();
71+
return true;
72+
}
6573

6674
/** Forward a status operation.
6775
* @param success[in] the operaton status to forward
6876
* or forward a previous failure if omitted
6977
*/
70-
bool forward(bool success = false) {
71-
if (success) { mMsg.clear(); }
78+
bool forward(bool success = false)
79+
{
80+
if (success) {
81+
mMsg.clear();
82+
}
7283
return success;
7384
}
7485
/** Error message accessors.
@@ -87,7 +98,8 @@ class Status
8798
///////////////////////////////
8899

89100
/** Default log callback. Log to cout or cerr depending on level. */
90-
static void defaultLogCb(void *, PfwLogLevel level, const char *logLine) {
101+
static void defaultLogCb(void *, PfwLogLevel level, const char *logLine)
102+
{
91103
switch (level) {
92104
case pfwLogInfo:
93105
std::cout << logLine << std::endl;
@@ -98,7 +110,7 @@ static void defaultLogCb(void *, PfwLogLevel level, const char *logLine) {
98110
};
99111
}
100112

101-
static PfwLogger defaultLogger = { NULL, &defaultLogCb };
113+
static PfwLogger defaultLogger = {NULL, &defaultLogCb};
102114

103115
class LogWrapper : public CParameterMgrPlatformConnector::ILogger
104116
{
@@ -109,7 +121,7 @@ class LogWrapper : public CParameterMgrPlatformConnector::ILogger
109121
private:
110122
void info(const string &msg) override { log(pfwLogInfo, msg); }
111123

112-
void warning(const string &msg) override { log(pfwLogWarning, msg); }
124+
void warning(const string &msg) override { log(pfwLogWarning, msg); }
113125

114126
void log(PfwLogLevel level, const string &strLog)
115127
{
@@ -137,14 +149,12 @@ struct PfwHandler_ : private utility::NonCopyable
137149
* Is mutable because even a const function can fail.
138150
*/
139151
mutable Status lastStatus;
152+
140153
private:
141154
LogWrapper mLogger;
142155
};
143156

144-
PfwHandler *pfwCreate()
145-
{
146-
return new PfwHandler();
147-
}
157+
PfwHandler *pfwCreate() { return new PfwHandler(); }
148158

149159
void pfwDestroy(PfwHandler *handle)
150160
{
@@ -161,7 +171,6 @@ void PfwHandler::setLogger(const PfwLogger *logger)
161171
pfw->setLogger(&mLogger);
162172
}
163173

164-
165174
bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t criterionNb)
166175
{
167176
Status &status = lastStatus;
@@ -176,8 +185,7 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
176185
}
177186
// Check that the criterion does not exist
178187
if (criteria.find(criterion.name) != criteria.end()) {
179-
return status.failure("Criterion \"" + string(criterion.name) +
180-
"\" already exist");
188+
return status.failure("Criterion \"" + string(criterion.name) + "\" already exist");
181189
}
182190

183191
// Create criterion type
@@ -189,15 +197,15 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
189197
int value;
190198
if (criterion.inclusive) {
191199
// Check that (int)1 << valueIndex would not overflow (UB)
192-
if(std::numeric_limits<int>::max() >> valueIndex == 0) {
200+
if (std::numeric_limits<int>::max() >> valueIndex == 0) {
193201
return status.failure("Too many values for criterion " +
194202
string(criterion.name));
195203
}
196204
value = 1 << valueIndex;
197205
} else {
198206
value = static_cast<int>(valueIndex);
199207
}
200-
const char * valueName = criterion.values[valueIndex];
208+
const char *valueName = criterion.values[valueIndex];
201209
string error;
202210
if (not type->addValuePair(value, valueName, error)) {
203211
return status.failure("Could not add value " + string(valueName) +
@@ -210,10 +218,8 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
210218
return status.success();
211219
}
212220

213-
214-
bool pfwStart(PfwHandler *handle, const char *configPath,
215-
const PfwCriterion criteria[], size_t criterionNb,
216-
const PfwLogger *logger)
221+
bool pfwStart(PfwHandler *handle, const char *configPath, const PfwCriterion criteria[],
222+
size_t criterionNb, const PfwLogger *logger)
217223
{
218224
// Check that the api is correctly used
219225
Status &status = handle->lastStatus;
@@ -233,13 +239,9 @@ bool pfwStart(PfwHandler *handle, const char *configPath,
233239
return status.forward(handle->pfw->start(status.msg()));
234240
}
235241

236-
const char *pfwGetLastError(const PfwHandler *handle)
237-
{
238-
return handle->lastStatus.msg().c_str();
239-
}
242+
const char *pfwGetLastError(const PfwHandler *handle) { return handle->lastStatus.msg().c_str(); }
240243

241-
static pfw::Criterion *getCriterion(const pfw::Criteria &criteria,
242-
const string &name)
244+
static pfw::Criterion *getCriterion(const pfw::Criteria &criteria, const string &name)
243245
{
244246
pfw::Criteria::const_iterator it = criteria.find(name);
245247
return it == criteria.end() ? NULL : it->second;
@@ -300,7 +302,8 @@ PfwParameterHandler *pfwBindParameter(PfwHandler *handle, const char path[])
300302
Status &status = handle->lastStatus;
301303
if (handle->pfw == NULL) {
302304
status.failure("The parameter framework is not started, "
303-
"while trying to bind parameter \"" + string(path) + "\")");
305+
"while trying to bind parameter \"" +
306+
string(path) + "\")");
304307
return NULL;
305308
}
306309

@@ -321,7 +324,6 @@ void pfwUnbindParameter(PfwParameterHandler *handle)
321324
delete handle;
322325
}
323326

324-
325327
bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value)
326328
{
327329
Status &status = handle->pfw.lastStatus;
@@ -339,7 +341,9 @@ bool pfwGetStringParameter(const PfwParameterHandler *handle, char *value[])
339341
*value = NULL;
340342
string retValue;
341343
bool success = handle->parameter.getAsString(retValue, status.msg());
342-
if (not success) { return status.forward(); }
344+
if (not success) {
345+
return status.forward();
346+
}
343347

344348
*value = strdup(retValue.c_str());
345349
return status.success();
@@ -352,4 +356,3 @@ bool pfwSetStringParameter(PfwParameterHandler *handle, const char value[])
352356
}
353357

354358
void pfwFree(void *ptr) { std::free(ptr); }
355-

bindings/c/ParameterFramework.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
#pragma once
4040

41-
4241
#ifdef __cplusplus
4342
extern "C" {
4443
#endif
@@ -53,17 +52,17 @@ extern "C" {
5352
* Such arguments are marked NONNULL.
5453
*/
5554
#if defined(__clang__) || defined(__GNUC__)
56-
# define NONNULL __attribute__((nonnull))
57-
# define NONNULL_(...) __attribute__((nonnull (__VA_ARGS__)))
58-
# define USERESULT __attribute__((warn_unused_result))
55+
#define NONNULL __attribute__((nonnull))
56+
#define NONNULL_(...) __attribute__((nonnull(__VA_ARGS__)))
57+
#define USERESULT __attribute__((warn_unused_result))
5958
#elif defined(_MSC_VER)
60-
// In visual studio's cl there is no
61-
// equivalent of nonnull
62-
# define NONNULL
63-
# define NONNULL_(...)
64-
# define USERESULT _Check_return_
59+
// In visual studio's cl there is no
60+
// equivalent of nonnull
61+
#define NONNULL
62+
#define NONNULL_(...)
63+
#define USERESULT _Check_return_
6564
#else
66-
# error "Unknown compilator"
65+
#error "Unknown compilator"
6766
#endif
6867

6968
/** Private handle to a parameter framework.
@@ -99,7 +98,8 @@ typedef enum {
9998
typedef void PfwLogCb(void *userCtx, PfwLogLevel level, const char *logLine);
10099

101100
/** Logger containing a callback method and its context. */
102-
typedef struct {
101+
typedef struct
102+
{
103103
/** User defined arbitrary value that will be provided to all logCb call. */
104104
void *userCtx;
105105
/** Callback that will be called.
@@ -113,10 +113,12 @@ typedef struct {
113113
///////////////////////////////
114114

115115
/** Structure of a parameter framework criterion. */
116-
typedef struct {
116+
typedef struct
117+
{
117118
/** Name of the criterion in the pfw configuration rules. */
118119
const char *name; //< Must not be null.
119-
bool inclusive; //< True if the criterion is inclusive, false if exclusive.
120+
bool inclusive; //< True if the criterion is inclusive, false if exclusive.
121+
120122
/** Null terminated list of criterion value names.
121123
* @example { "Red", "Green", "Blue", NULL }
122124
*
@@ -131,7 +133,6 @@ typedef struct {
131133
const char **values; //< Must not be null.
132134
} PfwCriterion;
133135

134-
135136
/** Create a parameter framework instance.
136137
* Can not fail except for memory allocation.
137138
*/
@@ -153,9 +154,8 @@ void pfwDestroy(PfwHandler *handle) NONNULL;
153154
* @return true on success, false on failure.
154155
*/
155156
CPARAMETER_EXPORT
156-
bool pfwStart(PfwHandler *handle, const char *configPath,
157-
const PfwCriterion criteria[], size_t criterionNb,
158-
const PfwLogger *loggger) NONNULL_(1, 2, 3) USERESULT;
157+
bool pfwStart(PfwHandler *handle, const char *configPath, const PfwCriterion criteria[],
158+
size_t criterionNb, const PfwLogger *loggger) NONNULL_(1, 2, 3) USERESULT;
159159

160160
/** @return a string describing the last call result.
161161
* If the last pfw function call succeeded, return an empty string.
@@ -190,7 +190,8 @@ CPARAMETER_EXPORT
190190
bool pfwSetCriterion(PfwHandler *handle, const char name[], int value) NONNULL USERESULT;
191191
/** Get a criterion value given its name.
192192
* Same usage as pfwSetCriterion except that value is an out param.
193-
* Get criterion will return the last value setted with pfwSetCriterion independantly of pfwCommitCritenio.
193+
* Get criterion will return the last value setted with pfwSetCriterion independantly of
194+
* pfwCommitCritenio.
194195
*/
195196
CPARAMETER_EXPORT
196197
bool pfwGetCriterion(const PfwHandler *handle, const char name[], int *value) NONNULL USERESULT;
@@ -244,7 +245,7 @@ void pfwUnbindParameter(PfwParameterHandler *handle) NONNULL;
244245
* return true of success, false on failure.
245246
*/
246247
CPARAMETER_EXPORT
247-
bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value ) NONNULL USERESULT;
248+
bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value) NONNULL USERESULT;
248249

249250
/** Set the value of a previously bind int parameter.
250251
* @param handle[in] Handler to a valid parameter.

0 commit comments

Comments
 (0)