Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory management in Variants #502

Merged
merged 7 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/crpropa/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ class AbstractCondition: public Module {
void setMakeAcceptedInactive(bool makeInactive);
void setRejectFlag(std::string key, std::string value);
void setAcceptFlag(std::string key, std::string value);

// return the reject flag (key & value), delimiter is the "&".
std::string getRejectFlag();

// return the accept flag (key & value), delimiter is the "&"
std::string getAcceptFlag();
};

/**
@class Deactivation
@brief Direct deactivation of the candidate. Can be used for debuging.
*/
class Deactivation: public AbstractCondition {
public:
void process(Candidate *cand) const { reject(cand); }
};


} // namespace crpropa

#endif /* CRPROPA_MODULE_H */
1 change: 1 addition & 0 deletions include/crpropa/module/Observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class ObserverTimeEvolution: public ObserverFeature {
DetectionState checkDetection(Candidate *candidate) const;
std::string getDescription() const;
};

/** @} */

}
Expand Down
14 changes: 12 additions & 2 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ void Module::setDescription(const std::string &d) {

AbstractCondition::AbstractCondition() :
makeRejectedInactive(true), makeAcceptedInactive(false), rejectFlagKey(
"Rejected") {

"Rejected"), rejectFlagValue( typeid(*this).name() ) {
}

void AbstractCondition::reject(Candidate *candidate) const {
Expand Down Expand Up @@ -77,4 +76,15 @@ void AbstractCondition::setAcceptFlag(std::string key, std::string value) {
acceptFlagValue = value;
}

std::string AbstractCondition::getRejectFlag() {
std::string out = rejectFlagKey + "&" + rejectFlagValue;
return out;
}

std::string AbstractCondition::getAcceptFlag() {
std::string out = acceptFlagKey + "&" + acceptFlagValue;
return out;
}


} // namespace crpropa
5 changes: 3 additions & 2 deletions src/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Variant::Variant(const char* s) {
}

Variant::~Variant() {
clear();
clear(type);
delete data._t_string;
}

const char* Variant::getTypeName() const {
Expand Down Expand Up @@ -676,7 +677,7 @@ Variant Variant::fromString(const std::string& s, Type t) {
}

void Variant::clear(Type t) {
if (t == TYPE_STRING)
if (t == TYPE_STRING)
safeDelete(data._t_string);
else if (t == TYPE_VECTOR3F)
safeDelete(data._t_vector3f);
Expand Down
1 change: 1 addition & 0 deletions src/module/Observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,5 @@ std::string ObserverSurface::getDescription() const {
return ss.str();
}


} // namespace crpropa
Loading