| OLD | NEW |
| (Empty) | |
| 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 #ifndef I18N_ADDRESSINPUT_LOOKUP_KEY_H_ |
| 16 #define I18N_ADDRESSINPUT_LOOKUP_KEY_H_ |
| 17 |
| 18 #include <libaddressinput/address_field.h> |
| 19 #include <libaddressinput/util/basictypes.h> |
| 20 #include <libaddressinput/util/scoped_ptr.h> |
| 21 |
| 22 #include <map> |
| 23 #include <string> |
| 24 |
| 25 namespace i18n { |
| 26 namespace addressinput { |
| 27 |
| 28 class Rule; |
| 29 |
| 30 // Sample usage: |
| 31 // LookupKey country_key("CA"); |
| 32 // Rule country_rule = RetrieveRule(country_key.GetKeyValue()); |
| 33 // country_key.SetRule(country_rule); |
| 34 // |
| 35 // LookupKey* administrative_area_key = country_key.AddSubKey("AB"); |
| 36 // administrative_area_key->SetRule( |
| 37 // RetrieveRule(administrative_area_key.GetKeyValue())); |
| 38 // |
| 39 // Process(administrative_area_key->GetLevel(), |
| 40 // administrative_area_key->GetRule()); |
| 41 // |
| 42 // LookupKey* language_code_key = country_key.AddLanguageCodeKey("fr"); |
| 43 // language_code_key->SetRule( |
| 44 // RetrieveRule(language_code_key.GetKeyValue())); |
| 45 // |
| 46 // Process(language_code_key->GetLevel(), |
| 47 // language_code_key->GetRule()); |
| 48 class LookupKey { |
| 49 public: |
| 50 explicit LookupKey(const std::string& country_code); |
| 51 ~LookupKey(); |
| 52 |
| 53 // Returns the string representation of this key, for example "data/US/CA". |
| 54 const std::string& GetKeyValue() const; |
| 55 |
| 56 // Returns the level of this key, for example ADMIN_AREA. |
| 57 AddressField GetLevel() const; |
| 58 |
| 59 // Takes ownership of |rule|. |
| 60 void SetRule(const Rule* rule); |
| 61 |
| 62 // The caller does not own the result. |
| 63 const Rule* GetRule() const; |
| 64 |
| 65 // Adds a sub-key and returns it. The caller does not own the result. |
| 66 LookupKey* AddSubKey(const std::string& sub_key); |
| 67 |
| 68 // Adds a language code key and returns it. The caller does not own the |
| 69 // result. |
| 70 LookupKey* AddLanguageCodeKey(const std::string& language_code); |
| 71 |
| 72 // Returns the lookup key for |sub_key| or NULL. The caller does not own the |
| 73 // result. |
| 74 LookupKey* GetSubKey(const std::string& sub_key) const; |
| 75 |
| 76 // Returns the lookup key for |language_code| or NULL. The caller does not own |
| 77 // the result. |
| 78 LookupKey* GetLanguageCodeKey(const std::string& language_code) const; |
| 79 |
| 80 private: |
| 81 typedef std::map<std::string, LookupKey*> LookupKeys; |
| 82 |
| 83 LookupKey(const std::string& key_value, AddressField level); |
| 84 |
| 85 const std::string value_; |
| 86 const AddressField level_; |
| 87 scoped_ptr<const Rule> rule_; |
| 88 LookupKeys sub_keys_; |
| 89 LookupKeys language_code_keys_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(LookupKey); |
| 92 }; |
| 93 |
| 94 } // namespace addressinput |
| 95 } // namespace i18n |
| 96 |
| 97 #endif // I18N_ADDRESSINPUT_LOOKUP_KEY_H_ |
| OLD | NEW |