1 // Copyright (C) 2012 The Libphonenumber Authors
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // Author: Patrick Mezard
17 #include "phonenumbers/geocoding/default_map_storage.h"
22 #include "base/logging.h"
25 namespace phonenumbers {
31 DefaultMapStorage::DefaultMapStorage() {
34 DefaultMapStorage::~DefaultMapStorage() {
37 int DefaultMapStorage::GetPrefix(int index) const {
39 DCHECK_LT(index, static_cast<int>(prefixes_.size()));
40 return prefixes_[index];
43 const string& DefaultMapStorage::GetDescription(int index) const {
45 DCHECK_LT(index, static_cast<int>(descriptions_.size()));
46 return descriptions_[index];
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();
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);
62 int DefaultMapStorage::GetNumOfEntries() const {
63 return prefixes_.size();
66 const set<int>& DefaultMapStorage::GetPossibleLengths() const {
67 return possible_lengths_;
70 } // namespace phonenumbers