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