Home | History | Annotate | Download | only in libaddressinput
      1 // Copyright (C) 2013 Google Inc.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 // http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 //
     15 // The interface to be implemented by the user of the library to enable
     16 // downloading validation rules from a server.
     17 
     18 #ifndef I18N_ADDRESSINPUT_DOWNLOADER_H_
     19 #define I18N_ADDRESSINPUT_DOWNLOADER_H_
     20 
     21 #include <libaddressinput/callback.h>
     22 
     23 #include <string>
     24 
     25 namespace i18n {
     26 namespace addressinput {
     27 
     28 // Downloads validation rules from the server. Sample usage:
     29 //    class MyDownloader : public Downloader {
     30 //     public:
     31 //      virtual void Download(const std::string& url,
     32 //                            const Callback& downloaded) const {
     33 //        bool success = ...
     34 //        std::string data = ...
     35 //        downloaded(success, url, data);
     36 //      }
     37 //    };
     38 class Downloader {
     39  public:
     40   typedef i18n::addressinput::Callback<std::string, std::string> Callback;
     41 
     42   virtual ~Downloader() {}
     43 
     44   // Downloads |url| and invokes the |downloaded| callback.
     45   virtual void Download(const std::string& url,
     46                         const Callback& downloaded) const = 0;
     47 };
     48 
     49 }  // namespace addressinput
     50 }  // namespace i18n
     51 
     52 #endif  // I18N_ADDRESSINPUT_DOWNLOADER_H_
     53