Mercurial > archived > louis > epitech > zia-api
view examples/rot13/main.cpp @ 41:7c8cd74023ce
Rework file layout, fix build, add README and SUPPORT
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Mon, 22 Mar 2010 02:08:24 +0100 |
parents | src/examples/rot13/main.cpp@812d6c5ac125 |
children | f8715c806d1c |
line wrap: on
line source
#include <sstream> #include <iostream> #include <vector> #include "Rot13Module.hpp" #include "Rot13Handler.hpp" /** * @brief Function that "emulates" the behavior of a server by instanciating a * IModule and by calling one of its handlers. * * @param [in] is The stream to read from. * @param [in] os The stream to write to. */ void process_stream(std::istream & is, std::ostream & os) { ModRot13 module; const std::vector<zia::api::handler::IHandler *> & handlers = module.getHandlers(); std::cout << "Running: " << module.getName() << " v" << module.getVersion() << std::endl; if (!handlers.empty() && handlers[0]->getHook() == zia::api::handler::ResponseBodyModifier) { /* * We should cast to zia::api::handler::IHttpHandler, but to call the * functor we would need to implement zia::api::http::ITransaction, * which isn't the purpose of this example. */ Rot13Handler * bodyHandler = dynamic_cast<Rot13Handler *>(handlers[0]); if (bodyHandler != NULL) (*bodyHandler)(is, os); } } /** * @brief This function print the content of a stream on the standard output * * @param [in] is the stream to dump */ void dump_stream(std::istream & is) { while (!is.eof()) { char c; is.get(c); std::cout << c; } std::cout << "---" << std::endl; } int main(void) { std::stringbuf buffer1; std::stringbuf buffer2; std::ostream os(NULL); std::istream is(NULL); os.rdbuf(&buffer1); os << "This is an example for the StreamIt api !" << std::endl; is.rdbuf(&buffer1); os.rdbuf(&buffer2); process_stream(is, os); is.rdbuf(&buffer2); dump_stream(is); std::cout << "The correct rot13 is: " << std::endl << "Guvf vf na rknzcyr sbe gur FgernzVg ncv !" << std::endl; return (0); }