Skip to content

Commit

Permalink
Merge pull request #100 from nanocoh/main
Browse files Browse the repository at this point in the history
Destroy function for Action
  • Loading branch information
nanocoh authored Sep 15, 2024
2 parents 0d3973e + ebe8451 commit e52efa7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
14 changes: 1 addition & 13 deletions src/bne/ActionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,7 @@ void ActionTree::process() {
// Destructor that releases all the actions
ActionTree::~ActionTree() {
for (auto& action : actions_) {
switch (action->getType()) {
case ActionType::DELETE:
delete static_cast<DeleteAction*>(action);
break;
case ActionType::DRIVE_WITH_CONSTANT:
delete static_cast<DriveWithConstantAction*>(action);
break;
case ActionType::REDUCTION:
delete static_cast<ReductionAction*>(action);
break;
default:
break;
}
action->destroy();
}
}

Expand Down
23 changes: 21 additions & 2 deletions src/bne/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ bool DriveWithConstantAction::operator<(const Action& action) const {
if (pathToDrive_ < driveWithConstantAction.pathToDrive_) {
return true;
} else if (pathToDrive_ == driveWithConstantAction.pathToDrive_) {

if (termToDrive_ < driveWithConstantAction.termToDrive_) {
return true;
} else if (termToDrive_ == driveWithConstantAction.termToDrive_) {
Expand All @@ -196,13 +195,33 @@ bool DriveWithConstantAction::operator<(const Action& action) const {
}
}
return false;
// LCOV_EXCL_STOP
// LCOV_EXCL_STOP
}

void DeleteAction::processOnContext(SNLDesign* design) {
design->getInstance(toDelete_)->destroy();
}

bool DeleteAction::operator==(const Action& action) const {
if (action.getType() != ActionType::DELETE) {
// LCOV_EXCL_START
return false;
// LCOV_EXCL_STOP
}
const DeleteAction& deleteAction = dynamic_cast<const DeleteAction&>(action);
return toDelete_ == deleteAction.toDelete_;
}

bool DeleteAction::operator<(const Action& action) const {
if (action.getType() != ActionType::DELETE) {
// LCOV_EXCL_START
return getType() < action.getType();
// LCOV_EXCL_STOP
}
const DeleteAction& deleteAction = dynamic_cast<const DeleteAction&>(action);
return toDelete_ < deleteAction.toDelete_;
}

void ReductionAction::replaceInstance(
SNLInstance* instance,
const std::pair<SNLDesign*, SNLLibraryTruthTables::Indexes>& result) {
Expand Down
25 changes: 7 additions & 18 deletions src/bne/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Action {
// Virtual destructor
virtual ~Action() {};

virtual void destroy() = 0;

private:
ActionType type_;
};
Expand Down Expand Up @@ -74,7 +76,7 @@ class DriveWithConstantAction : public Action {
// comparator
bool operator==(const Action& action) const override;
bool operator<(const Action& action) const override;

void destroy() override { delete this; }
private:
SNLID::DesignObjectID pathToDrive_;
SNLID::DesignObjectID termToDrive_;
Expand Down Expand Up @@ -103,23 +105,9 @@ class DeleteAction : public Action {
toDelete_(action.toDelete_),
context_(action.context_) {}
// comparator
bool operator==(const Action& action) const override {
if (action.getType() != ActionType::DELETE) {
return false;
}
const DeleteAction& deleteAction =
dynamic_cast<const DeleteAction&>(action);
return toDelete_ == deleteAction.toDelete_;
}
bool operator<(const Action& action) const override {
if (action.getType() != ActionType::DELETE) {
return getType() < action.getType();
}
const DeleteAction& deleteAction =
dynamic_cast<const DeleteAction&>(action);
return toDelete_ < deleteAction.toDelete_;
}

bool operator==(const Action& action) const override;
bool operator<(const Action& action) const override;
void destroy() override { delete this; }
private:
SNLID::DesignObjectID toDelete_;
std::vector<SNLID::DesignObjectID> context_;
Expand All @@ -144,6 +132,7 @@ class ReductionAction : public Action {
}
bool operator==(const Action& action) const override;
bool operator<(const Action& action) const override;
void destroy() override { delete this; }
private:
const std::vector<SNLID::DesignObjectID> context_;
const SNLID::DesignObjectID instance_;
Expand Down

0 comments on commit e52efa7

Please sign in to comment.