rikitiki  v0.1.67
Build C++ web server modules that allow easy routing and deployment.
connContext_ext.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 #include "../connContext.h"
5 #include <jsoncpp/json/json.h>
6 #include <array>
7 namespace rikitiki{
8  rikitiki::Response& operator <<(rikitiki::Response& response, const Json::Value&);
9  rikitiki::ConnContext& operator>>(rikitiki::ConnContext& response, Json::Value& val);
10 
11  template <>
12  struct ContentHandler_<Json::Value> {
13  static constexpr std::array<ContentType::t,2> ContentTypes() {
14  return { {ContentType::application_json, ContentType::application_javascript } }; };
15  };
16 
17 
18  template <typename T>
19  static Json::Value& operator >>(Json::Value& jv, std::vector<T>& t){
20  assert(jv.isArray());
21  t.resize(jv.size());
22  for(unsigned int i = 0;i < jv.size();i++)
23  jv[i] >> t[i];
24  return jv;
25  }
26 
27  template <typename T>
28  static Json::Value& operator<<(Json::Value& jv, std::vector<T>& t){
29  jv = Json::Value(Json::arrayValue);
30  jv.resize(t.size());
31  for(unsigned int i = 0;i < t.size();i++)
32  jv[i] << t[i];
33  return jv;
34  }
35 }
36 
37