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 DefaultMapStorage;
34 class PhoneNumberUtil;
35 struct PrefixDescriptions;
37 // A utility that maps phone number prefixes to a string describing the
38 // geographical area the prefix covers.
44 // Returns the description of the geographical area the number corresponds
45 // to. This method distinguishes the case of an invalid prefix and a prefix
46 // for which the name is not available in the current language. If the
47 // description is not available in the current language an empty string is
48 // returned. If no description was found for the provided number, null is
50 const char* Lookup(const PhoneNumber& number) const;
52 // Creates an AreaCodeMap initialized with area_codes. Note that the
53 // underlying implementation of this method is expensive thus should
54 // not be called by time-critical applications.
56 // area_codes maps phone number prefixes to geographical area description.
57 void ReadAreaCodeMap(const PrefixDescriptions* descriptions);
60 // Does a binary search for value in the provided array from start to end
61 // (inclusive). Returns the position if {@code value} is found; otherwise,
62 // returns the position which has the largest value that is less than value.
63 // This means if value is the smallest, -1 will be returned.
64 int BinarySearch(int start, int end, int64 value) const;
66 const PhoneNumberUtil& phone_util_;
67 scoped_ptr<const DefaultMapStorage> storage_;
69 DISALLOW_COPY_AND_ASSIGN(AreaCodeMap);
72 } // namespace phonenumbers
75 #endif /* I18N_PHONENUMBERS_AREA_CODE_MAP_H_ */