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 <cstdint> 23 #include "phonenumbers/base/basictypes.h" 24 25 namespace i18n { 26 namespace phonenumbers { 27 28 struct PrefixDescriptions; 29 30 // Default area code map storage strategy that is used for data not 31 // containing description duplications. It is mainly intended to avoid 32 // the overhead of the string table management when it is actually 33 // unnecessary (i.e no string duplication). 34 class DefaultMapStorage { 35 public: 36 DefaultMapStorage(); 37 38 // This type is neither copyable nor movable. 39 DefaultMapStorage(const DefaultMapStorage&) = delete; 40 DefaultMapStorage& operator=(const DefaultMapStorage&) = delete; 41 42 virtual ~DefaultMapStorage(); 43 44 // Returns the phone number prefix located at the provided index. 45 int32_t GetPrefix(int index) const; 46 47 // Gets the description corresponding to the phone number prefix located 48 // at the provided index. If the description is not available in the current 49 // language an empty string is returned. 50 const char* GetDescription(int index) const; 51 52 // Sets the internal state of the underlying storage implementation from the 53 // provided area_codes that maps phone number prefixes to description strings. 54 void ReadFromMap(const PrefixDescriptions* descriptions); 55 56 // Returns the number of entries contained in the area code map. 57 int GetNumOfEntries() const; 58 59 // Returns an array containing the possible lengths of prefixes sorted in 60 // ascending order. 61 const int* GetPossibleLengths() const; 62 63 // Returns the number of elements in GetPossibleLengths() array. 64 int GetPossibleLengthsSize() const; 65 66 private: 67 // Sorted sequence of phone number prefixes. 68 const int32_t* prefixes_; 69 int prefixes_size_; 70 // Sequence of prefix descriptions, in the same order than prefixes_. 71 const char** descriptions_; 72 // Sequence of unique possible lengths in ascending order. 73 const int32_t* possible_lengths_; 74 int possible_lengths_size_; 75 }; 76 77 } // namespace phonenumbers 78 } // namespace i18n 79 80 #endif /* I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ */ 81