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 access address
16// metadata, typically by downloading this from the address metadata server or
17// by linking the metadata into the binary.
18
19#ifndef I18N_ADDRESSINPUT_SOURCE_H_
20#define I18N_ADDRESSINPUT_SOURCE_H_
21
22#include <libaddressinput/callback.h>
23
24#include <string>
25
26namespace i18n {
27namespace addressinput {
28
29// Gets address metadata. The callback data must be allocated on the heap,
30// passing ownership to the callback. Sample usage:
31//
32//    class MySource : public Source {
33//     public:
34//      virtual void Get(const std::string& key,
35//                       const Callback& data_ready) const {
36//        bool success = ...
37//        std::string* data = new ...
38//        data_ready(success, key, data);
39//      }
40//    };
41class Source {
42 public:
43  typedef i18n::addressinput::Callback<const std::string&,
44                                       std::string*> Callback;
45
46  virtual ~Source() {}
47
48  // Gets metadata for |key| and invokes the |data_ready| callback.
49  virtual void Get(const std::string& key,
50                   const Callback& data_ready) const = 0;
51};
52
53}  // namespace addressinput
54}  // namespace i18n
55
56#endif  // I18N_ADDRESSINPUT_SOURCE_H_
57