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 #include "ruleset.h" | |
16 | |
17 #include <libaddressinput/util/scoped_ptr.h> | |
18 | |
19 #include <cassert> | |
20 #include <cstddef> | |
21 #include <map> | |
22 #include <string> | |
23 #include <utility> | |
24 | |
25 #include "rule.h" | |
26 #include "util/stl_util.h" | |
27 | |
28 namespace i18n { | |
29 namespace addressinput { | |
30 | |
31 Ruleset::Ruleset(scoped_ptr<Rule> rule) | |
32 : rule_(rule.Pass()), | |
33 sub_regions_(), | |
34 language_codes_() { | |
35 assert(rule_ != NULL); | |
36 } | |
37 | |
38 Ruleset::~Ruleset() { | |
39 STLDeleteContainerPairSecondPointers( | |
40 sub_regions_.begin(), sub_regions_.end()); | |
41 STLDeleteContainerPairSecondPointers( | |
42 language_codes_.begin(), language_codes_.end()); | |
43 } | |
44 | |
45 const Rule* Ruleset::GetRule() const { | |
46 return rule_.get(); | |
47 } | |
48 | |
49 Ruleset* Ruleset::AddSubRegion(const std::string& sub_region, | |
50 scoped_ptr<Rule> rule) { | |
51 assert(sub_regions_.find(sub_region) == sub_regions_.end()); | |
Evan Stade
2014/01/06 22:54:19
seems like these asserts should be debug only
please use gerrit instead
2014/01/06 23:44:35
These asserts do not trigger in Release mode (I've
| |
52 Ruleset* sub_region_rules = new Ruleset(rule.Pass()); | |
53 sub_regions_.insert(std::make_pair(sub_region, sub_region_rules)); | |
54 return sub_region_rules; | |
55 } | |
56 | |
57 void Ruleset::AddLanguageCode(const std::string& language_code, | |
58 scoped_ptr<Rule> rule) { | |
59 assert(language_codes_.find(language_code) == language_codes_.end()); | |
60 language_codes_.insert(std::make_pair(language_code, rule.release())); | |
61 } | |
62 | |
63 Ruleset* Ruleset::GetSubRegion(const std::string& sub_region) const { | |
64 std::map<std::string, Ruleset*>::const_iterator it = | |
65 sub_regions_.find(sub_region); | |
66 return it == sub_regions_.end() ? NULL : it->second; | |
67 } | |
68 | |
69 const Rule* Ruleset::GetLanguageCode(const std::string& language_code) const { | |
70 std::map<std::string, const Rule*>::const_iterator it = | |
71 language_codes_.find(language_code); | |
72 return it == language_codes_.end() ? NULL : it->second; | |
73 } | |
74 | |
75 } // namespace addressinput | |
76 } // namespace i18n | |
OLD | NEW |