changeset 659:443cced10836

code cleaning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Nov 2013 14:41:46 +0100
parents e8e59e80868c
children f0232774b913
files Core/RestApi/RestApi.cpp Core/RestApi/RestApi.h
diffstat 2 files changed, 88 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/Core/RestApi/RestApi.cpp	Mon Nov 04 12:08:07 2013 +0100
+++ b/Core/RestApi/RestApi.cpp	Mon Nov 04 14:41:46 2013 +0100
@@ -51,7 +51,7 @@
     result.clear();
 
     for (HttpHandler::Arguments::const_iterator 
-           it = getArguments_->begin(); it != getArguments_->end(); ++it)
+           it = getArguments_.begin(); it != getArguments_.end(); ++it)
     {
       result[it->first] = it->second;
     }
@@ -200,15 +200,7 @@
         {
           //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri);
           ok = true;
-          GetCall call;
-          call.output_ = &restOutput;
-          call.context_ = this;
-          call.httpHeaders_ = &headers;
-          call.uriComponents_ = &components;
-          call.trailing_ = &trailing;
-          call.fullUri_ = &uri;
-          
-          call.getArguments_ = &getArguments;
+          GetCall call(restOutput, *this, headers, components, trailing, uri, getArguments);
           it->second(call);
         }
       }
@@ -222,15 +214,7 @@
         {
           //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri);
           ok = true;
-          PutCall call;
-          call.output_ = &restOutput;
-          call.context_ = this;
-          call.httpHeaders_ = &headers;
-          call.uriComponents_ = &components;
-          call.trailing_ = &trailing;
-          call.fullUri_ = &uri;
-           
-          call.data_ = &postData;
+          PutCall call(restOutput, *this, headers, components, trailing, uri, postData);
           it->second(call);
         }
       }
@@ -244,15 +228,7 @@
         {
           //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri);
           ok = true;
-          PostCall call;
-          call.output_ = &restOutput;
-          call.context_ = this;
-          call.httpHeaders_ = &headers;
-          call.uriComponents_ = &components;
-          call.trailing_ = &trailing;
-          call.fullUri_ = &uri;
-           
-          call.data_ = &postData;
+          PostCall call(restOutput, *this, headers, components, trailing, uri, postData);
           it->second(call);
         }
       }
@@ -266,13 +242,7 @@
         {
           //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri);
           ok = true;
-          DeleteCall call;
-          call.output_ = &restOutput;
-          call.context_ = this;
-          call.httpHeaders_ = &headers;
-          call.uriComponents_ = &components;
-          call.trailing_ = &trailing;
-          call.fullUri_ = &uri;
+          DeleteCall call(restOutput, *this, headers, components, trailing, uri);
           it->second(call);
         }
       }
--- a/Core/RestApi/RestApi.h	Mon Nov 04 12:08:07 2013 +0100
+++ b/Core/RestApi/RestApi.h	Mon Nov 04 14:41:46 2013 +0100
@@ -48,12 +48,27 @@
       friend class RestApi;
 
     private:
-      RestApiOutput* output_;
-      RestApi* context_;
-      const HttpHandler::Arguments* httpHeaders_;
-      const RestApiPath::Components* uriComponents_;
-      const UriComponents* trailing_;
-      const UriComponents* fullUri_;
+      RestApiOutput& output_;
+      RestApi& context_;
+      const HttpHandler::Arguments& httpHeaders_;
+      const RestApiPath::Components& uriComponents_;
+      const UriComponents& trailing_;
+      const UriComponents& fullUri_;
+
+      Call(RestApiOutput& output,
+           RestApi& context,
+           const HttpHandler::Arguments& httpHeaders,
+           const RestApiPath::Components& uriComponents,
+           const UriComponents& trailing,
+           const UriComponents& fullUri) :
+        output_(output),
+        context_(context),
+        httpHeaders_(httpHeaders),
+        uriComponents_(uriComponents),
+        trailing_(trailing),
+        fullUri_(fullUri)
+      {
+      }
 
     protected:
       static bool ParseJsonRequestInternal(Json::Value& result,
@@ -62,44 +77,44 @@
     public:
       RestApiOutput& GetOutput()
       {
-        return *output_;
+        return output_;
       }
 
       RestApi& GetContext()
       {
-        return *context_;
+        return context_;
       }
     
       const UriComponents& GetFullUri() const
       {
-        return *fullUri_;
+        return fullUri_;
       }
     
       const UriComponents& GetTrailingUri() const
       {
-        return *trailing_;
+        return trailing_;
       }
 
       std::string GetUriComponent(const std::string& name,
                                   const std::string& defaultValue) const
       {
-        return HttpHandler::GetArgument(*uriComponents_, name, defaultValue);
+        return HttpHandler::GetArgument(uriComponents_, name, defaultValue);
       }
 
       std::string GetHttpHeader(const std::string& name,
                                 const std::string& defaultValue) const
       {
-        return HttpHandler::GetArgument(*httpHeaders_, name, defaultValue);
+        return HttpHandler::GetArgument(httpHeaders_, name, defaultValue);
       }
 
       const HttpHandler::Arguments& GetHttpHeaders() const
       {
-        return *httpHeaders_;
+        return httpHeaders_;
       }
 
       void ParseCookies(HttpHandler::Arguments& result) const
       {
-        HttpHandler::ParseCookies(result, *httpHeaders_);
+        HttpHandler::ParseCookies(result, httpHeaders_);
       }
 
       virtual bool ParseJsonRequest(Json::Value& result) const = 0;
@@ -111,34 +126,59 @@
       friend class RestApi;
 
     private:
-      const HttpHandler::Arguments* getArguments_;
+      const HttpHandler::Arguments& getArguments_;
 
     public:
+      GetCall(RestApiOutput& output,
+              RestApi& context,
+              const HttpHandler::Arguments& httpHeaders,
+              const RestApiPath::Components& uriComponents,
+              const UriComponents& trailing,
+              const UriComponents& fullUri,
+              const HttpHandler::Arguments& getArguments) :
+        Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
+        getArguments_(getArguments)
+      {
+      }
+
       std::string GetArgument(const std::string& name,
                               const std::string& defaultValue) const
       {
-        return HttpHandler::GetArgument(*getArguments_, name, defaultValue);
+        return HttpHandler::GetArgument(getArguments_, name, defaultValue);
       }
 
       bool HasArgument(const std::string& name) const
       {
-        return getArguments_->find(name) != getArguments_->end();
+        return getArguments_.find(name) != getArguments_.end();
       }
 
       virtual bool ParseJsonRequest(Json::Value& result) const;
     };
 
+
     class PutCall : public Call
     {
       friend class RestApi;
 
     private:
-      const std::string* data_;
+      const std::string& data_;
 
     public:
+      PutCall(RestApiOutput& output,
+              RestApi& context,
+              const HttpHandler::Arguments& httpHeaders,
+              const RestApiPath::Components& uriComponents,
+              const UriComponents& trailing,
+              const UriComponents& fullUri,
+              const std::string& data) :
+        Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
+        data_(data)
+      {
+      }
+
       const std::string& GetPutBody() const
       {
-        return *data_;
+        return data_;
       }
 
       virtual bool ParseJsonRequest(Json::Value& result) const
@@ -152,12 +192,24 @@
       friend class RestApi;
 
     private:
-      const std::string* data_;
+      const std::string& data_;
 
     public:
+      PostCall(RestApiOutput& output,
+               RestApi& context,
+               const HttpHandler::Arguments& httpHeaders,
+               const RestApiPath::Components& uriComponents,
+               const UriComponents& trailing,
+               const UriComponents& fullUri,
+               const std::string& data) :
+        Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
+        data_(data)
+      {
+      }
+
       const std::string& GetPostBody() const
       {
-        return *data_;
+        return data_;
       }
 
       virtual bool ParseJsonRequest(Json::Value& result) const
@@ -169,6 +221,16 @@
     class DeleteCall : public Call
     {
     public:
+      DeleteCall(RestApiOutput& output,
+                 RestApi& context,
+                 const HttpHandler::Arguments& httpHeaders,
+                 const RestApiPath::Components& uriComponents,
+                 const UriComponents& trailing,
+                 const UriComponents& fullUri) :
+        Call(output, context, httpHeaders, uriComponents, trailing, fullUri)
+      {
+      }
+
       virtual bool ParseJsonRequest(Json::Value& result) const
       {
         result.clear();