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_ADDRESS_INPUT_HELPER_H_ 16 #define I18N_ADDRESSINPUT_ADDRESS_INPUT_HELPER_H_ 17 18 #include <libaddressinput/util/basictypes.h> 19 20 #include <vector> 21 22 namespace i18n { 23 namespace addressinput { 24 25 class LookupKey; 26 class PreloadSupplier; 27 struct AddressData; 28 struct Node; 29 30 class AddressInputHelper { 31 public: 32 // Creates an input helper that uses the supplier provided to get metadata to 33 // help a user complete or fix an address. Doesn't take ownership of 34 // |supplier|. Since latency is important for these kinds of tasks, we expect 35 // the supplier to have the data already. 36 AddressInputHelper(PreloadSupplier* supplier); 37 38 ~AddressInputHelper(); 39 40 // Fill in missing components of an address as best as we can based on 41 // existing data. For example, for some countries only one postal code is 42 // valid; this would enter that one. For others, the postal code indicates 43 // what state should be selected. Existing data will never be overwritten. 44 // 45 // Note that the preload supplier must have had the rules for the country 46 // represented by this address loaded before this method is called - otherwise 47 // an assertion failure will result. 48 // 49 // The address should have the best language tag as returned from 50 // BuildComponents(). 51 void FillAddress(AddressData* address) const; 52 53 private: 54 void CheckChildrenForPostCodeMatches( 55 const AddressData& address, const LookupKey& lookup_key, 56 const Node* parent, std::vector<Node>* hierarchy) const; 57 58 // We don't own the supplier_. 59 PreloadSupplier* const supplier_; 60 61 DISALLOW_COPY_AND_ASSIGN(AddressInputHelper); 62 }; 63 64 } // namespace addressinput 65 } // namespace i18n 66 67 #endif // I18N_ADDRESSINPUT_ADDRESS_INPUT_HELPER_H_ 68