12dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Copyright (C) 2012 The Libphonenumber Authors 22dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// 32dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Licensed under the Apache License, Version 2.0 (the "License"); 42dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// you may not use this file except in compliance with the License. 52dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// You may obtain a copy of the License at 62dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// 72dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// http://www.apache.org/licenses/LICENSE-2.0 82dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// 92dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Unless required by applicable law or agreed to in writing, software 102dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// distributed under the License is distributed on an "AS IS" BASIS, 112dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// See the License for the specific language governing permissions and 132dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// limitations under the License. 142dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// 152dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Author: Patrick Mezard 162dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// 172dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Default class for storing area codes. 182dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 192dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com#ifndef I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ 202dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com#define I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ 212dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 22af4a2ce290b619b39c2cb2a682ea4d7746d3fb21philip.liard@gmail.com#include "phonenumbers/base/basictypes.h" 232dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 242dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.comnamespace i18n { 252dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.comnamespace phonenumbers { 262dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 27b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.pengstruct PrefixDescriptions; 282dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 292dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// Default area code map storage strategy that is used for data not 302dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// containing description duplications. It is mainly intended to avoid 312dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// the overhead of the string table management when it is actually 322dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com// unnecessary (i.e no string duplication). 33b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.pengclass DefaultMapStorage { 342dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com public: 352dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com DefaultMapStorage(); 362dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com virtual ~DefaultMapStorage(); 372dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 38b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Returns the phone number prefix located at the provided index. 39b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng int32 GetPrefix(int index) const; 40b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng 41b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Gets the description corresponding to the phone number prefix located 42b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // at the provided index. If the description is not available in the current 43b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // language an empty string is returned. 44b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng const char* GetDescription(int index) const; 45b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng 46b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Sets the internal state of the underlying storage implementation from the 47b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // provided area_codes that maps phone number prefixes to description strings. 48b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng void ReadFromMap(const PrefixDescriptions* descriptions); 49b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng 50b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Returns the number of entries contained in the area code map. 51b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng int GetNumOfEntries() const; 52b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng 53b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Returns an array containing the possible lengths of prefixes sorted in 54b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // ascending order. 55b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng const int* GetPossibleLengths() const; 56b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng 57b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng // Returns the number of elements in GetPossibleLengths() array. 58b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng int GetPossibleLengthsSize() const; 592dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 602dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com private: 612dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com // Sorted sequence of phone number prefixes. 62b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng const int32* prefixes_; 63b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng int prefixes_size_; 642dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com // Sequence of prefix descriptions, in the same order than prefixes_. 65b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng const char** descriptions_; 662dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com // Sequence of unique possible lengths in ascending order. 67b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng const int32* possible_lengths_; 68b32eeb5f079c0b91bc073455657cfc3003df2608jia.shao.peng int possible_lengths_size_; 692dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 702dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com DISALLOW_COPY_AND_ASSIGN(DefaultMapStorage); 712dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com}; 722dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 732dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com} // namespace phonenumbers 742dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com} // namespace i18n 752dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com 762dbe1d8526f8d057898bc02ed3185a84f82cbb9aphilip.liard@gmail.com#endif /* I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ */ 77