Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // processWrapper.hpp
- // ProjectViolet
- //
- // Created by Keegan Bilodeau on 8/31/20.
- // Copyright © 2020 Keegan Bilodeau. All rights reserved.
- //
- #ifndef processWrapper_hpp
- #define processWrapper_hpp
- #include <stdio.h>
- #include <type_traits>
- enum ProcessOperationCode
- {
- START,
- RESET,
- STEP,
- PAUSE,
- STOP
- };
- class RunnableProcess
- {
- public:
- // Starts and lets the program continue without stopping
- void start();
- // Resets a completed program
- void reset();
- // Runs a looping process for one cycle; non-looping will break the program by assertion
- void stepLoop();
- // Stops a looping process without resetting it; non-looping processes will break the program by assertion
- void pauseLoop();
- // Stops a looping process and resets it; non-looping process will break the prohram by assertion
- void stopLoop();
- };
- template <typename ProcessType>
- class ProcessWrapper
- {
- public:
- // A constructor that allows passing by reference
- ProcessWrapper(ProcessType &process) : mWrappedProcess(process)
- {
- static_assert(std::is_base_of<RunnableProcess, ProcessType>::value, "WrappedProcessType must inherit from RunnableProcess!");
- }
- // A constructor that allows passing by rvalue
- ProcessWrapper(ProcessType process) : mWrappedProcess(process)
- {
- static_assert(std::is_base_of<RunnableProcess, ProcessType>::value, "WrappedProcessType must inherit from RunnableProcess!");
- }
- // Calls the respective process function:
- void runProcessOperation(ProcessOperationCode processCode)
- {
- switch (processCode)
- {
- case START:
- mWrappedProcess.start();
- break;
- case RESET:
- mWrappedProcess.reset();
- break;
- case STEP:
- mWrappedProcess.stepLoop();
- break;
- case PAUSE:
- mWrappedProcess.pauseLoop();
- break;
- case STOP:
- mWrappedProcess.stopLoop();
- break;
- }
- }
- private:
- ProcessType mWrappedProcess;
- };
- #endif /* processWrapper_hpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement