Advertisement
Ardente

ProcessWrapper

Aug 31st, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. //
  2. //  processWrapper.hpp
  3. //  ProjectViolet
  4. //
  5. //  Created by Keegan Bilodeau on 8/31/20.
  6. //  Copyright © 2020 Keegan Bilodeau. All rights reserved.
  7. //
  8.  
  9. #ifndef processWrapper_hpp
  10. #define processWrapper_hpp
  11.  
  12. #include <stdio.h>
  13. #include <type_traits>
  14.  
  15. enum ProcessOperationCode
  16. {
  17.     START,
  18.     RESET,
  19.     STEP,
  20.     PAUSE,
  21.     STOP
  22. };
  23.  
  24. class RunnableProcess
  25. {
  26. public:
  27.     // Starts and lets the program continue without stopping
  28.     void start();
  29.    
  30.     // Resets a completed program
  31.     void reset();
  32.    
  33.     // Runs a looping process for one cycle; non-looping will break the program by assertion
  34.     void stepLoop();
  35.    
  36.     // Stops a looping process without resetting it; non-looping processes will break the program by assertion
  37.     void pauseLoop();
  38.    
  39.     // Stops a looping process and resets it; non-looping process will break the prohram by assertion
  40.     void stopLoop();
  41. };
  42.  
  43. template <typename ProcessType>
  44. class ProcessWrapper
  45. {
  46. public:
  47.     // A constructor that allows passing by reference
  48.     ProcessWrapper(ProcessType &process) : mWrappedProcess(process)
  49.     {
  50.         static_assert(std::is_base_of<RunnableProcess, ProcessType>::value, "WrappedProcessType must inherit from RunnableProcess!");
  51.     }
  52.    
  53.     // A constructor that allows passing by rvalue
  54.     ProcessWrapper(ProcessType process) : mWrappedProcess(process)
  55.     {
  56.         static_assert(std::is_base_of<RunnableProcess, ProcessType>::value, "WrappedProcessType must inherit from RunnableProcess!");
  57.     }
  58.    
  59.     // Calls the respective process function:
  60.     void runProcessOperation(ProcessOperationCode processCode)
  61.     {
  62.         switch (processCode)
  63.         {
  64.             case START:
  65.                 mWrappedProcess.start();
  66.                 break;
  67.                
  68.             case RESET:
  69.                 mWrappedProcess.reset();
  70.                 break;
  71.                
  72.             case STEP:
  73.                 mWrappedProcess.stepLoop();
  74.                 break;
  75.                
  76.             case PAUSE:
  77.                 mWrappedProcess.pauseLoop();
  78.                 break;
  79.                
  80.             case STOP:
  81.                 mWrappedProcess.stopLoop();
  82.                 break;
  83.         }
  84.     }
  85.    
  86. private:
  87.     ProcessType mWrappedProcess;
  88. };
  89.  
  90. #endif /* processWrapper_hpp */
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement