From 1794e5ad61fda2fbb2da17897634b1c4dfcd012a Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 9 Sep 2012 21:31:12 +0200 Subject: static code checking (fixes Bug #614227 ) (bzr r11658) --- src/libvpsc/csolve_VPSC.cpp | 119 ++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/csolve_VPSC.cpp b/src/libvpsc/csolve_VPSC.cpp index 24459d09f..4be73a19e 100644 --- a/src/libvpsc/csolve_VPSC.cpp +++ b/src/libvpsc/csolve_VPSC.cpp @@ -19,108 +19,109 @@ using namespace vpsc; extern "C" { Variable* newVariable(int id, double desiredPos, double weight) { - return new Variable(id,desiredPos,weight); + return new Variable(id,desiredPos,weight); } Constraint* newConstraint(Variable* left, Variable* right, double gap) { - return new Constraint(left,right,gap); + return new Constraint(left,right,gap); } Solver* newSolver(int n, Variable* vs[], int m, Constraint* cs[]) { - return new Solver(n,vs,m,cs); + return new Solver(n,vs,m,cs); } Solver* newIncSolver(int n, Variable* vs[], int m, Constraint* cs[]) { - return (Solver*)new vpsc::IncSolver(n,vs,m,cs); + return (Solver*)new vpsc::IncSolver(n,vs,m,cs); } int genXConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs,int transitiveClosure) { - Rectangle* rs[n]; - for(int i=0;i 0); + Rectangle* rs[n]; + for(int i=0;isatisfy(); - } catch(const char *e) { - std::cerr << e << std::endl; - exit(1); - } + try { + vpsc->satisfy(); + } catch(const char *e) { + std::cerr << e << std::endl; + exit(1); + } } int getSplitCnt(IncSolver *vpsc) { - return vpsc->splitCnt; + return vpsc->splitCnt; } void deleteVPSC(Solver *vpsc) { - assert(vpsc!=NULL); - delete vpsc; + assert(vpsc!=NULL); + delete vpsc; } void solveVPSC(Solver* vpsc) { - vpsc->solve(); + vpsc->solve(); } void splitIncVPSC(IncSolver* vpsc) { - vpsc->splitBlocks(); + vpsc->splitBlocks(); } void setVariableDesiredPos(Variable *v, double desiredPos) { - v->desiredPosition = desiredPos; + v->desiredPosition = desiredPos; } double getVariablePos(Variable *v) { - return v->position(); + return v->position(); } void remapInConstraints(Variable *u, Variable *v, double dgap) { - for(Constraints::iterator i=u->in.begin();i!=u->in.end();i++) { - Constraint* c=*i; - c->right=v; - c->gap+=dgap; - v->in.push_back(c); - } - u->in.clear(); + for(Constraints::iterator i=u->in.begin();i!=u->in.end();i++) { + Constraint* c=*i; + c->right=v; + c->gap+=dgap; + v->in.push_back(c); + } + u->in.clear(); } void remapOutConstraints(Variable *u, Variable *v, double dgap) { - for(Constraints::iterator i=u->out.begin();i!=u->out.end();i++) { - Constraint* c=*i; - c->left=v; - c->gap+=dgap; - v->out.push_back(c); - } - u->out.clear(); + for(Constraints::iterator i=u->out.begin();i!=u->out.end();i++) { + Constraint* c=*i; + c->left=v; + c->gap+=dgap; + v->out.push_back(c); + } + u->out.clear(); } int getLeftVarID(Constraint *c) { - return c->left->id; + return c->left->id; } int getRightVarID(Constraint *c){ - return c->right->id; + return c->right->id; } double getSeparation(Constraint *c){ - return c->gap; + return c->gap; } } -- cgit v1.2.3 From 9f52a01c5a908dcacbfdbaa218400b43b036ffe8 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 9 Sep 2012 21:42:05 +0200 Subject: better fix (bzr r11659) --- src/libvpsc/csolve_VPSC.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/csolve_VPSC.cpp b/src/libvpsc/csolve_VPSC.cpp index 4be73a19e..60e88a50b 100644 --- a/src/libvpsc/csolve_VPSC.cpp +++ b/src/libvpsc/csolve_VPSC.cpp @@ -8,6 +8,7 @@ * * Released under GNU LGPL. Read the file 'COPYING' for more information. */ +#include #include #include #include @@ -43,7 +44,7 @@ int genXConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs,int transit return m; } int genYConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs) { - assert(n > 0); + g_assert(n > 0); Rectangle* rs[n]; for(int i=0;i Date: Wed, 21 Nov 2012 09:55:55 +1100 Subject: code cleanup: quiet warnings with gcc. (bzr r11888) --- src/libvpsc/csolve_VPSC.h | 2 ++ src/libvpsc/generate-constraints.cpp | 6 +++--- src/libvpsc/remove_rectangle_overlap.cpp | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/csolve_VPSC.h b/src/libvpsc/csolve_VPSC.h index b0d01e763..edfd16657 100644 --- a/src/libvpsc/csolve_VPSC.h +++ b/src/libvpsc/csolve_VPSC.h @@ -60,7 +60,9 @@ int genXConstraints(int n, boxf[], Variable** vs, Constraint*** cs, int genYConstraints(int n, boxf[], Variable** vs, Constraint*** cs); void satisfyVPSC(Solver*); +void deleteVPSC(Solver*); void solveVPSC(Solver*); +void splitIncVPSC(IncSolver*); Solver* newIncSolver(int n, Variable* vs[], int m, Constraint* cs[]); void splitIncSolver(IncSolver*); int getSplitCnt(IncSolver *vpsc); diff --git a/src/libvpsc/generate-constraints.cpp b/src/libvpsc/generate-constraints.cpp index 8dd2d9331..fabe5217f 100644 --- a/src/libvpsc/generate-constraints.cpp +++ b/src/libvpsc/generate-constraints.cpp @@ -105,7 +105,7 @@ bool CmpNodePos::operator() (const Node* u, const Node* v) const { */ } -NodeSet* getLeftNeighbours(NodeSet &scanline,Node *v) { +static NodeSet* getLeftNeighbours(NodeSet &scanline,Node *v) { NodeSet *leftv = new NodeSet; NodeSet::iterator i=scanline.find(v); while(i--!=scanline.begin()) { @@ -120,7 +120,7 @@ NodeSet* getLeftNeighbours(NodeSet &scanline,Node *v) { } return leftv; } -NodeSet* getRightNeighbours(NodeSet &scanline,Node *v) { +static NodeSet* getRightNeighbours(NodeSet &scanline,Node *v) { NodeSet *rightv = new NodeSet; NodeSet::iterator i=scanline.find(v); for(++i;i!=scanline.end(); ++i) { @@ -144,7 +144,7 @@ struct Event { Event(EventType t, Node *v, double p) : type(t),v(v),pos(p) {}; }; Event **events; -int compare_events(const void *a, const void *b) { +static int compare_events(const void *a, const void *b) { Event *ea=*(Event**)a; Event *eb=*(Event**)b; if(ea->v->r==eb->v->r) { diff --git a/src/libvpsc/remove_rectangle_overlap.cpp b/src/libvpsc/remove_rectangle_overlap.cpp index 381759f3c..d667ffb1e 100644 --- a/src/libvpsc/remove_rectangle_overlap.cpp +++ b/src/libvpsc/remove_rectangle_overlap.cpp @@ -15,6 +15,7 @@ #include "solve_VPSC.h" #include "variable.h" #include "constraint.h" +#include "remove_rectangle_overlap.h" /* own include */ #ifdef RECTANGLE_OVERLAP_LOGGING #include #include "blocks.h" -- cgit v1.2.3 From af8374a9745905bde55e5b19425bf95b2fd3f935 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 16 Oct 2013 21:47:12 +0200 Subject: static code analysis: performance (bzr r12695) --- src/libvpsc/constraint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/constraint.cpp b/src/libvpsc/constraint.cpp index 2bd173155..0ec06dfac 100644 --- a/src/libvpsc/constraint.cpp +++ b/src/libvpsc/constraint.cpp @@ -24,11 +24,11 @@ Constraint::Constraint(Variable *left, Variable *right, double gap, bool equalit } Constraint::~Constraint() { Constraints::iterator i; - for(i=left->out.begin(); i!=left->out.end(); i++) { + for(i=left->out.begin(); i!=left->out.end(); ++i) { if(*i==this) break; } left->out.erase(i); - for(i=right->in.begin(); i!=right->in.end(); i++) { + for(i=right->in.begin(); i!=right->in.end(); ++i) { if(*i==this) break; } right->in.erase(i); -- cgit v1.2.3 From 2a512b54b57ae53464601b38b05eab6f6c3cf3c4 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 22 Oct 2013 16:50:54 +0200 Subject: cppcheck (bzr r12713) --- src/libvpsc/solve_VPSC.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/solve_VPSC.cpp b/src/libvpsc/solve_VPSC.cpp index f9bed649c..83cb517b6 100644 --- a/src/libvpsc/solve_VPSC.cpp +++ b/src/libvpsc/solve_VPSC.cpp @@ -301,16 +301,16 @@ bool Solver::constraintGraphIsCyclic(const unsigned n, Variable* const vs[]) { varmap[vs[i]]->out.insert(varmap[r]); } } - while(graph.size()>0) { + while(!graph.empty()) { node *u=NULL; vector::iterator i=graph.begin(); for(;i!=graph.end();++i) { u=*i; - if(u->in.size()==0) { + if(u->in.empty()) { break; } } - if(i==graph.end() && graph.size()>0) { + if(i==graph.end() && !graph.empty()) { //cycle found! return true; } else { @@ -358,16 +358,16 @@ bool Solver::blockGraphIsCyclic() { c=b->findMinOutConstraint(); } } - while(graph.size()>0) { + while(!graph.empty()) { node *u=NULL; vector::iterator i=graph.begin(); for(;i!=graph.end();++i) { u=*i; - if(u->in.size()==0) { + if(u->in.empty()) { break; } } - if(i==graph.end() && graph.size()>0) { + if(i==graph.end() && !graph.empty()) { //cycle found! return true; } else { -- cgit v1.2.3 From b7b45eae8e4b5489a6342060782f7f2f82c1c500 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 8 Mar 2014 14:00:45 -0500 Subject: Remove useless r variable and warning (bzr r13130) --- src/libvpsc/generate-constraints.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/libvpsc') diff --git a/src/libvpsc/generate-constraints.cpp b/src/libvpsc/generate-constraints.cpp index fabe5217f..288e7ed53 100644 --- a/src/libvpsc/generate-constraints.cpp +++ b/src/libvpsc/generate-constraints.cpp @@ -209,7 +209,6 @@ int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constrain } } else { // Close event - int r; if(useNeighbourLists) { for(NodeSet::iterator i=v->leftNeighbours->begin(); i!=v->leftNeighbours->end();i++ @@ -217,7 +216,7 @@ int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constrain Node *u=*i; double sep = (v->r->width()+u->r->width())/2.0; constraints.push_back(new Constraint(u->v,v->v,sep)); - r=u->rightNeighbours->erase(v); + u->rightNeighbours->erase(v); } for(NodeSet::iterator i=v->rightNeighbours->begin(); @@ -226,22 +225,22 @@ int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constrain Node *u=*i; double sep = (v->r->width()+u->r->width())/2.0; constraints.push_back(new Constraint(v->v,u->v,sep)); - r=u->leftNeighbours->erase(v); + u->leftNeighbours->erase(v); } } else { Node *l=v->firstAbove, *r=v->firstBelow; if(l!=NULL) { double sep = (v->r->width()+l->r->width())/2.0; constraints.push_back(new Constraint(l->v,v->v,sep)); - l->firstBelow=v->firstBelow; + l->firstBelow = v->firstBelow; } if(r!=NULL) { double sep = (v->r->width()+r->r->width())/2.0; constraints.push_back(new Constraint(v->v,r->v,sep)); - r->firstAbove=v->firstAbove; + r->firstAbove = v->firstAbove; } } - r=scanline.erase(v); + scanline.erase(v); delete v; } delete e; -- cgit v1.2.3 From 3a4bbd50a7b0f06b8bb126db2af10782d91eda28 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 23 Mar 2014 18:59:12 +0100 Subject: remove files that interface through C with libvpsc, we are using C++ so... (bzr r13191) --- src/libvpsc/CMakeLists.txt | 2 - src/libvpsc/Makefile_insert | 2 - src/libvpsc/csolve_VPSC.cpp | 128 -------------------------------------------- src/libvpsc/csolve_VPSC.h | 72 ------------------------- 4 files changed, 204 deletions(-) delete mode 100644 src/libvpsc/csolve_VPSC.cpp delete mode 100644 src/libvpsc/csolve_VPSC.h (limited to 'src/libvpsc') diff --git a/src/libvpsc/CMakeLists.txt b/src/libvpsc/CMakeLists.txt index 4099900b5..aa693670c 100644 --- a/src/libvpsc/CMakeLists.txt +++ b/src/libvpsc/CMakeLists.txt @@ -3,7 +3,6 @@ set(libvpsc_SRC block.cpp blocks.cpp constraint.cpp - csolve_VPSC.cpp generate-constraints.cpp remove_rectangle_overlap.cpp solve_VPSC.cpp @@ -16,7 +15,6 @@ set(libvpsc_SRC block.h blocks.h constraint.h - csolve_VPSC.h generate-constraints.h pairingheap/PairingHeap.h pairingheap/dsexceptions.h diff --git a/src/libvpsc/Makefile_insert b/src/libvpsc/Makefile_insert index 4af86324e..cb05be6c0 100644 --- a/src/libvpsc/Makefile_insert +++ b/src/libvpsc/Makefile_insert @@ -11,7 +11,6 @@ libvpsc_libvpsc_a_SOURCES = libvpsc/block.cpp\ libvpsc/pairingheap/PairingHeap.cpp\ libvpsc/remove_rectangle_overlap.cpp\ libvpsc/solve_VPSC.cpp\ - libvpsc/csolve_VPSC.cpp\ libvpsc/variable.cpp\ libvpsc/block.h\ libvpsc/blocks.h\ @@ -21,5 +20,4 @@ libvpsc_libvpsc_a_SOURCES = libvpsc/block.cpp\ libvpsc/pairingheap/dsexceptions.h\ libvpsc/remove_rectangle_overlap.h\ libvpsc/solve_VPSC.h\ - libvpsc/csolve_VPSC.h\ libvpsc/variable.h diff --git a/src/libvpsc/csolve_VPSC.cpp b/src/libvpsc/csolve_VPSC.cpp deleted file mode 100644 index 60e88a50b..000000000 --- a/src/libvpsc/csolve_VPSC.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Bridge for C programs to access solve_VPSC (which is in C++). - * - * Authors: - * Tim Dwyer - * - * Copyright (C) 2005 Authors - * - * Released under GNU LGPL. Read the file 'COPYING' for more information. - */ -#include -#include -#include -#include -#include "variable.h" -#include "constraint.h" -#include "generate-constraints.h" -#include "solve_VPSC.h" -#include "csolve_VPSC.h" -using namespace vpsc; -extern "C" { -Variable* newVariable(int id, double desiredPos, double weight) { - return new Variable(id,desiredPos,weight); -} -Constraint* newConstraint(Variable* left, Variable* right, double gap) { - return new Constraint(left,right,gap); -} -Solver* newSolver(int n, Variable* vs[], int m, Constraint* cs[]) { - return new Solver(n,vs,m,cs); -} -Solver* newIncSolver(int n, Variable* vs[], int m, Constraint* cs[]) { - return (Solver*)new vpsc::IncSolver(n,vs,m,cs); -} - -int genXConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs,int transitiveClosure) { - Rectangle* rs[n]; - for(int i=0;i 0); - Rectangle* rs[n]; - for(int i=0;isatisfy(); - } catch(const char *e) { - std::cerr << e << std::endl; - exit(1); - } -} -int getSplitCnt(IncSolver *vpsc) { - return vpsc->splitCnt; -} -void deleteVPSC(Solver *vpsc) { - assert(vpsc!=NULL); - delete vpsc; -} -void solveVPSC(Solver* vpsc) { - vpsc->solve(); -} -void splitIncVPSC(IncSolver* vpsc) { - vpsc->splitBlocks(); -} -void setVariableDesiredPos(Variable *v, double desiredPos) { - v->desiredPosition = desiredPos; -} -double getVariablePos(Variable *v) { - return v->position(); -} -void remapInConstraints(Variable *u, Variable *v, double dgap) { - for(Constraints::iterator i=u->in.begin();i!=u->in.end();i++) { - Constraint* c=*i; - c->right=v; - c->gap+=dgap; - v->in.push_back(c); - } - u->in.clear(); -} -void remapOutConstraints(Variable *u, Variable *v, double dgap) { - for(Constraints::iterator i=u->out.begin();i!=u->out.end();i++) { - Constraint* c=*i; - c->left=v; - c->gap+=dgap; - v->out.push_back(c); - } - u->out.clear(); -} -int getLeftVarID(Constraint *c) { - return c->left->id; -} -int getRightVarID(Constraint *c){ - return c->right->id; -} -double getSeparation(Constraint *c){ - return c->gap; -} -} diff --git a/src/libvpsc/csolve_VPSC.h b/src/libvpsc/csolve_VPSC.h deleted file mode 100644 index edfd16657..000000000 --- a/src/libvpsc/csolve_VPSC.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @file - * Bridge for C programs to access solve_VPSC (which is in C++). - */ -/* - * Authors: - * Tim Dwyer - * - * Copyright (C) 2005 Authors - * - * Released under GNU LGPL. Read the file 'COPYING' for more information. - */ -#ifndef CSOLVE_VPSC_H_ -#define CSOLVE_VPSC_H_ -#ifdef __cplusplus -namespace vpsc -{ - class Variable; - class Constraint; - class Solver; - class IncSolver; -} -/* TODO 'using' should never be in a .h file. We need a different approach here. */ -using vpsc::Variable; -using vpsc::Constraint; -using vpsc::Solver; -using vpsc::IncSolver; -extern "C" { -#else -typedef struct Variable Variable; -typedef struct Constraint Constraint; -typedef struct Solver Solver; -typedef struct IncSolver IncSolver; -#endif - -Variable* newVariable(int id, double desiredPos, double weight); -void setVariableDesiredPos(Variable *, double desiredPos); -double getVariablePos(Variable*); - -Constraint* newConstraint(Variable* left, Variable* right, double gap); - -Solver* newSolver(int n, Variable* vs[], int m, Constraint* cs[]); -void deleteSolver(Solver*); -void deleteConstraint(Constraint*); -void deleteVariable(Variable*); -Constraint** newConstraints(int m); -void deleteConstraints(int m,Constraint**); -void remapInConstraints(Variable *u, Variable *v, double dgap); -void remapOutConstraints(Variable *u, Variable *v, double dgap); -int getLeftVarID(Constraint *c); -int getRightVarID(Constraint *c); -double getSeparation(Constraint *c); - -#ifndef HAVE_POINTF_S -typedef struct pointf_s { double x, y; } pointf; -typedef struct { pointf LL, UR; } boxf; -#endif -int genXConstraints(int n, boxf[], Variable** vs, Constraint*** cs, - int transitiveClosure); -int genYConstraints(int n, boxf[], Variable** vs, Constraint*** cs); - -void satisfyVPSC(Solver*); -void deleteVPSC(Solver*); -void solveVPSC(Solver*); -void splitIncVPSC(IncSolver*); -Solver* newIncSolver(int n, Variable* vs[], int m, Constraint* cs[]); -void splitIncSolver(IncSolver*); -int getSplitCnt(IncSolver *vpsc); -#ifdef __cplusplus -} -#endif -#endif /* CSOLVE_VPSC_H_ */ -- cgit v1.2.3