Skip to content

Commit

Permalink
Removed using namespace std from all files (project-chip#35741)
Browse files Browse the repository at this point in the history
* Removed using namespace std from all files

* Fix compilation

* Found some more files were using namespace std

* Fix TV app

* Use std::to_underlying with c++23 and later

* Addressed review comments
  • Loading branch information
jadhavrohit924 authored and yyzhong-g committed Dec 11, 2024
1 parent 68b8081 commit 02008bc
Show file tree
Hide file tree
Showing 46 changed files with 100 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <app/util/config.h>
#include <static-supported-modes-manager.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <app/util/config.h>
#include <static-supported-temperature-levels.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::TemperatureControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifdef MATTER_DM_PLUGIN_AUDIO_OUTPUT_SERVER
#include "AudioOutputManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::AudioOutput;
using chip::app::AttributeValueEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#ifdef MATTER_DM_PLUGIN_MEDIA_INPUT_SERVER
#include "MediaInputManager.h"

using namespace std;
using namespace chip;
using namespace chip::app::Clusters::MediaInput;
using Protocols::InteractionModel::Status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#ifdef MATTER_DM_PLUGIN_MEDIA_PLAYBACK_SERVER
#include "MediaPlaybackManager.h"

using namespace std;
using namespace chip;
using namespace chip::app;
using namespace chip::app::DataModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <list>
#include <string>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::TargetNavigator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <app/util/config.h>
#include <static-supported-modes-manager.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ModeSelect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <app/util/config.h>
#include <static-supported-temperature-levels.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::TemperatureControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <app/util/config.h>
#include <static-supported-temperature-levels.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::TemperatureControl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@
#include <json/json.h>
#include <lib/core/DataModelTypes.h>

using namespace std;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::AccountLogin;
using Status = chip::Protocols::InteractionModel::Status;

namespace {

const auto loginTempAccountIdentifierFieldId =
to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier));
const auto loginSetupPINFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN));
const auto loginNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode));
const auto logoutNodeFieldId = to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode));
std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kTempAccountIdentifier));
const auto loginSetupPINFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kSetupPIN));
const auto loginNodeFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Login::Fields::kNode));
const auto logoutNodeFieldId = std::to_string(chip::to_underlying(AccountLogin::Commands::Logout::Fields::kNode));

string charSpanToString(const CharSpan & charSpan)
std::string charSpanToString(const CharSpan & charSpan)
{
return { charSpan.data(), charSpan.size() };
}
Expand All @@ -45,12 +44,12 @@ std::string serializeLoginCommand(AccountLogin::Commands::Login::Type cmd)
{
return R"({")" + loginTempAccountIdentifierFieldId + R"(":")" + charSpanToString(cmd.tempAccountIdentifier) + R"(",)" + R"(")" +
loginSetupPINFieldId + R"(":")" + charSpanToString(cmd.setupPIN) + R"(",)" + R"(")" + loginNodeFieldId + R"(":")" +
to_string(cmd.node.Value()) + R"("})";
std::to_string(cmd.node.Value()) + R"("})";
}

std::string serializeLogoutCommand(AccountLogin::Commands::Logout::Type cmd)
{
return R"({")" + logoutNodeFieldId + R"(":")" + to_string(cmd.node.Value()) + R"("})";
return R"({")" + logoutNodeFieldId + R"(":")" + std::to_string(cmd.node.Value()) + R"("})";
}

} // namespace
Expand Down Expand Up @@ -128,7 +127,7 @@ bool AccountLoginManager::HandleLogout(const chip::Optional<chip::NodeId> & node
void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper<GetSetupPINResponse> & helper,
const CharSpan & tempAccountIdentifier)
{
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());

GetSetupPINResponse response;
ChipLogProgress(Zcl, "temporary account id: %s returning pin: %s", tempAccountIdentifierString.c_str(), mSetupPin);
Expand All @@ -144,7 +143,7 @@ void AccountLoginManager::GetSetupPin(char * setupPin, size_t setupPinSize, cons
// Other methods in this class do not need to be changed beecause those will get routed to java layer
// upstream.
ChipLogProgress(DeviceLayer, "AccountLoginManager::GetSetupPin called for endpoint %d", mEndpointId);
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
if (mCommandDelegate == nullptr)
{
// For the dummy content apps to work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "ApplicationBasicManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::ApplicationBasic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "AudioOutputManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::AudioOutput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters::ContentAppObserver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::DataModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
#include <list>
#include <string>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::DataModel;
using namespace chip::app::Clusters::ContentLauncher;
using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate;

AppContentLauncherManager::AppContentLauncherManager(ContentAppAttributeDelegate * attributeDelegate,
list<std::string> acceptHeaderList, uint32_t supportedStreamingProtocols) :
std::list<std::string> acceptHeaderList,
uint32_t supportedStreamingProtocols) :
mAttributeDelegate(attributeDelegate)
{
mAcceptHeaderList = acceptHeaderList;
Expand All @@ -46,7 +46,7 @@ void AppContentLauncherManager::HandleLaunchContent(CommandResponseHelper<Launch
bool useCurrentContext)
{
ChipLogProgress(Zcl, "AppContentLauncherManager::HandleLaunchContent for endpoint %d", mEndpointId);
string dataString(data.data(), data.size());
std::string dataString(data.data(), data.size());

ChipLogProgress(Zcl, " AutoPlay=%s", (autoplay ? "true" : "false"));

Expand Down Expand Up @@ -76,8 +76,8 @@ void AppContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchResp
{
ChipLogProgress(Zcl, "AppContentLauncherManager::HandleLaunchUrl");

string contentUrlString(contentUrl.data(), contentUrl.size());
string displayStringString(displayString.data(), displayString.size());
std::string contentUrlString(contentUrl.data(), contentUrl.size());
std::string displayStringString(displayString.data(), displayString.size());

// TODO: Insert code here
LaunchResponseType response;
Expand All @@ -100,7 +100,7 @@ CHIP_ERROR AppContentLauncherManager::HandleGetAcceptHeaderList(AttributeValueEn
Json::Value value;
if (reader.parse(resStr, value))
{
std::string attrId = to_string(chip::app::Clusters::ContentLauncher::Attributes::AcceptHeader::Id);
std::string attrId = std::to_string(chip::app::Clusters::ContentLauncher::Attributes::AcceptHeader::Id);
ChipLogProgress(Zcl, "AppContentLauncherManager::HandleGetAcceptHeaderList response parsing done. reading attr %s",
attrId.c_str());
if (value[attrId].isArray())
Expand Down Expand Up @@ -146,7 +146,7 @@ uint32_t AppContentLauncherManager::HandleGetSupportedStreamingProtocols()
{
return mSupportedStreamingProtocols;
}
std::string attrId = to_string(chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id);
std::string attrId = std::to_string(chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id);
ChipLogProgress(Zcl, "AppContentLauncherManager::HandleGetSupportedStreamingProtocols response parsing done. reading attr %s",
attrId.c_str());
if (!value[attrId].empty() && value[attrId].isInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <string>

using namespace std;
using namespace chip;
using namespace chip::app;
using namespace chip::app::DataModel;
Expand Down Expand Up @@ -204,7 +203,7 @@ uint64_t AppMediaPlaybackManager::HandleMediaRequestGetAttribute(chip::Attribute
Json::Value value;
if (reader.parse(resStr, value))
{
std::string attrId = to_string(attributeId);
std::string attrId = std::to_string(attributeId);
ChipLogProgress(Zcl, "AppMediaPlaybackManager::HandleMediaRequestGetAttribute response parsing done. reading attr %s",
attrId.c_str());
if (!value[attrId].empty() && value[attrId].isUInt())
Expand Down Expand Up @@ -250,14 +249,14 @@ CHIP_ERROR AppMediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncod
Json::Value value;
if (reader.parse(resStr, value))
{
std::string attrId = to_string(chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::Id);
std::string attrId = std::to_string(chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::Id);
ChipLogProgress(Zcl, "AppContentLauncherManager::HandleGetSampledPosition response parsing done. reading attr %s",
attrId.c_str());
if (!value[attrId].empty() && value[attrId].isObject())
{
std::string updatedAt = to_string(
std::string updatedAt = std::to_string(
static_cast<uint32_t>(chip::app::Clusters::MediaPlayback::Structs::PlaybackPositionStruct::Fields::kUpdatedAt));
std::string position = to_string(
std::string position = std::to_string(
static_cast<uint32_t>(chip::app::Clusters::MediaPlayback::Structs::PlaybackPositionStruct::Fields::kPosition));
if (!value[attrId][updatedAt].empty() && !value[attrId][position].empty() && value[attrId][updatedAt].isUInt() &&
value[attrId][position].isUInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "MessagesManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::Messages;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <list>
#include <string>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::TargetNavigator;
using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate;
Expand Down Expand Up @@ -53,16 +52,16 @@ CHIP_ERROR TargetNavigatorManager::HandleGetTargetList(AttributeValueEncoder & a
Json::Value value;
if (reader.parse(resStr, value))
{
std::string attrId = to_string(chip::app::Clusters::TargetNavigator::Attributes::TargetList::Id);
std::string attrId = std::to_string(chip::app::Clusters::TargetNavigator::Attributes::TargetList::Id);
ChipLogProgress(Zcl, "TargetNavigatorManager::HandleNavigateTarget response parsing done. reading attr %s",
attrId.c_str());
if (value[attrId].isArray())
{
return aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR {
int i = 0;
std::string targetId = to_string(static_cast<uint32_t>(
std::string targetId = std::to_string(static_cast<uint32_t>(
chip::app::Clusters::TargetNavigator::Structs::TargetInfoStruct::Fields::kIdentifier));
std::string targetName = to_string(
std::string targetName = std::to_string(
static_cast<uint32_t>(chip::app::Clusters::TargetNavigator::Structs::TargetInfoStruct::Fields::kName));
for (Json::Value & entry : value[attrId])
{
Expand Down Expand Up @@ -118,7 +117,7 @@ uint8_t TargetNavigatorManager::HandleGetCurrentTarget()
Json::Value value;
if (reader.parse(resStr, value))
{
std::string attrId = to_string(chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::Id);
std::string attrId = std::to_string(chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::Id);
ChipLogProgress(Zcl, "TargetNavigatorManager::HandleGetCurrentTarget response parsing done. reading attr %s",
attrId.c_str());
if (value[attrId].isUInt() && value[attrId].asUInt() < 256)
Expand Down
1 change: 0 additions & 1 deletion examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>

using namespace std;
using namespace chip;
using namespace chip::app::DataModel;
using namespace chip::app::Clusters::ContentLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ApplicationLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <app/CommandHandler.h>
#include <app/util/config.h>

using namespace std;
using namespace chip::app::Clusters::AccountLogin;

AccountLoginManager::AccountLoginManager(const char * setupPin)
Expand All @@ -32,8 +31,8 @@ AccountLoginManager::AccountLoginManager(const char * setupPin)
bool AccountLoginManager::HandleLogin(const CharSpan & tempAccountIdentifier, const CharSpan & setupPin,
const chip::Optional<chip::NodeId> & nodeId)
{
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
string setupPinString(setupPin.data(), setupPin.size());
std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
std::string setupPinString(setupPin.data(), setupPin.size());
ChipLogProgress(Zcl, "temporary account id: %s", tempAccountIdentifierString.c_str());
ChipLogProgress(Zcl, "setup pin %s", setupPinString.c_str());

Expand All @@ -57,7 +56,7 @@ bool AccountLoginManager::HandleLogout(const chip::Optional<chip::NodeId> & node
void AccountLoginManager::HandleGetSetupPin(CommandResponseHelper<GetSetupPINResponse> & helper,
const CharSpan & tempAccountIdentifier)
{
string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());
std::string tempAccountIdentifierString(tempAccountIdentifier.data(), tempAccountIdentifier.size());

GetSetupPINResponse response;
ChipLogProgress(Zcl, "temporary account id: %s returning pin: %s", tempAccountIdentifierString.c_str(), mSetupPin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "ApplicationBasicManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::ApplicationBasic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "ApplicationLauncherManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::ApplicationLauncher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "AudioOutputManager.h"

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters::AudioOutput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

using namespace std;
using namespace chip;
using namespace chip::app::Clusters::ContentAppObserver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app/util/config.h>

using namespace std;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::DataModel;
Expand Down
Loading

0 comments on commit 02008bc

Please sign in to comment.