Skip to content

Commit

Permalink
Remove and suppress warnings in genlib and tests (#252)
Browse files Browse the repository at this point in the history
* Squash warnings on windows

* Crank up warning level to /W4 on MSVC

* Fix w4 warnings in MSVC

* Remove some clang warnings

* Remove psubvec - only used in one place and does not add real value.

* Shut up warning about overload hiding in paftl (we know about it and the
only way to get rid of it is getting rid of paftl)

* Suppress warnings on mac as well.
  • Loading branch information
blsemo committed Oct 19, 2018
1 parent ac19a6a commit 147c56a
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 358 deletions.
6 changes: 6 additions & 0 deletions defaults.pri
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Debug:OBJECTS_DIR = debug/.obj
Debug:MOC_DIR = debug/.moc
Debug:RCC_DIR = debug/.rcc
Debug:UI_DIR = debug/.ui

win32: QMAKE_CXXFLAGS_WARN_ON -= -W3
win32: QMAKE_CXXFLAGS_WARN_ON += -W4

linux: QMAKE_CXXFLAGS_WARN_ON += -Wno-overloaded-virtual
mac: QMAKE_CXXFLAGS_WARN_ON += -Wno-overloaded-virtual
17 changes: 8 additions & 9 deletions genlib/bsptree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ void BSPTree::make(Communicator *communicator, time_t atime, const std::vector<T

int BSPTree::pickMidpointLine(const std::vector<TaggedLine> &lines, BSPNode *par) {
int chosen = -1;
size_t i;
Point2f midpoint;
for (i = 0; i < lines.size(); i++) {
for (size_t i = 0; i < lines.size(); i++) {
midpoint += lines[i].line.start() + lines[i].line.end();
}
midpoint /= 2.0 * lines.size();
Expand All @@ -89,17 +88,17 @@ int BSPTree::pickMidpointLine(const std::vector<TaggedLine> &lines, BSPNode *par
ver = false;
}
double chosendist = -1.0;
for (i = 0; i < lines.size(); i++) {
for (size_t i = 0; i < lines.size(); i++) {
const Line& line = lines[i].line;
if (ver) {
if (line.height() > line.width() && (chosen == -1 || dist(line.midpoint(),midpoint) < chosendist)) {
chosen = i;
chosen = static_cast<int>(i);
chosendist = dist(line.midpoint(),midpoint);
}
}
else {
if (line.width() > line.height() && (chosen == -1 || dist(line.midpoint(),midpoint) < chosendist)) {
chosen = i;
chosen = static_cast<int>(i);
chosendist = dist(line.midpoint(),midpoint);
}
}
Expand All @@ -108,7 +107,7 @@ int BSPTree::pickMidpointLine(const std::vector<TaggedLine> &lines, BSPNode *par
if (chosen == -1) {
for (size_t i = 0; i < lines.size(); i++) {
if (chosen == -1 || dist(lines[i].line.midpoint(),midpoint) < chosendist) {
chosen = i;
chosen = static_cast<int>(i);
chosendist = dist(lines[i].line.midpoint(),midpoint);
}
}
Expand All @@ -123,8 +122,8 @@ int BSPTree::pickMidpointLine(const std::vector<TaggedLine> &lines, BSPNode *par
* from one side of the chosen to the other are split in two and each part goes to the relevant set.
*/

std::pair<std::vector<TaggedLine>, std::vector<TaggedLine> > BSPTree::makeLines(Communicator *communicator,
time_t atime,
std::pair<std::vector<TaggedLine>, std::vector<TaggedLine> > BSPTree::makeLines(Communicator *,
time_t ,
const std::vector<TaggedLine> &lines,
BSPNode *base)
{
Expand All @@ -149,7 +148,7 @@ std::pair<std::vector<TaggedLine>, std::vector<TaggedLine> > BSPTree::makeLines(
v0.normalise();

for (size_t i = 0; i < lines.size(); i++) {
if (i == chosen) {
if (i == static_cast<unsigned int>(chosen)) {
continue;
}
const Line& testline = lines[i].line;
Expand Down
4 changes: 2 additions & 2 deletions genlib/containerutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ bool addIfNotExists(std::map<K, V> &map, const K &key, const V &value) {
}

template<typename K, typename V>
typename std::map<K, V>::const_iterator getMapAtIndex(const std::map<K, V> &m, int idx) {
typename std::map<K, V>::const_iterator getMapAtIndex(const std::map<K, V> &m, size_t idx) {
auto iter = m.begin();
std::advance(iter, idx);
return iter;
}

template<typename K, typename V>
typename std::map<K, V>::iterator getMapAtIndex(std::map<K, V> &m, int idx) {
typename std::map<K, V>::iterator getMapAtIndex(std::map<K, V> &m, size_t idx) {
auto iter = m.begin();
std::advance(iter, idx);
return iter;
Expand Down
53 changes: 25 additions & 28 deletions genlib/dxfp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ DxfLineType *DxfParser::getLineType( const std::string& line_type_name ) // con
return &(lineTypeIter->second);
}

int DxfParser::numLayers() const
size_t DxfParser::numLayers() const
{
return m_layers.size();
}

int DxfParser::numLineTypes() const
size_t DxfParser::numLineTypes() const
{
return m_line_types.size();
}
Expand All @@ -106,7 +106,7 @@ std::istream& operator >> (std::istream& stream, DxfParser& dxfp)
{
if (dxfp.m_communicator)
{
long size = dxfp.m_communicator->GetInfileSize();
long size = static_cast<long>(dxfp.m_communicator->GetInfileSize());
dxfp.m_communicator->CommPostMessage( Communicator::NUM_RECORDS, size );

qtimer( dxfp.m_time, 0 );
Expand Down Expand Up @@ -187,19 +187,16 @@ std::istream& DxfParser::open( std::istream& stream )
if (m_communicator->IsCancelled()) {
throw Communicator::CancelledException();
}
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, m_size );
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, static_cast<long>(m_size) );
}
}
}
// Get overall bounding box from layers:
bool first = true;

std::map<std::string, DxfLayer>::iterator iter = m_layers.begin(), end =
m_layers.end();
for ( ; iter != end; ++iter )
// Get overall bounding box from layers:
for ( const auto& layer : m_layers )
{
if (!iter->second.empty()) {
m_region.merge( iter->second );
if (!layer.second.empty()) {
m_region.merge( layer.second );
}
}
return stream;
Expand Down Expand Up @@ -416,7 +413,7 @@ void DxfParser::openBlocks( std::istream& stream )
if (m_communicator->IsCancelled()) {
throw Communicator::CancelledException();
}
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, m_size );
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, static_cast<long>(m_size) );
}
}
}
Expand Down Expand Up @@ -524,7 +521,7 @@ void DxfParser::openEntities( std::istream& stream, DxfToken& token, DxfBlock *b
layer = poly_line.m_p_layer;
}
layer->m_poly_lines.push_back( poly_line );
int line_count = (poly_line.getAttributes() & DxfPolyLine::CLOSED) ?
size_t line_count = (poly_line.getAttributes() & DxfPolyLine::CLOSED) ?
poly_line.numVertices() - 2 : poly_line.numVertices() - 1;
layer->merge(poly_line); // <- merge bounding box
layer->m_total_line_count += line_count;
Expand All @@ -544,7 +541,7 @@ void DxfParser::openEntities( std::istream& stream, DxfToken& token, DxfBlock *b
layer = lw_poly_line.m_p_layer;
}
layer->m_poly_lines.push_back( lw_poly_line );
int line_count = (lw_poly_line.getAttributes() & DxfPolyLine::CLOSED) ?
size_t line_count = (lw_poly_line.getAttributes() & DxfPolyLine::CLOSED) ?
lw_poly_line.numVertices() - 2 : lw_poly_line.numVertices() - 1;
layer->merge(lw_poly_line); // <- merge bounding box
layer->m_total_line_count += line_count;
Expand Down Expand Up @@ -605,7 +602,7 @@ void DxfParser::openEntities( std::istream& stream, DxfToken& token, DxfBlock *b
layer = spline.m_p_layer;
}
layer->m_splines.push_back( spline );
int line_count = (spline.getAttributes() & DxfSpline::CLOSED) ?
size_t line_count = (spline.getAttributes() & DxfSpline::CLOSED) ?
spline.numVertices() - 2 : spline.numVertices() - 1;
layer->merge(spline);
layer->m_total_line_count += line_count;
Expand Down Expand Up @@ -649,7 +646,7 @@ void DxfParser::openEntities( std::istream& stream, DxfToken& token, DxfBlock *b
if (m_communicator->IsCancelled()) {
throw Communicator::CancelledException();
}
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, m_size );
m_communicator->CommPostMessage( Communicator::CURRENT_RECORD, static_cast<long>(m_size) );
}
}
}
Expand All @@ -664,7 +661,7 @@ DxfTableRow::DxfTableRow(const std::string& name)
m_name = name;
}

bool DxfTableRow::parse( const DxfToken& token, DxfParser *parser )
bool DxfTableRow::parse( const DxfToken& token, DxfParser * )
{
bool parsed = false;

Expand Down Expand Up @@ -873,7 +870,7 @@ bool DxfPolyLine::parse( const DxfToken& token, DxfParser *parser )
return parsed;
}

int DxfPolyLine::numVertices() const
size_t DxfPolyLine::numVertices() const
{
return m_vertices.size();
}
Expand Down Expand Up @@ -1255,7 +1252,7 @@ DxfVertex DxfCircle::getVertex(int i, int segments) const
return v;
}

void DxfCircle::reflect(double x, double y)
void DxfCircle::reflect(double , double )
{
// reflect has no effect on a circle
}
Expand Down Expand Up @@ -1335,12 +1332,12 @@ bool DxfSpline::parse( const DxfToken& token, DxfParser *parser )

// Note: return control points not actual points!

int DxfSpline::numVertices() const
size_t DxfSpline::numVertices() const
{
return m_ctrl_pts.size();
}

const DxfVertex& DxfSpline::getVertex(int i) const
const DxfVertex& DxfSpline::getVertex(size_t i) const
{
return m_ctrl_pts[i];
}
Expand Down Expand Up @@ -1502,37 +1499,37 @@ const DxfSpline& DxfLayer::getSpline( int i ) const
return m_splines[i];
}

int DxfLayer::numPoints() const
size_t DxfLayer::numPoints() const
{
return m_points.size();
}

int DxfLayer::numLines() const
size_t DxfLayer::numLines() const
{
return m_lines.size();
}

int DxfLayer::numPolyLines() const
size_t DxfLayer::numPolyLines() const
{
return m_poly_lines.size();
}

int DxfLayer::numArcs() const
size_t DxfLayer::numArcs() const
{
return m_arcs.size();
}

int DxfLayer::numEllipses() const
size_t DxfLayer::numEllipses() const
{
return m_ellipses.size();
}

int DxfLayer::numCircles() const
size_t DxfLayer::numCircles() const
{
return m_circles.size();
}

int DxfLayer::numSplines() const
size_t DxfLayer::numSplines() const
{
return m_splines.size();
}
Expand Down
38 changes: 19 additions & 19 deletions genlib/dxfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const double DXF_PI = 3.1415926535897932384626433832795;
class DxfToken {
public:
int code;
int size;
size_t size;
std::string data;
//
DxfToken();
Expand Down Expand Up @@ -189,7 +189,7 @@ class DxfRegion {
void scale(const DxfVertex& base_vertex, const DxfVertex& scale)
{ m_min.scale(base_vertex, scale); m_max.scale(base_vertex, scale); }
// rotate tricky...
void rotate(const DxfVertex& base_vertex, double angle)
void rotate(const DxfVertex&, double)
{ ; }
void translate(const DxfVertex& translation)
{ m_min.translate(translation); m_max.translate(translation); }
Expand Down Expand Up @@ -242,7 +242,7 @@ class DxfPolyLine : public DxfEntity, public DxfRegion
DxfPolyLine( int tag = -1 );
void clear(); // for reuse when parsing
//
int numVertices() const;
size_t numVertices() const;
const DxfVertex& getVertex(int i) const;
int getAttributes() const;
const DxfRegion& getBoundingBox();
Expand Down Expand Up @@ -440,8 +440,8 @@ class DxfSpline : public DxfEntity, public DxfRegion
DxfSpline( int tag = -1 );
void clear(); // for reuse when parsing
//
int numVertices() const;
const DxfVertex& getVertex(int i) const;
size_t numVertices() const;
const DxfVertex& getVertex(size_t i) const;
int getAttributes() const;
//
// some basic manipulation
Expand Down Expand Up @@ -512,8 +512,8 @@ class DxfLayer : public DxfTableRow, public DxfRegion
std::vector<DxfCircle> m_circles;
std::vector<DxfSpline> m_splines;
std::vector<DxfInsert> m_inserts;
int m_total_point_count = 0;
int m_total_line_count = 0;
size_t m_total_point_count = 0;
size_t m_total_line_count = 0;
public:
DxfLayer( const std::string& name = "" );
//
Expand All @@ -525,17 +525,17 @@ class DxfLayer : public DxfTableRow, public DxfRegion
const DxfCircle& getCircle( int i ) const;
const DxfSpline& getSpline( int i ) const;
//
int numPoints() const;
int numLines() const;
int numPolyLines() const;
int numArcs() const;
int numEllipses() const;
int numCircles() const;
int numSplines() const;
size_t numPoints() const;
size_t numLines() const;
size_t numPolyLines() const;
size_t numArcs() const;
size_t numEllipses() const;
size_t numCircles() const;
size_t numSplines() const;
//
int numTotalPoints() const
size_t numTotalPoints() const
{ return m_total_point_count; }
int numTotalLines() const
size_t numTotalLines() const
{ return m_total_line_count; }
//
// this merges an insert (so the insert remains flattened)
Expand Down Expand Up @@ -579,7 +579,7 @@ class DxfParser {
std::map<std::string, DxfBlock> m_blocks;
std::map<std::string, DxfLineType> m_line_types;
//
long m_size;
size_t m_size;
Communicator *m_communicator;
public:
DxfParser(Communicator *comm = NULL);
Expand All @@ -596,8 +596,8 @@ class DxfParser {
DxfLayer *getLayer( const std::string& layer_name ); // const; <- removed as will have to add layer when DXF hasn't declared one
DxfLineType *getLineType( const std::string& line_type_name ); // const;
//
int numLayers() const;
int numLineTypes() const;
size_t numLayers() const;
size_t numLineTypes() const;
//
friend std::istream& operator >> (std::istream& stream, DxfParser& dxfp);

Expand Down
1 change: 0 additions & 1 deletion genlib/genlib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ HEADERS += \
linreg.h \
bsptree.h \
readwritehelpers.h \
psubvec.h \
pflipper.h \
simplematrix.h
Loading

0 comments on commit 147c56a

Please sign in to comment.