Created
September 6, 2018 11:34
-
-
Save 5a494d/2797075937a985dcabc4752b4d8df7e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
#include <string> | |
class EmailProcessor | |
{ | |
public: | |
void receiveMessage (const std::string& message) | |
{ | |
if ( _handler_func ) | |
{ | |
_handler_func( message ); | |
} | |
// other processing | |
} | |
void setHandlerFunc (std::function<void (const std::string&)> handler_func) | |
{ | |
_handler_func = handler_func; | |
} | |
private: | |
std::function<void (const std::string&)> _handler_func; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EmailProcessor processor; | |
MessageSizeStore size_store; | |
processor.setHandlerFunc( | |
[&] (const std::string& message) { size_store.checkMessage( message ); } | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
class MessageSizeStore | |
{ | |
public: | |
MessageSizeStore () : _max_size( 0 ) {} | |
void checkMessage (const std::string& message ) | |
{ | |
const int size = message.length(); | |
if ( size > _max_size ) | |
{ | |
_max_size = size; | |
} | |
} | |
int getSize () | |
{ | |
return _max_size; | |
} | |
private: | |
int _max_size; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment