OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (C) 2014 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_RULESET_H_ | |
16 #define I18N_ADDRESSINPUT_RULESET_H_ | |
17 | |
18 #include <libaddressinput/util/basictypes.h> | |
19 #include <libaddressinput/util/scoped_ptr.h> | |
20 | |
21 #include <map> | |
22 #include <string> | |
23 | |
24 namespace i18n { | |
25 namespace addressinput { | |
26 | |
27 class Rule; | |
28 | |
29 // A recursive data structure that stores a set of rules for a region. Can store | |
30 // the rules for a country, its administrative areas, localities, and dependent | |
31 // localities, in addition to the language-specific rules. | |
32 // | |
33 // Example for Canada and some of its provinces: | |
34 // CA-->fr | |
35 // | | |
36 // ------------------------------------- | |
37 // | | | | | | |
38 // v v v v v | |
39 // AB-->fr BC-->fr MB-->fr NB-->fr NL-->fr | |
40 // | |
41 // The rules in Canada are in English by default. Each rule also has a French | |
42 // language version. | |
43 class Ruleset { | |
44 public: | |
45 // Builds a ruleset with a region-wide |rule| in the default language of the | |
46 // country. The |rule| should not be NULL. | |
47 explicit Ruleset(scoped_ptr<Rule> rule); | |
48 | |
49 ~Ruleset(); | |
50 | |
51 // Returns the region-wide rule in the default language of the country. | |
52 const Rule& rule() const { return *rule_.get(); } | |
53 | |
54 // Adds and returns a ruleset for |sub_region| with the subregion-wide |rule| | |
55 // in the default language of the country. The caller does not own the result. | |
56 Ruleset* AddSubRegion(const std::string& sub_region, scoped_ptr<Rule> rule); | |
57 | |
58 // Adds a language-specific |rule| for |language_code| for this region. | |
59 void AddLanguageCode(const std::string& language_code, scoped_ptr<Rule> rule); | |
60 | |
61 // Returns the set of rules for |sub_region|. The result can be NULL. The | |
62 // caller does not own the result. | |
63 Ruleset* GetSubRegion(const std::string& sub_region) const; | |
Evan Stade
2014/01/08 21:08:59
imo, call these fns Add/GetSubRegionRuleset, Add/G
please use gerrit instead
2014/01/09 00:38:11
Done.
| |
64 | |
65 // Returns the language-specific rule for |language_code|. The result can be | |
66 // NULL. The caller does not own the result. | |
67 const Rule* GetLanguageCode(const std::string& language_code) const; | |
68 | |
69 private: | |
70 // The region-wide rule in the default language of the country. | |
71 scoped_ptr<const Rule> rule_; | |
72 | |
73 // Owned rulesets for sub-regions. | |
74 std::map<std::string, Ruleset*> sub_regions_; | |
75 | |
76 // Owned language-specific rules for the region. | |
77 std::map<std::string, const Rule*> language_codes_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(Ruleset); | |
80 }; | |
81 | |
82 } // namespace addressinput | |
83 } // namespace i18n | |
84 | |
85 #endif // I18N_ADDRESSINPUT_RULESET_H_ | |
OLD | NEW |