Skip to content

Commit

Permalink
Fix warnings -Wheader-hygiene (#2273)
Browse files Browse the repository at this point in the history
* Fix warnings -Wheader-hygeine

../../src/setup_payload/SetupPayloadHelper.h:31:17: error: using namespace directive in global context in header [-Werror,-Wheader-hygiene]
using namespace std;

* Restyled by clang-format

* Add std:: namespace to string use in wifi-echo

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
mspang and restyled-commits authored Aug 22, 2020
1 parent ccf6f88 commit cc2423a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ bool isRendezvousBypassed()
std::string createSetupPayload()
{
CHIP_ERROR err = CHIP_NO_ERROR;
string result;
std::string result;

uint32_t discriminator;
err = ConfigurationMgr().GetSetupDiscriminator(discriminator);
Expand Down
14 changes: 7 additions & 7 deletions src/qrcodetool/setup_payload_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ enum class SetupPayloadCodeType
SetupPayloadCodeTypeManual
};

static string _extractFilePath(int argc, char * const * argv)
static std::string _extractFilePath(int argc, char * const * argv)
{
string path;
std::string path;
if (argc == 0)
{
return path;
Expand All @@ -53,18 +53,18 @@ static string _extractFilePath(int argc, char * const * argv)
return path; /* @@@ Return 2 triggers usage message. */
}
}
return string(filePath);
return std::string(filePath);
}

extern int setup_payload_operation_generate_qr_code(int argc, char * const * argv)
{
ChipLogDetail(chipTool, "setup_payload_operation_generate_qr_code\n");
string path = _extractFilePath(argc, argv);
std::string path = _extractFilePath(argc, argv);
if (path.length() == 0)
{
return 2;
}
string code;
std::string code;
CHIP_ERROR err = generateQRCodeFromFilePath(path, code);
if (err == CHIP_NO_ERROR)
{
Expand All @@ -80,12 +80,12 @@ extern int setup_payload_operation_generate_qr_code(int argc, char * const * arg
extern int setup_payload_operation_generate_manual_code(int argc, char * const * argv)
{
ChipLogDetail(chipTool, "setup_payload_operation_generate_qr_code\n");
string path = _extractFilePath(argc, argv);
std::string path = _extractFilePath(argc, argv);
if (path.length() == 0)
{
return 2;
}
string code;
std::string code;
CHIP_ERROR err = generateManualCodeFromFilePath(path, code);
if (err == CHIP_NO_ERROR)
{
Expand Down
6 changes: 2 additions & 4 deletions src/setup_payload/Base41.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#include <string>
#include <vector>

using namespace std;

namespace chip {
// returns CHIP_NO_ERROR on successful decode
CHIP_ERROR base41Decode(string base41, vector<uint8_t> & out);
string base41Encode(const uint8_t * buf, size_t buf_len);
CHIP_ERROR base41Decode(std::string base41, std::vector<uint8_t> & out);
std::string base41Encode(const uint8_t * buf, size_t buf_len);

} // namespace chip

Expand Down
10 changes: 5 additions & 5 deletions src/setup_payload/ManualSetupPayloadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ static uint32_t shortPayloadRepresentation(const SetupPayload & payload)
return result;
}

static string decimalStringWithPadding(uint32_t number, int minLength)
static std::string decimalStringWithPadding(uint32_t number, int minLength)
{
char buf[minLength + 1];
snprintf(buf, sizeof(buf), "%0*" PRIu32, minLength, number);
return string(buf);
return std::string(buf);
}

CHIP_ERROR ManualSetupPayloadGenerator::payloadDecimalStringRepresentation(string & outDecimalString)
CHIP_ERROR ManualSetupPayloadGenerator::payloadDecimalStringRepresentation(std::string & outDecimalString)
{
if (!mSetupPayload.isValidManualCode())
{
ChipLogError(SetupPayload, "Failed encoding invalid payload");
return CHIP_ERROR_INVALID_ARGUMENT;
}

uint32_t shortDecimal = shortPayloadRepresentation(mSetupPayload);
string decimalString = decimalStringWithPadding(shortDecimal, kManualSetupShortCodeCharLength);
uint32_t shortDecimal = shortPayloadRepresentation(mSetupPayload);
std::string decimalString = decimalStringWithPadding(shortDecimal, kManualSetupShortCodeCharLength);

if (mSetupPayload.requiresCustomFlow)
{
Expand Down
3 changes: 1 addition & 2 deletions src/setup_payload/ManualSetupPayloadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include <string>

using namespace std;
namespace chip {

class ManualSetupPayloadGenerator
Expand All @@ -52,7 +51,7 @@ class ManualSetupPayloadGenerator
ManualSetupPayloadGenerator(const SetupPayload & payload) : mSetupPayload(payload){};

// Populates decimal string representation of the payload into outDecimalString
CHIP_ERROR payloadDecimalStringRepresentation(string & outDecimalString);
CHIP_ERROR payloadDecimalStringRepresentation(std::string & outDecimalString);
};

}; // namespace chip
Expand Down
5 changes: 2 additions & 3 deletions src/setup_payload/ManualSetupPayloadParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <core/CHIPError.h>
#include <string>
using namespace std;

namespace chip {

Expand All @@ -36,10 +35,10 @@ namespace chip {
class ManualSetupPayloadParser
{
private:
string mDecimalStringRepresentation;
std::string mDecimalStringRepresentation;

public:
ManualSetupPayloadParser(string decimalRepresentation) : mDecimalStringRepresentation(decimalRepresentation){};
ManualSetupPayloadParser(std::string decimalRepresentation) : mDecimalStringRepresentation(decimalRepresentation){};
CHIP_ERROR populatePayload(SetupPayload & outPayload);
};

Expand Down
5 changes: 2 additions & 3 deletions src/setup_payload/QRCodeSetupPayloadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "SetupPayload.h"

#include <string>
using namespace std;

#ifndef _QR_CODE_SETUP_PAYLOAD_GENERATOR_
#define _QR_CODE_SETUP_PAYLOAD_GENERATOR_
Expand Down Expand Up @@ -58,7 +57,7 @@ class QRCodeSetupPayloadGenerator
* that an error occurred preventing the function from
* producing the requested string.
*/
CHIP_ERROR payloadBase41Representation(string & base41Representation);
CHIP_ERROR payloadBase41Representation(std::string & base41Representation);

/**
* This function is called to encode the binary data of a payload to a
Expand All @@ -82,7 +81,7 @@ class QRCodeSetupPayloadGenerator
* that an error occurred preventing the function from
* producing the requested string.
*/
CHIP_ERROR payloadBase41Representation(string & base41Representation, uint8_t * tlvDataStart, size_t tlvDataStartSize);
CHIP_ERROR payloadBase41Representation(std::string & base41Representation, uint8_t * tlvDataStart, size_t tlvDataStartSize);

private:
CHIP_ERROR generateTLVFromOptionalData(SetupPayload & outPayload, uint8_t * tlvDataStart, uint32_t maxLen,
Expand Down
7 changes: 3 additions & 4 deletions src/setup_payload/QRCodeSetupPayloadParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <core/CHIPTLV.h>

#include <string>
using namespace std;

namespace chip {

Expand All @@ -38,15 +37,15 @@ namespace chip {
class QRCodeSetupPayloadParser
{
private:
string mBase41Representation;
std::string mBase41Representation;

public:
QRCodeSetupPayloadParser(string base41Representation) : mBase41Representation(base41Representation){};
QRCodeSetupPayloadParser(std::string base41Representation) : mBase41Representation(base41Representation){};
CHIP_ERROR populatePayload(SetupPayload & outPayload);

private:
CHIP_ERROR retrieveOptionalInfos(SetupPayload & outPayload, TLV::TLVReader & reader);
CHIP_ERROR populateTLV(SetupPayload & outPayload, const vector<uint8_t> & buf, int & index);
CHIP_ERROR populateTLV(SetupPayload & outPayload, const std::vector<uint8_t> & buf, int & index);
CHIP_ERROR parseTLVFields(chip::SetupPayload & outPayload, uint8_t * tlvDataStart, uint32_t tlvDataLengthInBytes);
};

Expand Down
18 changes: 8 additions & 10 deletions src/setup_payload/SetupPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#include <core/CHIPError.h>

using namespace std;

namespace chip {

// TODO this should point to the spec
Expand Down Expand Up @@ -104,7 +102,7 @@ struct OptionalQRCodeInfo
/*@{*/
uint8_t tag; /**< the tag number of the optional info */
enum optionalQRCodeInfoType type; /**< the type (String or Int) of the optional info */
string data; /**< the string value if type is optionalQRCodeInfoTypeString, otherwise should not be set */
std::string data; /**< the string value if type is optionalQRCodeInfoTypeString, otherwise should not be set */
int32_t int32; /**< the integer value if type is optionalQRCodeInfoTypeInt, otherwise should not be set */
/*@}*/
};
Expand Down Expand Up @@ -147,7 +145,7 @@ class SetupPayload
* @param data String representation of data to add
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR addOptionalVendorData(uint8_t tag, string data);
CHIP_ERROR addOptionalVendorData(uint8_t tag, std::string data);

/** @brief A function to add an optional vendor data
* @param tag 7 bit [0-127] tag number
Expand All @@ -165,13 +163,13 @@ class SetupPayload
* @brief A function to retrieve the vector of OptionalQRCodeInfo infos
* @return Returns a vector of optionalQRCodeInfos
**/
vector<OptionalQRCodeInfo> getAllOptionalVendorData();
std::vector<OptionalQRCodeInfo> getAllOptionalVendorData();

/** @brief A function to add a string serial number
* @param serialNumber string serial number
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR addSerialNumber(string serialNumber);
CHIP_ERROR addSerialNumber(std::string serialNumber);

/** @brief A function to add a uint32_t serial number
* @param serialNumber uint32_t serial number
Expand All @@ -183,7 +181,7 @@ class SetupPayload
* @param outSerialNumber retrieved string serial number
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR getSerialNumber(string & outSerialNumber);
CHIP_ERROR getSerialNumber(std::string & outSerialNumber);

/** @brief A function to remove the serial number from the payload
* @return Returns a CHIP_ERROR_KEY_NOT_FOUND on error, CHIP_NO_ERROR otherwise
Expand All @@ -200,8 +198,8 @@ class SetupPayload
bool operator==(SetupPayload & input);

private:
map<uint8_t, OptionalQRCodeInfo> optionalVendorData;
map<uint8_t, OptionalQRCodeInfoExtension> optionalExtensionData;
std::map<uint8_t, OptionalQRCodeInfo> optionalVendorData;
std::map<uint8_t, OptionalQRCodeInfoExtension> optionalExtensionData;

/** @brief A function to add an optional QR Code info vendor object
* @param info Optional QR code info object to add
Expand All @@ -219,7 +217,7 @@ class SetupPayload
* @brief A function to retrieve the vector of CHIPQRCodeInfo infos
* @return Returns a vector of CHIPQRCodeInfos
**/
vector<OptionalQRCodeInfoExtension> getAllOptionalExtensionData();
std::vector<OptionalQRCodeInfoExtension> getAllOptionalExtensionData();

/** @brief A function to retrieve an optional QR Code info vendor object
* @param tag 7 bit [0-127] tag number
Expand Down
16 changes: 8 additions & 8 deletions src/setup_payload/SetupPayloadHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ enum SetupPayloadKey
struct SetupPayloadParameter
{
SetupPayloadKey key;
string stringValue;
std::string stringValue;
uint64_t uintValue;
};

static CHIP_ERROR resolveSetupPayloadParameter(SetupPayloadParameter & parameter, string key, string value)
static CHIP_ERROR resolveSetupPayloadParameter(SetupPayloadParameter & parameter, std::string key, std::string value)
{
bool isUnsignedInt = true;
bool shouldHaveValue = true;
Expand Down Expand Up @@ -139,16 +139,16 @@ static CHIP_ERROR addParameter(SetupPayload & setupPayload, SetupPayloadParamete
return CHIP_NO_ERROR;
}

CHIP_ERROR loadPayloadFromFile(SetupPayload & setupPayload, string filePath)
CHIP_ERROR loadPayloadFromFile(SetupPayload & setupPayload, std::string filePath)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ifstream fileStream(filePath);
std::ifstream fileStream(filePath);
VerifyOrExit(!fileStream.fail(), err = CHIP_ERROR_INVALID_ARGUMENT);

while (fileStream)
{
string key;
string value;
std::string key;
std::string value;
SetupPayloadParameter parameter;

getline(fileStream, key, ' ');
Expand All @@ -169,7 +169,7 @@ CHIP_ERROR loadPayloadFromFile(SetupPayload & setupPayload, string filePath)
return err;
}

CHIP_ERROR generateQRCodeFromFilePath(string filePath, string & outCode)
CHIP_ERROR generateQRCodeFromFilePath(std::string filePath, std::string & outCode)
{
SetupPayload setupPayload;
CHIP_ERROR err = loadPayloadFromFile(setupPayload, filePath);
Expand All @@ -182,7 +182,7 @@ CHIP_ERROR generateQRCodeFromFilePath(string filePath, string & outCode)
return err;
}

CHIP_ERROR generateManualCodeFromFilePath(string filePath, string & outCode)
CHIP_ERROR generateManualCodeFromFilePath(std::string filePath, std::string & outCode)
{
SetupPayload setupPayload;
CHIP_ERROR err = loadPayloadFromFile(setupPayload, filePath);
Expand Down
6 changes: 2 additions & 4 deletions src/setup_payload/SetupPayloadHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@

#include <string>

using namespace std;

namespace chip {
CHIP_ERROR generateQRCodeFromFilePath(string filePath, string & outCode);
CHIP_ERROR generateManualCodeFromFilePath(string filePath, string & outCode);
CHIP_ERROR generateQRCodeFromFilePath(std::string filePath, std::string & outCode);
CHIP_ERROR generateManualCodeFromFilePath(std::string filePath, std::string & outCode);
} // namespace chip

#endif /* SetupPayloadHelper_h */

0 comments on commit cc2423a

Please sign in to comment.