b4b9631c015aff27b47d923b3119e630ebeb7d90
[platform/upstream/libphonenumber.git] / cpp / src / phonenumbers / geocoding / default_map_storage.h
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 <map>
23 #include <set>
24 #include <string>
25 #include <vector>
26
27 #include "base/basictypes.h"
28 #include "phonenumbers/geocoding/area_code_map_storage_strategy.h"
29
30 namespace i18n {
31 namespace phonenumbers {
32
33 using std::map;
34 using std::set;
35 using std::string;
36 using std::vector;
37
38 // Default area code map storage strategy that is used for data not
39 // containing description duplications. It is mainly intended to avoid
40 // the overhead of the string table management when it is actually
41 // unnecessary (i.e no string duplication).
42 class DefaultMapStorage : public AreaCodeMapStorageStrategy {
43  public:
44   DefaultMapStorage();
45   virtual ~DefaultMapStorage();
46
47   virtual int GetPrefix(int index) const;
48   virtual const string& GetDescription(int index) const;
49   virtual void ReadFromMap(const map<int, string>& area_codes);
50   virtual int GetNumOfEntries() const;
51   virtual const set<int>& GetPossibleLengths() const;
52
53  private:
54   // Sorted sequence of phone number prefixes.
55   vector<int> prefixes_;
56   // Sequence of prefix descriptions, in the same order than prefixes_.
57   vector<string> descriptions_;
58   // Sequence of unique possible lengths in ascending order.
59   set<int> possible_lengths_;
60
61   DISALLOW_COPY_AND_ASSIGN(DefaultMapStorage);
62 };
63
64 }  // namespace phonenumbers
65 }  // namespace i18n
66
67 #endif /* I18N_PHONENUMBERS_DEFAULT_MAP_STORAGE_H_ */