Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include "net_http.h"
  2. #include "../net.h"
  3.  
  4. #include <tuple>
  5. #include <algorithm>
  6.  
  7. //typedef std::function<std::vector<uint8_t>(std::vector<std::vector<uint8_t> >) > net_http_function_t;
  8.  
  9. static std::vector<std::pair<std::string, net_http_function_t> > registrar;
  10.  
  11. void net_http::file::add(
  12. std::string file,
  13. net_http_function_t function){
  14. std::pair<std::string, net_http_function_t> new_pair =
  15. std::make_pair(file, function);
  16. if(std::find(
  17. registrar.begin(),
  18. registrar.end(),
  19. new_pair) == registrar.end()){
  20. registrar.push_back(
  21. new_pair);
  22. }else{
  23. print("attempting to re-register the same function and path, fix references and enforce one-per-program stuff", P_ERR);
  24. }
  25. }
  26.  
  27. void net_http::file::del(
  28. std::string file){
  29. auto iter =
  30. std::find_if(
  31. registrar.begin(),
  32. registrar.end(),
  33. [&file](const std::pair<std::string, net_http_function_t> elem){
  34. return elem.first == file;
  35. });
  36. if(iter != registrar.end()){
  37. registrar.erase(
  38. iter);
  39. }else{
  40. print("attempting to erase a non-existant path, fix the function calls", P_ERR);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement