-
Notifications
You must be signed in to change notification settings - Fork 16
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
added userdefined statistics #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,76 @@ class ClaspFacade : public ModelHandler { | |
*/ | ||
bool read(); | ||
//@} | ||
|
||
/*! | ||
* \name Userdefimed statistics functions | ||
* Functions for adding userdefined statistics. | ||
* @{ */ | ||
|
||
class UserdefinedStats { | ||
public: | ||
UserdefinedStats(); | ||
const char* name() const; | ||
size_t root() const; | ||
/// check whether an Object (of a certain type) is already attached to a map | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be consistent in the use of comment styles and please also document any exceptions and/or preconditions. |
||
/// if yes, target is set to the objects key | ||
bool exists(size_t key, const std::string& name, size_t& target) const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more natural interface would be to use a size_t-pointer as return value and then use nullptr to indicate the absence of name. |
||
bool exists(size_t key, const std::string& name, Potassco::Statistics_t type, size_t& target) const; | ||
/// check whether an Object (of a certain type) is already attached to an array | ||
/// if yes, target is set to the objects key | ||
bool exists(size_t key, size_t index, size_t& target) const; | ||
bool exists(size_t key, size_t index, Potassco::Statistics_t type, size_t& target) const; | ||
/// attach a new Object to a Map or Array, or return the old one if if already exists | ||
size_t get(size_t key, const std::string& name, Potassco::Statistics_t type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having get() to actually create an object feeels kinda wrong. |
||
size_t get(size_t key, size_t index, Potassco::Statistics_t type); | ||
|
||
/// (re)sets the value of a value object | ||
void set(size_t key, double v); | ||
|
||
StatisticObject toStats(); | ||
private: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation |
||
void validKey(size_t key) const ; | ||
Potassco::Statistics_t type(size_t key) const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The private parts should be "pimpl"'ed out into the cpp file. |
||
|
||
StatisticObject getStats(size_t k) const; | ||
size_t toId(const std::string& s); | ||
struct Connector { | ||
Connector(size_t index, size_t target) : index(index), target(target) {} | ||
size_t index; /// index to strings or integer for array | ||
size_t target; /// key of the target that is connected here | ||
}; | ||
//! An array of statistic objects. | ||
class SimpleStatsVec : public PodVector<StatisticObject>::type { | ||
public: | ||
StatisticObject toStats() const { return StatisticObject::array(this); } | ||
}; | ||
|
||
size_t root_; /// root map index | ||
std::unordered_map<size_t, std::vector<Connector>> connections_; /// key -> coneections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now please use POTASSCO_EXT_NS::unordered_map |
||
std::vector<double> numbers_; | ||
std::vector<std::string> strings_; | ||
std::vector<std::pair<size_t, Potassco::Statistics_t>> mapper_; | ||
std::vector<StatsMap> maps_; | ||
std::vector<SimpleStatsVec> vecs_; | ||
|
||
}; | ||
|
||
|
||
//! Sets the callback for updating userdefined statistics. | ||
/*! | ||
* \param cb Callback method to be called whenever an update is needed. | ||
* \param data Userdefined callback data. | ||
*/ | ||
typedef void(*UserdefinedStatsCallback)(UserdefinedStats*, void*); | ||
void addUserStatisticsCallback(UserdefinedStatsCallback cb , void* data); | ||
//@} | ||
//! Gets the callbacks for updating userdefined statistics. | ||
/*! | ||
* \param cb returns the callback methods to be called whenever an update is needed. | ||
* \param data returns userdefined callback data. | ||
*/ | ||
void getUserStatisticsCallback(std::vector<UserdefinedStatsCallback>& cbs , std::vector<void*>& data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be const-correct. Furthermore, I think returning a vector of Closures, where Closure would be a pair<UserdefinedStatsCallback, void*>, would be more natural. |
||
//@} | ||
|
||
|
||
/*! | ||
|
@@ -449,6 +519,8 @@ class ClaspFacade : public ModelHandler { | |
BuilderPtr builder_; | ||
SummaryPtr accu_; | ||
StatsPtr stats_; // statistics: only if requested | ||
std::vector<UserdefinedStatsCallback> userStatsCbs_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a single vector storing pairs of function pointer and corresponding data. |
||
std::vector<void*> userStatsData_; | ||
SolvePtr solve_; // NOTE: last so that it is destroyed first; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Userdefimed -> Userdefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, even better, “User-defined,”
UserDefinedStats
, and so on.