Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -54,10 +54,11 @@ wpi::StringRef SourceImpl::GetDescription(
void SourceImpl::SetConnected(bool connected) {
bool wasConnected = m_connected.exchange(connected);
if (wasConnected && !connected)
if (wasConnected && !connected) {
m_notifier.NotifySource(*this, CS_SOURCE_DISCONNECTED);
else if (!wasConnected && connected)
} else if (!wasConnected && connected) {
m_notifier.NotifySource(*this, CS_SOURCE_CONNECTED);
}
}
uint64_t SourceImpl::GetCurFrameTime() {
@@ -130,7 +131,9 @@ void SourceImpl::SetExposureManual(int value, CS_Status* status) {
}
VideoMode SourceImpl::GetVideoMode(CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return VideoMode{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
return m_mode;
}
@@ -138,14 +141,18 @@ VideoMode SourceImpl::GetVideoMode(CS_Status* status) const {
bool SourceImpl::SetPixelFormat(VideoMode::PixelFormat pixelFormat,
CS_Status* status) {
auto mode = GetVideoMode(status);
if (!mode) return false;
if (!mode) {
return false;
}
mode.pixelFormat = pixelFormat;
return SetVideoMode(mode, status);
}
bool SourceImpl::SetResolution(int width, int height, CS_Status* status) {
auto mode = GetVideoMode(status);
if (!mode) return false;
if (!mode) {
return false;
}
mode.width = width;
mode.height = height;
return SetVideoMode(mode, status);
@@ -153,7 +160,9 @@ bool SourceImpl::SetResolution(int width, int height, CS_Status* status) {
bool SourceImpl::SetFPS(int fps, CS_Status* status) {
auto mode = GetVideoMode(status);
if (!mode) return false;
if (!mode) {
return false;
}
mode.fps = fps;
return SetVideoMode(mode, status);
}
@@ -315,8 +324,9 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
}
// properties
if (config.count("properties") != 0)
if (config.count("properties") != 0) {
SetPropertiesJson(config.at("properties"), m_logger, GetName(), status);
}
return true;
}
@@ -353,30 +363,41 @@ wpi::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
default:
break;
}
if (!pixelFormat.empty()) j.emplace("pixel format", pixelFormat);
if (!pixelFormat.empty()) {
j.emplace("pixel format", pixelFormat);
}
// width
if (m_mode.width != 0) j.emplace("width", m_mode.width);
if (m_mode.width != 0) {
j.emplace("width", m_mode.width);
}
// height
if (m_mode.height != 0) j.emplace("height", m_mode.height);
if (m_mode.height != 0) {
j.emplace("height", m_mode.height);
}
// fps
if (m_mode.fps != 0) j.emplace("fps", m_mode.fps);
if (m_mode.fps != 0) {
j.emplace("fps", m_mode.fps);
}
// TODO: output brightness, white balance, and exposure?
// properties
wpi::json props = GetPropertiesJsonObject(status);
if (props.is_array()) j.emplace("properties", props);
if (props.is_array()) {
j.emplace("properties", props);
}
return j;
}
std::vector<VideoMode> SourceImpl::EnumerateVideoModes(
CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return std::vector<VideoMode>{};
if (!m_properties_cached && !CacheProperties(status)) {
return {};
}
std::scoped_lock lock(m_mutex);
return m_videoModes;
}
@@ -401,10 +422,11 @@ std::unique_ptr<Image> SourceImpl::AllocImage(
}
// if nothing found, allocate a new buffer
if (found < 0)
if (found < 0) {
image.reset(new Image{size});
else
} else {
image = std::move(m_imagesAvail[found]);
}
}
// Initialize image
@@ -461,21 +483,25 @@ void SourceImpl::NotifyPropertyCreated(int propIndex, PropertyImpl& prop) {
propIndex, prop.propKind, prop.value,
prop.valueStr);
// also notify choices updated event for enum types
if (prop.propKind == CS_PROP_ENUM)
if (prop.propKind == CS_PROP_ENUM) {
m_notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CHOICES_UPDATED,
prop.name, propIndex, prop.propKind,
prop.value, wpi::Twine{});
}
}
void SourceImpl::UpdatePropertyValue(int property, bool setString, int value,
const wpi::Twine& valueStr) {
auto prop = GetProperty(property);
if (!prop) return;
if (!prop) {
return;
}
if (setString)
if (setString) {
prop->SetValue(valueStr);
else
} else {
prop->SetValue(value);
}
// Only notify updates after we've notified created
if (m_properties_cached) {
@@ -487,7 +513,9 @@ void SourceImpl::UpdatePropertyValue(int property, bool setString, int value,
void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
std::scoped_lock lock{m_poolMutex};
if (m_destroyFrames) return;
if (m_destroyFrames) {
return;
}
// Return the frame to the pool. First try to find an empty slot, otherwise
// add it to the end.
auto it = std::find(m_imagesAvail.begin(), m_imagesAvail.end(), nullptr);
@@ -501,7 +529,9 @@ void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
[](const std::unique_ptr<Image>& a, const std::unique_ptr<Image>& b) {
return a->capacity() < b->capacity();
});
if ((*it2)->capacity() < image->capacity()) *it2 = std::move(image);
if ((*it2)->capacity() < image->capacity()) {
*it2 = std::move(image);
}
} else {
m_imagesAvail.emplace_back(std::move(image));
}
@@ -510,7 +540,9 @@ void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
std::scoped_lock lock{m_poolMutex};
if (m_framesAvail.empty()) return std::make_unique<Frame::Impl>(*this);
if (m_framesAvail.empty()) {
return std::make_unique<Frame::Impl>(*this);
}
auto impl = std::move(m_framesAvail.back());
m_framesAvail.pop_back();
@@ -519,6 +551,8 @@ std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
void SourceImpl::ReleaseFrameImpl(std::unique_ptr<Frame::Impl> impl) {
std::scoped_lock lock{m_poolMutex};
if (m_destroyFrames) return;
if (m_destroyFrames) {
return;
}
m_framesAvail.push_back(std::move(impl));
}