1 // Copyright (C) 2012 The Libphonenumber Authors 2 // 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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 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. 14 // 15 // Author: Patrick Mezard 16 // 17 // Default class for storing area codes. 18 19 #ifndef I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ 20 #define I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ 21 22 #include "phonenumbers/base/basictypes.h" 23 24 namespace i18n { 25 namespace phonenumbers { 26 27 struct PrefixDescriptions; 28 29 // Default area code map storage strategy that is used for data not 30 // containing description duplications. It is mainly intended to avoid 31 // the overhead of the string table management when it is actually 32 // unnecessary (i.e no string duplication). 33 class DefaultMapStorage { 34 public: 35 DefaultMapStorage(); 36 virtual ~DefaultMapStorage(); 37 38 // Returns the phone number prefix located at the provided index. 39 int32 GetPrefix(int index) const; 40 41 // Gets the description corresponding to the phone number prefix located 42 // at the provided index. If the description is not available in the current 43 // language an empty string is returned. 44 const char* GetDescription(int index) const; 45 46 // Sets the internal state of the underlying storage implementation from the 47 // provided area_codes that maps phone number prefixes to description strings. 48 void ReadFromMap(const PrefixDescriptions* descriptions); 49 50 // Returns the number of entries contained in the area code map. 51 int GetNumOfEntries() const; 52 53 // Returns an array containing the possible lengths of prefixes sorted in 54 // ascending order. 55 const int* GetPossibleLengths() const; 56 57 // Returns the number of elements in GetPossibleLengths() array. 58 int GetPossibleLengthsSize() const; 59 60 private: 61 // Sorted sequence of phone number prefixes. 62 const int32* prefixes_; 63 int prefixes_size_; 64 // Sequence of prefix descriptions, in the same order than prefixes_. 65 const char** descriptions_; 66 // Sequence of unique possible lengths in ascending order. 67 const int32* possible_lengths_; 68 int possible_lengths_size_; 69 70 DISALLOW_COPY_AND_ASSIGN(DefaultMapStorage); 71 }; 72 73 } // namespace phonenumbers 74 } // namespace i18n 75 76 #endif /* I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ */ 77