Skip to content

Commit c5ec112

Browse files
Merge pull request #502 from JulienDoerner/issue_493
Memory management in Variants
2 parents a5a51d3 + 84581dd commit c5ec112

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

include/crpropa/Module.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,24 @@ class AbstractCondition: public Module {
5959
void setMakeAcceptedInactive(bool makeInactive);
6060
void setRejectFlag(std::string key, std::string value);
6161
void setAcceptFlag(std::string key, std::string value);
62+
63+
// return the reject flag (key & value), delimiter is the "&".
64+
std::string getRejectFlag();
65+
66+
// return the accept flag (key & value), delimiter is the "&"
67+
std::string getAcceptFlag();
6268
};
69+
70+
/**
71+
@class Deactivation
72+
@brief Direct deactivation of the candidate. Can be used for debuging.
73+
*/
74+
class Deactivation: public AbstractCondition {
75+
public:
76+
void process(Candidate *cand) const { reject(cand); }
77+
};
78+
79+
6380
} // namespace crpropa
6481

6582
#endif /* CRPROPA_MODULE_H */

include/crpropa/module/Observer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class ObserverTimeEvolution: public ObserverFeature {
268268
DetectionState checkDetection(Candidate *candidate) const;
269269
std::string getDescription() const;
270270
};
271+
271272
/** @} */
272273

273274
}

src/Module.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ void Module::setDescription(const std::string &d) {
1919

2020
AbstractCondition::AbstractCondition() :
2121
makeRejectedInactive(true), makeAcceptedInactive(false), rejectFlagKey(
22-
"Rejected") {
23-
22+
"Rejected"), rejectFlagValue( typeid(*this).name() ) {
2423
}
2524

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

79+
std::string AbstractCondition::getRejectFlag() {
80+
std::string out = rejectFlagKey + "&" + rejectFlagValue;
81+
return out;
82+
}
83+
84+
std::string AbstractCondition::getAcceptFlag() {
85+
std::string out = acceptFlagKey + "&" + acceptFlagValue;
86+
return out;
87+
}
88+
89+
8090
} // namespace crpropa

src/Variant.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Variant::Variant(const char* s) {
2727
}
2828

2929
Variant::~Variant() {
30-
clear();
30+
clear(type);
31+
delete data._t_string;
3132
}
3233

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

678679
void Variant::clear(Type t) {
679-
if (t == TYPE_STRING)
680+
if (t == TYPE_STRING)
680681
safeDelete(data._t_string);
681682
else if (t == TYPE_VECTOR3F)
682683
safeDelete(data._t_vector3f);

src/module/Observer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,5 @@ std::string ObserverSurface::getDescription() const {
348348
return ss.str();
349349
}
350350

351+
351352
} // namespace crpropa

0 commit comments

Comments
 (0)