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// An object to retrieve validation rules. 16 17#ifndef I18N_ADDRESSINPUT_RULE_RETRIEVER_H_ 18#define I18N_ADDRESSINPUT_RULE_RETRIEVER_H_ 19 20#include <libaddressinput/callback.h> 21#include <libaddressinput/util/basictypes.h> 22#include <libaddressinput/util/scoped_ptr.h> 23 24#include <string> 25 26namespace i18n { 27namespace addressinput { 28 29class Retriever; 30class Rule; 31 32// Retrieves validation rules. Sample usage: 33// const Retriever* retriever = ... 34// RuleRetriever rules(retriever); 35// const scoped_ptr<const RuleRetriever::Callback> rule_ready( 36// BuildCallback(this, &MyClass::OnRuleReady)); 37// rules.RetrieveRule("data/CA/AB--fr", *rule_ready); 38class RuleRetriever { 39 public: 40 typedef i18n::addressinput::Callback<const std::string&, 41 const Rule&> Callback; 42 43 // Takes ownership of |retriever|. 44 explicit RuleRetriever(const Retriever* retriever); 45 ~RuleRetriever(); 46 47 // Retrieves the rule for |key| and invokes the |rule_ready| callback. 48 void RetrieveRule(const std::string& key, const Callback& rule_ready) const; 49 50 private: 51 scoped_ptr<const Retriever> data_retriever_; 52 53 DISALLOW_COPY_AND_ASSIGN(RuleRetriever); 54}; 55 56} // namespace addressinput 57} // namespace i18n 58 59#endif // I18N_ADDRESSINPUT_RULE_RETRIEVER_H_ 60