11767c5feSopenharmony_ci// Copyright (C) 2012 The Libphonenumber Authors
21767c5feSopenharmony_ci//
31767c5feSopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
41767c5feSopenharmony_ci// you may not use this file except in compliance with the License.
51767c5feSopenharmony_ci// You may obtain a copy of the License at
61767c5feSopenharmony_ci//
71767c5feSopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0
81767c5feSopenharmony_ci//
91767c5feSopenharmony_ci// Unless required by applicable law or agreed to in writing, software
101767c5feSopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
111767c5feSopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121767c5feSopenharmony_ci// See the License for the specific language governing permissions and
131767c5feSopenharmony_ci// limitations under the License.
141767c5feSopenharmony_ci//
151767c5feSopenharmony_ci// Author: Patrick Mezard
161767c5feSopenharmony_ci
171767c5feSopenharmony_ci#ifndef I18N_PHONENUMBERS_AREA_CODE_MAP_H_
181767c5feSopenharmony_ci#define I18N_PHONENUMBERS_AREA_CODE_MAP_H_
191767c5feSopenharmony_ci
201767c5feSopenharmony_ci#include <cstdint>
211767c5feSopenharmony_ci#include <map>
221767c5feSopenharmony_ci#include <string>
231767c5feSopenharmony_ci
241767c5feSopenharmony_ci#include "phonenumbers/base/basictypes.h"
251767c5feSopenharmony_ci#include "phonenumbers/base/memory/scoped_ptr.h"
261767c5feSopenharmony_ci
271767c5feSopenharmony_cinamespace i18n {
281767c5feSopenharmony_cinamespace phonenumbers {
291767c5feSopenharmony_ci
301767c5feSopenharmony_ciusing std::map;
311767c5feSopenharmony_ciusing std::string;
321767c5feSopenharmony_ci
331767c5feSopenharmony_ciclass DefaultMapStorage;
341767c5feSopenharmony_ciclass PhoneNumber;
351767c5feSopenharmony_ciclass PhoneNumberUtil;
361767c5feSopenharmony_cistruct PrefixDescriptions;
371767c5feSopenharmony_ci
381767c5feSopenharmony_ci// A utility that maps phone number prefixes to a string describing the
391767c5feSopenharmony_ci// geographical area the prefix covers.
401767c5feSopenharmony_ciclass AreaCodeMap {
411767c5feSopenharmony_ci public:
421767c5feSopenharmony_ci  AreaCodeMap();
431767c5feSopenharmony_ci
441767c5feSopenharmony_ci  // This type is neither copyable nor movable.
451767c5feSopenharmony_ci  AreaCodeMap(const AreaCodeMap&) = delete;
461767c5feSopenharmony_ci  AreaCodeMap& operator=(const AreaCodeMap&) = delete;
471767c5feSopenharmony_ci
481767c5feSopenharmony_ci  ~AreaCodeMap();
491767c5feSopenharmony_ci
501767c5feSopenharmony_ci  // Returns the description of the geographical area the number corresponds
511767c5feSopenharmony_ci  // to. This method distinguishes the case of an invalid prefix and a prefix
521767c5feSopenharmony_ci  // for which the name is not available in the current language. If the
531767c5feSopenharmony_ci  // description is not available in the current language an empty string is
541767c5feSopenharmony_ci  // returned. If no description was found for the provided number, null is
551767c5feSopenharmony_ci  // returned.
561767c5feSopenharmony_ci  const char* Lookup(const PhoneNumber& number) const;
571767c5feSopenharmony_ci
581767c5feSopenharmony_ci  // Creates an AreaCodeMap initialized with area_codes. Note that the
591767c5feSopenharmony_ci  // underlying implementation of this method is expensive thus should
601767c5feSopenharmony_ci  // not be called by time-critical applications.
611767c5feSopenharmony_ci  //
621767c5feSopenharmony_ci  // area_codes maps phone number prefixes to geographical area description.
631767c5feSopenharmony_ci  void ReadAreaCodeMap(const PrefixDescriptions* descriptions);
641767c5feSopenharmony_ci
651767c5feSopenharmony_ci private:
661767c5feSopenharmony_ci  // Does a binary search for value in the provided array from start to end
671767c5feSopenharmony_ci  // (inclusive). Returns the position if {@code value} is found; otherwise,
681767c5feSopenharmony_ci  // returns the position which has the largest value that is less than value.
691767c5feSopenharmony_ci  // This means if value is the smallest, -1 will be returned.
701767c5feSopenharmony_ci  int BinarySearch(int start, int end, int64_t value) const;
711767c5feSopenharmony_ci
721767c5feSopenharmony_ci  const PhoneNumberUtil& phone_util_;
731767c5feSopenharmony_ci  scoped_ptr<const DefaultMapStorage> storage_;
741767c5feSopenharmony_ci};
751767c5feSopenharmony_ci
761767c5feSopenharmony_ci}  // namespace phonenumbers
771767c5feSopenharmony_ci}  // namespace i18n
781767c5feSopenharmony_ci
791767c5feSopenharmony_ci#endif /* I18N_PHONENUMBERS_AREA_CODE_MAP_H_ */
80