1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (C) 2013 Google Inc.
2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Licensed under the Apache License, Version 2.0 (the "License");
4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// you may not use this file except in compliance with the License.
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// You may obtain a copy of the License at
6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// http://www.apache.org/licenses/LICENSE-2.0
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Unless required by applicable law or agreed to in writing, software
10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// distributed under the License is distributed on an "AS IS" BASIS,
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// See the License for the specific language governing permissions and
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// limitations under the License.
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// An object to retrieve validation rules.
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef I18N_ADDRESSINPUT_RULE_RETRIEVER_H_
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define I18N_ADDRESSINPUT_RULE_RETRIEVER_H_
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <libaddressinput/callback.h>
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <libaddressinput/util/basictypes.h>
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <libaddressinput/util/scoped_ptr.h>
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <string>
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace i18n {
27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace addressinput {
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Retriever;
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Rule;
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Retrieves validation rules. Sample usage:
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//    const Retriever* retriever = ...
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//    RuleRetriever rules(retriever);
35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//    scoped_ptr<RuleRetriever::Callback> rule_ready(BuildCallback(
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//        this, &MyClass::OnRuleReady));
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//    rules.RetrieveRule("data/CA/AB--fr", *rule_ready);
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class RuleRetriever {
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  typedef i18n::addressinput::Callback<std::string, Rule> Callback;
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Takes ownership of |retriever|.
43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  explicit RuleRetriever(const Retriever* retriever);
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ~RuleRetriever();
45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Retrieves the rule for |key| and invokes the |rule_ready| callback.
47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void RetrieveRule(const std::string& key, const Callback& rule_ready) const;
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<const Retriever> data_retriever_;
51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(RuleRetriever);
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace addressinput
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace i18n
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // I18N_ADDRESSINPUT_RULE_RETRIEVER_H_
59