Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GSG violations on non-trivially destructible types #1264

Merged
merged 16 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/sdf/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace sdf

/// \enum ParticleEmitterType
/// \brief The set of particle emitter types.
// Developer note: Make sure to update emitterTypeStrs in the source
// Developer note: Make sure to update kEmitterTypeStrs in the source
// file when changing this enum.
enum class ParticleEmitterType
{
Expand Down
2 changes: 1 addition & 1 deletion include/sdf/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace sdf

/// \enum SensorType
/// \brief The set of sensor types.
// Developer note: Make sure to update sensorTypeStrs in the source file
// Developer note: Make sure to update kSensorTypeStrs in the source file
// when changing this enum.
enum class SensorType
{
Expand Down
8 changes: 7 additions & 1 deletion include/sdf/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <utility>
#include <vector>

#include <gz/utils/NeverDestroyed.hh>
#include <sdf/sdf_config.h>
#include "sdf/system_util.hh"
#include "sdf/Error.hh"
Expand All @@ -35,7 +36,12 @@ namespace sdf
inline namespace SDF_VERSION_NAMESPACE {
//

const std::string kSdfScopeDelimiter = "::";
static const std::string &SdfScopeDelimiter()
aaronchongth marked this conversation as resolved.
Show resolved Hide resolved
{
static const gz::utils::NeverDestroyed<std::string> delimiter{"::"};
return delimiter.Access();
}
static const std::string &kSdfScopeDelimiter = SdfScopeDelimiter();

/// \brief The source path replacement if it was parsed from a string,
/// instead of a file.
Expand Down
7 changes: 4 additions & 3 deletions src/Camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/
#include <array>

#include "sdf/Camera.hh"
#include "sdf/parser.hh"
#include "Utils.hh"
Expand All @@ -23,7 +24,7 @@ using namespace sdf;

/// \brief String names for the pixel formats.
/// \sa Image::PixelFormat.
static std::array<std::string, 19> kPixelFormatNames =
static const std::array<const char *, 19> kPixelFormatNames =
azeey marked this conversation as resolved.
Show resolved Hide resolved
{
"UNKNOWN_PIXEL_FORMAT",
"L_INT8",
Expand Down Expand Up @@ -1146,9 +1147,9 @@ std::string Camera::ConvertPixelFormat(PixelFormatType _type)
{
unsigned int index = static_cast<int>(_type);
if (index < kPixelFormatNames.size())
return kPixelFormatNames[static_cast<int>(_type)];
return std::string(kPixelFormatNames[static_cast<int>(_type)]);

return kPixelFormatNames[0];
return std::string(kPixelFormatNames[0]);
}

/////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DirIter::Implementation

#ifndef _WIN32

static const char preferred_separator = '/';
static const char kSdfFileSystemPreferredSeparator = '/';

//////////////////////////////////////////////////
bool exists(const std::string &_path)
Expand Down Expand Up @@ -210,7 +210,7 @@ void DirIter::close_handle()

#else // Windows

static const char preferred_separator = '\\';
static const char kSdfFileSystemPreferredSeparator = '\\';

//////////////////////////////////////////////////
static bool not_found_error(int _errval)
Expand Down Expand Up @@ -496,7 +496,7 @@ void DirIter::close_handle()
//////////////////////////////////////////////////
const std::string separator(const std::string &_p)
{
return _p + preferred_separator;
return _p + kSdfFileSystemPreferredSeparator;
}

//////////////////////////////////////////////////
Expand All @@ -509,7 +509,7 @@ std::string basename(const std::string &_path)

for (size_t i = 0; i < _path.length(); ++i)
{
if (_path[i] == preferred_separator)
if (_path[i] == kSdfFileSystemPreferredSeparator)
{
if (i == (_path.length() - 1))
{
Expand All @@ -519,7 +519,7 @@ std::string basename(const std::string &_path)
// basename is empty, we return just a "/".
if (basename.size() == 0)
{
basename.push_back(preferred_separator);
basename.push_back(kSdfFileSystemPreferredSeparator);
}
break;
}
Expand Down Expand Up @@ -556,7 +556,7 @@ DirIter::DirIter() : dataPtr(gz::utils::MakeUniqueImpl<Implementation>())
//////////////////////////////////////////////////
std::string DirIter::operator*() const
{
return this->dataPtr->dirname + preferred_separator +
return this->dataPtr->dirname + kSdfFileSystemPreferredSeparator +
this->dataPtr->current;
}

Expand Down
16 changes: 9 additions & 7 deletions src/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*
*/
#include <array>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <string_view>

#include "sdf/Error.hh"
#include "sdf/parser.hh"
Expand All @@ -31,8 +32,9 @@
using namespace sdf;

/// Particle emitter type strings. These should match the data in
/// `enum class ParticleEmitterType` located in ParticleEmitter.hh.
const std::vector<std::string> emitterTypeStrs =
/// `enum class ParticleEmitterType` located in ParticleEmitter.hh, and the size
/// template parameter should match the number of elements as well.
constexpr std::array<const std::string_view, 4> kEmitterTypeStrs =
{
"point",
"box",
Expand Down Expand Up @@ -250,9 +252,9 @@ void ParticleEmitter::SetType(const ParticleEmitterType _type)
/////////////////////////////////////////////////
bool ParticleEmitter::SetType(const std::string &_typeStr)
{
for (size_t i = 0; i < emitterTypeStrs.size(); ++i)
for (size_t i = 0; i < kEmitterTypeStrs.size(); ++i)
{
if (_typeStr == emitterTypeStrs[i])
if (_typeStr == kEmitterTypeStrs[i])
{
this->dataPtr->type = static_cast<ParticleEmitterType>(i);
return true;
Expand All @@ -265,8 +267,8 @@ bool ParticleEmitter::SetType(const std::string &_typeStr)
std::string ParticleEmitter::TypeStr() const
{
size_t index = static_cast<int>(this->dataPtr->type);
if (index < emitterTypeStrs.size())
return emitterTypeStrs[index];
if (index < kEmitterTypeStrs.size())
return std::string(kEmitterTypeStrs[index]);
return "point";
}

Expand Down
14 changes: 8 additions & 6 deletions src/Sensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
#include <array>
#include <memory>
#include <string>
#include <optional>
Expand All @@ -39,8 +40,9 @@
using namespace sdf;

/// Sensor type strings. These should match the data in
/// `enum class SensorType` located in Sensor.hh.
const std::vector<std::string> sensorTypeStrs =
/// `enum class SensorType` located in Sensor.hh, and the size template
/// parameter should match the number of elements as well.
static const std::array<const char *, 27> kSensorTypeStrs =
{
"none",
"altimeter",
Expand Down Expand Up @@ -528,9 +530,9 @@ void Sensor::SetType(const SensorType _type)
/////////////////////////////////////////////////
bool Sensor::SetType(const std::string &_typeStr)
{
for (size_t i = 0; i < sensorTypeStrs.size(); ++i)
for (size_t i = 0; i < kSensorTypeStrs.size(); ++i)
{
if (_typeStr == sensorTypeStrs[i])
if (_typeStr == kSensorTypeStrs[i])
{
this->dataPtr->type = static_cast<SensorType>(i);
return true;
Expand Down Expand Up @@ -645,8 +647,8 @@ void Sensor::SetUpdateRate(double _hz)
std::string Sensor::TypeStr() const
{
size_t index = static_cast<int>(this->dataPtr->type);
if (index > 0 && index < sensorTypeStrs.size())
return sensorTypeStrs[index];
if (index > 0 && index < kSensorTypeStrs.size())
return std::string(kSensorTypeStrs[index]);
return "none";
}

Expand Down