Skip to content

Instantly share code, notes, and snippets.

@5a494d
Created September 6, 2018 11:34
Show Gist options
  • Save 5a494d/2797075937a985dcabc4752b4d8df7e6 to your computer and use it in GitHub Desktop.
Save 5a494d/2797075937a985dcabc4752b4d8df7e6 to your computer and use it in GitHub Desktop.
#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;
};
EmailProcessor processor;
MessageSizeStore size_store;
processor.setHandlerFunc(
[&] (const std::string& message) { size_store.checkMessage( message ); }
);
#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