// Copyright (C) 2014 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // The public interface to the address validation features of libaddressinput. // The AddressValidator will examine an AddressData struct and return a map of // the problems found with the different fields of this struct. #ifndef I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ #define I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ #include <libaddressinput/address_field.h> #include <libaddressinput/address_problem.h> #include <libaddressinput/callback.h> #include <map> namespace i18n { namespace addressinput { class Supplier; struct AddressData; FieldProblemMap; // Validates an AddressData struct. Sample usage: // class MyClass { // public: // MyClass() // : supplier_(new MySupplier), // validator_(new AddressValidator(supplier_.get())), // validated_(BuildCallback(this, &MyClass::Validated)) {} // // virtual ~MyClass() {} // // void ValidateAddress() const { // address_.region_code = "US"; // address_.administrative_area = "CA"; // validator_.Validate(address_, filter_, &problems_, *validated_); // } // // void Validated(bool success, // const AddressData& address, // const FieldProblemMap& problems) { // if (success && problems.empty()) { // ... // } // } // // private: // AddressData address_; // FieldProblemMap filter_; // FieldProblemMap problems_; // const std::unique_ptr<Supplier> supplier_; // const std::unique_ptr<AddressValidator> validator_; // const std::unique_ptr<const AddressValidator::Callback> validated_; // }; class AddressValidator { … }; } // namespace addressinput } // namespace i18n #endif // I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_