rikitiki  v0.1.67
Build C++ web server modules that allow easy routing and deployment.
routing.h
1 /* Copyright (C) 2012-2013 Justin Berger
2  The full license is available in the LICENSE file at the root of this project and is also available at http://opensource.org/licenses/MIT. */
3 
4 #pragma once
5 #include "server.h"
6 #include "connContext.h"
7 #include <cstring>
8 namespace rikitiki {
9 
14 struct Route : public Handler {
15  std::string route;
16  ConnContext::Method method;
17 
18  Route(const std::string& _route, ConnContext::Method _method);
19  Route(const std::string& _route);
20  virtual std::string name() const;
21 };
22 
26 template <typename T, bool Enable = std::is_compound<T>::value >
28  typedef T type;
29 };
30 
34 template <typename T>
35 struct sane_ref_type<T, true>{
36  typedef const T& type;
37 };
38 
46 template <typename P, typename... T>
47  struct Route_ : public Route {
48  typedef void (P::*F)(ConnContext& ctx, typename sane_ref_type<T>::type...);
49  P* parent;
50  F f;
51  virtual bool visible() const { return false; }
52  Route_(P* p, const std::string& _route, F _f, ConnContext::Method method);
53 
54  int Scan(ConnContext& ctx, T&... t);
55  virtual bool Handle(ConnContext& ctx);
56 };
57 
61 template <typename P>
62  struct Route_<P> : public Route {
63  typedef void (P::*F)(ConnContext& ctx);
64  P* parent;
65  F f;
66  virtual bool visible() const { return method == ConnContext::GET || method == ConnContext::ANY; }
67  Route_(P* p, const std::string& _route, F _f, ConnContext::Method method);
68  virtual bool Handle(ConnContext& ctx);
69 };
70 
76 template <typename... T>
77  struct CreateRoute {
78  template<typename P>
79  static Route* With(P* p,
80  const std::string& _route,
81  typename Route_<P, T...>::F _f,
82  ConnContext::Method method = ConnContext::ANY);
83 
84  template<typename P>
85  static Route* With(P* p,
86  const std::string& _route,
87  ConnContext::Method method = ConnContext::ANY);
88 
89  };
90 
91 #include "routing.tcc"
92 
93 }