1// Copyright (C) 2014 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#ifndef I18N_ADDRESSINPUT_SUPPLIER_H_
16#define I18N_ADDRESSINPUT_SUPPLIER_H_
17
18#include <libaddressinput/callback.h>
19
20namespace i18n {
21namespace addressinput {
22
23class LookupKey;
24class Rule;
25
26// Interface for objects that are able to supply the AddressValidator with the
27// metadata needed to validate an address, as described by a LookupKey.
28class Supplier {
29 public:
30  struct RuleHierarchy;
31  typedef i18n::addressinput::Callback<const LookupKey&,
32                                       const RuleHierarchy&> Callback;
33
34  virtual ~Supplier() {}
35
36  // Aggregates the metadata needed for |lookup_key| into a RuleHierarchy
37  // object, then calls |supplied|. Implementations of this interface may
38  // either load the necessary data on demand, or fail if the necessary data
39  // hasn't already been loaded.
40  virtual void Supply(const LookupKey& lookup_key,
41                      const Callback& supplied) = 0;
42
43  // A RuleHierarchy object encapsulates the hierarchical list of Rule objects
44  // that corresponds to a particular LookupKey.
45  struct RuleHierarchy {
46    RuleHierarchy() : rule() {}
47    const Rule* rule[4];  // Cf. LookupKey::kHierarchy.
48  };
49};
50
51}  // namespace addressinput
52}  // namespace i18n
53
54#endif  // I18N_ADDRESSINPUT_SUPPLIER_H_
55