450ee5b08b2a6cde6c813a6efa3218f959fe2a4b
[platform/upstream/libphonenumber.git] / cpp / src / phonenumbers / geocoding / default_map_storage.cc
1 // Copyright (C) 2012 The Libphonenumber Authors
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 // Author: Patrick Mezard
16
17 #include "phonenumbers/geocoding/default_map_storage.h"
18
19 #include <math.h>
20 #include <utility>
21
22 #include "base/logging.h"
23
24 namespace i18n {
25 namespace phonenumbers {
26
27 using std::map;
28 using std::set;
29 using std::string;
30
31 DefaultMapStorage::DefaultMapStorage() {
32 }
33
34 DefaultMapStorage::~DefaultMapStorage() {
35 }
36
37 int DefaultMapStorage::GetPrefix(int index) const {
38   DCHECK_GE(index, 0);
39   DCHECK_LT(index, static_cast<int>(prefixes_.size()));
40   return prefixes_[index];
41 }
42
43 const string& DefaultMapStorage::GetDescription(int index) const {
44   DCHECK_GE(index, 0);
45   DCHECK_LT(index, static_cast<int>(descriptions_.size()));
46   return descriptions_[index];
47 }
48
49 void DefaultMapStorage::ReadFromMap(const map<int, string>& area_codes) {
50   prefixes_.resize(area_codes.size());
51   descriptions_.resize(area_codes.size());
52   possible_lengths_.clear();
53   int index = 0;
54   for (map<int, string>::const_iterator it = area_codes.begin();
55        it != area_codes.end(); ++it, ++index) {
56     prefixes_[index] = it->first;
57     descriptions_[index] = it->second;
58     possible_lengths_.insert(static_cast<int>(log10(it->first)) + 1);
59   }
60 }
61
62 int DefaultMapStorage::GetNumOfEntries() const {
63   return prefixes_.size();
64 }
65
66 const set<int>& DefaultMapStorage::GetPossibleLengths() const {
67   return possible_lengths_;
68 }
69
70 }  // namespace phonenumbers
71 }  // namespace i18n