Skip to content

Commit

Permalink
Fixed|Clang: Compiler warnings and errors
Browse files Browse the repository at this point in the history
Resolved ambiguous constructors wrt. char const *, QString, String,
Path, and Uri.

Added C++ constructor for ColorRawf.

Fixed a case of passing an r-value as a non-const reference.
  • Loading branch information
skyjake committed Nov 28, 2012
1 parent f6e5899 commit 2182dae
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 8 deletions.
4 changes: 4 additions & 0 deletions doomsday/engine/include/color.h
Expand Up @@ -49,6 +49,10 @@ typedef struct ColorRawf_s {
float _alpha;
};
};
#ifdef __cplusplus
ColorRawf_s(float r = 0.f, float g = 0.f, float b = 0.f, float a = 0.f)
: red(r), green(g), blue(b), _alpha(a) {}
#endif
} ColorRawf;

float ColorRawf_AverageColor(ColorRawf* color);
Expand Down
9 changes: 9 additions & 0 deletions doomsday/engine/include/uri.hh
Expand Up @@ -110,6 +110,15 @@ public:
*/
Uri(Path const &path);

/**
* Construct a Uri instance from a UTF-8 C-style text string, using RC_UNKNOWN
* as the default resource class.
*
* @param nullTerminatedCStr String to be parsed. Assumed to be in
* percent-encoded representation.
*/
Uri(char const* nullTerminatedCStr);

/**
* Construct a Uri instance by duplicating @a other.
*/
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/gl/gl_texmanager.cpp
Expand Up @@ -138,7 +138,7 @@ static GraphicFileType const graphicTypes[] = {
{ "JPG", "jpg", interpretJpg, 0 }, // TODO: add alternate "jpeg" extension
{ "TGA", "tga", interpretTga, TGA_LastError },
{ "PCX", "pcx", interpretPcx, PCX_LastError },
{ 0 } // Terminate.
{ 0, 0, 0, 0 } // Terminate.
};

static variantspecificationlist_t *variantSpecs;
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/src/render/r_draw.cpp
Expand Up @@ -25,6 +25,7 @@
#include "de_graphics.h"
#include "de_play.h"

#include "render/r_draw.h"
#include "gl/sys_opengl.h"
#include "resource/texture.h"
#include "resource/texturevariant.h"
Expand Down
9 changes: 5 additions & 4 deletions doomsday/engine/src/render/sky.cpp
Expand Up @@ -182,9 +182,9 @@ materialvariantspecification_t const *Sky_SphereMaterialSpec(bool masked)

static void calculateSkyAmbientColor()
{
ColorRawf avgMaterialColor = { 0, 0, 0, 0 };
ColorRawf bottomCapColor = { 0, 0, 0, 0 };
ColorRawf topCapColor = { 0, 0, 0, 0 };
ColorRawf avgMaterialColor;
ColorRawf bottomCapColor;
ColorRawf topCapColor;
skylayer_t *slayer;
int i, avgCount;

Expand Down Expand Up @@ -391,7 +391,8 @@ int Sky_FirstActiveLayer()

ColorRawf const *Sky_AmbientColor()
{
static ColorRawf const white = { 1.0f, 1.0f, 1.0f, 0 };
static ColorRawf const white(1.0f, 1.0f, 1.0f, 0);

if(skyAmbientColorDefined || rendSkyLightAuto)
{
if(!skyAmbientColorDefined)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/resource/r_data.cpp
Expand Up @@ -363,7 +363,7 @@ static CompositeTextures readCompositeTextureDefs(IByteArray &data,

// Ensure the offset is within valid range.
if(offset < 0 || (unsigned) offset < definitionCount * sizeof(offset) ||
offset > reader.source()->size())
(dsize) offset > reader.source()->size())
{
LOG_WARNING("Invalid offset %i for definition #%i, ignoring.") << offset << i;
}
Expand Down Expand Up @@ -557,7 +557,7 @@ static CompositeTextures loadCompositeTextureDefs()
/**
* @param defs Definitions to be processed.
*/
static void processCompositeTextureDefs(CompositeTextures &defs)
static void processCompositeTextureDefs(CompositeTextures defs)
{
LOG_AS("processCompositeTextureDefs");
bool isFirst = true;
Expand Down
5 changes: 5 additions & 0 deletions doomsday/engine/src/uri.cpp
Expand Up @@ -246,6 +246,11 @@ Uri::Uri(Path const &path) : d(new Instance)
setPath(path);
}

Uri::Uri(char const *nullTerminatedCStr) : d(new Instance)
{
setUri(nullTerminatedCStr);
}

Uri::Uri(Uri const &other) : LogEntry::Arg::Base(), d(new Instance(*other.d))
{}

Expand Down
32 changes: 32 additions & 0 deletions doomsday/libdeng2/include/de/data/path.h
Expand Up @@ -145,6 +145,13 @@ class DENG2_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base
*/
Path(String const &path, QChar sep = '/');

/**
* Construct a path from @a str with '/' as the segment separator.
*
* @param str String.
*/
Path(QString const &str);

/**
* Construct a path from a UTF-8 C-style string.
*
Expand All @@ -153,6 +160,13 @@ class DENG2_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base
*/
Path(char const *nullTerminatedCStr, char sep);

/**
* Construct a path from a UTF-8 C-style string that uses '/' separators.
*
* @param nullTerminatedCStr Path to be parsed. All white space is included in the path.
*/
Path(char const *nullTerminatedCStr);

/**
* Construct a path by duplicating @a other.
*/
Expand All @@ -165,6 +179,24 @@ class DENG2_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base
return *this;
}

/**
* Append a string.
*
* @param str String.
*
* @return Path with @a str added to the end.
*
* @note This is a plain string append, not a path concatenation: use the /
* operator for concatenating paths in a way that takes care of separators
* and path relativity.
*/
Path operator + (QString const &str) const;

/**
* @copydoc operator+
*/
Path operator + (char const *nullTerminatedCStr) const;

/**
* Swaps this Path with @a other.
* @param other Path.
Expand Down
21 changes: 20 additions & 1 deletion doomsday/libdeng2/src/data/path.cpp
Expand Up @@ -244,10 +244,19 @@ Path::Path(String const &path, QChar sep)
: LogEntry::Arg::Base(), d(new Instance(path, sep))
{}

Path::Path(const QString &str)
: LogEntry::Arg::Base(), d(new Instance(str, '/'))
{}

Path::Path(char const *nullTerminatedCStr, char sep)
: LogEntry::Arg::Base(), d(new Instance(QString::fromUtf8(nullTerminatedCStr), sep))
{}

Path::Path(const char *nullTerminatedCStr)
: LogEntry::Arg::Base(), d(new Instance(QString::fromUtf8(nullTerminatedCStr), '/'))
{
}

Path::Path(Path const &other)
: ISerializable(), LogEntry::Arg::Base(),
d(new Instance(other.d->path, other.d->separator))
Expand All @@ -258,6 +267,16 @@ Path::~Path()
delete d;
}

Path Path::operator + (QString const &str) const
{
return Path(d->path + str, d->separator);
}

Path Path::operator + (const char *nullTerminatedCStr) const
{
return Path(d->path + QString(nullTerminatedCStr), d->separator);
}

int Path::segmentCount() const
{
d->parse();
Expand Down Expand Up @@ -327,7 +346,7 @@ Path Path::operator / (QString other) const

Path Path::operator / (char const *otherNullTerminatedUtf8) const
{
return *this / Path(otherNullTerminatedUtf8);
return *this / Path(otherNullTerminatedUtf8, '/');
}

String Path::toString() const
Expand Down

0 comments on commit 2182dae

Please sign in to comment.