Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I have the following two classes and trying to figure out how to do SBRM correctly. The user will issue commands after starting the app in the following order 1) prepare, 2) start, 3) stop, and 4) clean. The user then might issue those same commands again. */
- class Runnable {
- private:
- std::shared_ptr<Solver> solver;
- public:
- Runnable();
- ~Runnable() { solver.reset() }
- prepare(std::shared_ptr<Solver> s) { solver = s; }
- run() { (*solver)(); }
- stop() { solver->stop() }
- clean() { solver.reset() }
- };
- class Manager {
- private:
- std::shared_ptr<Solver> solver;
- std::shared_ptr<Runnable> solveInterface;
- // ...
- };
- Manager::Manager() {
- solverInterface = make_shared<Runnable>();
- }
- Manager::prepare() {
- solver = make_shared<Solver>();
- solveInterface->prepare(solver);
- }
- Manager::start() {
- solverInterface->run();
- }
- Manager::stop() {
- solverInterface->stop();
- }
- Manager::clean() {
- solverInterface->clean();
- }
- /*
- My question is, is it correct to call solver.reset() in the destructor of Runnable or would proc just get destroyed naturally because it's going out of scope?
- */
Advertisement
Add Comment
Please, Sign In to add comment