1 // Copyright (C) 2013 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // An object to retrieve validation rules.
17 #ifndef I18N_ADDRESSINPUT_RULE_RETRIEVER_H_
18 #define I18N_ADDRESSINPUT_RULE_RETRIEVER_H_
20 #include <libaddressinput/callback.h>
21 #include <libaddressinput/util/basictypes.h>
22 #include <libaddressinput/util/scoped_ptr.h>
27 namespace addressinput {
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);
40 typedef i18n::addressinput::Callback<const std::string&,
41 const Rule&> Callback;
43 // Takes ownership of |retriever|.
44 explicit RuleRetriever(const Retriever* retriever);
47 // Retrieves the rule for |key| and invokes the |rule_ready| callback.
48 void RetrieveRule(const std::string& key, const Callback& rule_ready) const;
51 scoped_ptr<const Retriever> data_retriever_;
53 DISALLOW_COPY_AND_ASSIGN(RuleRetriever);
56 } // namespace addressinput
59 #endif // I18N_ADDRESSINPUT_RULE_RETRIEVER_H_