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