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 // scoped_ptr<RuleRetriever::Callback> rule_ready(BuildCallback(
36 // this, &MyClass::OnRuleReady));
37 // rules.RetrieveRule("data/CA/AB--fr", *rule_ready);
40 typedef i18n::addressinput::Callback<std::string, Rule> Callback;
42 // Takes ownership of |retriever|.
43 explicit RuleRetriever(const Retriever* retriever);
46 // Retrieves the rule for |key| and invokes the |rule_ready| callback.
47 void RetrieveRule(const std::string& key, const Callback& rule_ready) const;
50 scoped_ptr<const Retriever> data_retriever_;
52 DISALLOW_COPY_AND_ASSIGN(RuleRetriever);
55 } // namespace addressinput
58 #endif // I18N_ADDRESSINPUT_RULE_RETRIEVER_H_