* Adaptagrams repository.
*/
#include <cassert>
+#include <memory>
#include <vpsc/pairingheap/PairingHeap.h>
#include <vpsc/constraint.h>
#include <vpsc/block.h>
Block::Block(Variable *v) {
timeStamp=0;
posn=weight=wposn=0;
- in=nullptr;
- out=nullptr;
deleted=false;
if(v!=nullptr) {
v->offset=0;
}
return wp;
}
-Block::~Block()
-{
- delete in;
- delete out;
-}
void Block::setUpInConstraints() {
setUpConstraintHeap(in,true);
}
void Block::setUpOutConstraints() {
setUpConstraintHeap(out,false);
}
-void Block::setUpConstraintHeap(PairingHeap<Constraint*>* &h,bool in) {
- delete h;
- h = new PairingHeap<Constraint*>(&compareConstraints);
+void Block::setUpConstraintHeap(std::unique_ptr<PairingHeap<Constraint*>> &h,
+ bool in) {
+ h = std::unique_ptr<PairingHeap<Constraint*>>(
+ new PairingHeap<Constraint*>(&compareConstraints));
for (Variable *v : vars) {
vector<Constraint*> *cs=in?&(v->in):&(v->out);
for (vector<Constraint*>::iterator j=cs->begin();j!=cs->end();j++) {
// We check the top of the heaps to remove possible internal constraints
findMinInConstraint();
b->findMinInConstraint();
- in->merge(b->in);
+ in->merge(b->in.get());
if (RECTANGLE_OVERLAP_LOGGING) {
ofstream f(LOGFILE,ios::app);
f<<" merged heap: "<<*in<<"\n";
void Block::mergeOut(Block *b) {
findMinOutConstraint();
b->findMinOutConstraint();
- out->merge(b->out);
+ out->merge(b->out.get());
}
Constraint *Block::findMinInConstraint() {
Constraint *v = nullptr;
#pragma once
+#include <memory>
#include <vector>
#include <iostream>
#include <vpsc/pairingheap/PairingHeap.h>
double wposn;
Block(Variable *v=nullptr);
Block(const Block &) = delete;
- ~Block();
Constraint* findMinLM();
Constraint* findMinLMBetween(Variable* lv, Variable* rv);
Constraint* findMinInConstraint();
double cost();
bool deleted;
long timeStamp;
- PairingHeap<Constraint*> *in;
- PairingHeap<Constraint*> *out;
+ std::unique_ptr<PairingHeap<Constraint*>> in;
+ std::unique_ptr<PairingHeap<Constraint*>> out;
private:
typedef enum {NONE, LEFT, RIGHT} Direction;
typedef std::pair<double, Constraint*> Pair;
bool canFollowRight(Constraint *c, Variable *last);
void populateSplitBlock(Block *b, Variable *v, Variable *u);
void addVariable(Variable *v);
- void setUpConstraintHeap(PairingHeap<Constraint*>* &h,bool in);
+ void setUpConstraintHeap(std::unique_ptr<PairingHeap<Constraint*>> &h,bool in);
};