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 #ifndef I18N_PHONENUMBERS_AREA_CODE_MAP_H_
18 #define I18N_PHONENUMBERS_AREA_CODE_MAP_H_
23 #include "base/basictypes.h"
24 #include "base/memory/scoped_ptr.h"
27 namespace phonenumbers {
32 class AreaCodeMapStorageStrategy;
34 class PhoneNumberUtil;
36 // A utility that maps phone number prefixes to a string describing the
37 // geographical area the prefix covers.
43 // Returns the description of the geographical area the number corresponds
44 // to. This method distinguishes the case of an invalid prefix and a prefix
45 // for which the name is not available in the current language. If the
46 // description is not available in the current language an empty string is
47 // returned. If no description was found for the provided number, null is
49 const string* Lookup(const PhoneNumber& number) const;
51 // Creates an AreaCodeMap initialized with area_codes. Note that the
52 // underlying implementation of this method is expensive thus should
53 // not be called by time-critical applications.
55 // area_codes maps phone number prefixes to geographical area description.
56 void ReadAreaCodeMap(const map<int, string>& area_codes);
59 AreaCodeMapStorageStrategy* CreateDefaultMapStorage() const;
61 // Does a binary search for value in the provided array from start to end
62 // (inclusive). Returns the position if {@code value} is found; otherwise,
63 // returns the position which has the largest value that is less than value.
64 // This means if value is the smallest, -1 will be returned.
65 int BinarySearch(int start, int end, int64 value) const;
67 const PhoneNumberUtil& phone_util_;
68 scoped_ptr<const AreaCodeMapStorageStrategy> storage_;
70 DISALLOW_COPY_AND_ASSIGN(AreaCodeMap);
73 } // namespace phonenumbers
76 #endif /* I18N_PHONENUMBERS_AREA_CODE_MAP_H_ */