MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
scope_helper.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <string>
5 
6 namespace microstrain
7 {
8 namespace extras
9 {
10 
11 //Class: ScopeHelper
12 // Class that allows a function to be run when this object goes out of scope.
14 {
15 private:
16  //Variable: m_outOfScopeFunction
17  // The function to run when the ScopeHelper goes out of scope.
18  std::function<void()> m_outOfScopeFunction;
19 
20  //Variable: m_canceled
21  // Whether the scope function has been canceled or not.
22  bool m_canceled;
23 
24  ScopeHelper(); //default constructor disabled
25  ScopeHelper(const ScopeHelper&); //copy constructor disabled
26  ScopeHelper& operator=(const ScopeHelper&); //assignment operator disabled
27 
28 public:
29  //Constructor: ScopeHelper
30  // Creates a ScopeHelper object.
31  //
32  //Parameters:
33  // scopeFunction - The function to run when the ScopeHelper object is destroyed.
34  ScopeHelper(std::function<void()> scopeFunction);
35 
36  //Destructor: ScopeHelper
37  // Runs whatever function was assigned in the creation of the ScopeHelper.
38  ~ScopeHelper();
39 
40  //Function: cancel
41  // Sets a flag that indicates the originally set function should NOT be run when
42  // the ScopeHelper is destroyed.
43  void cancel();
44 };
45 
46 } //namespace extras
47 } //namespace microstrain
microstrain::extras::ScopeHelper::cancel
void cancel()
Definition: scope_helper.cpp:22
microstrain::extras::ScopeHelper
Definition: scope_helper.hpp:13
microstrain::extras::ScopeHelper::~ScopeHelper
~ScopeHelper()
Definition: scope_helper.cpp:14
microstrain
Definition: embedded_time.h:8