OLD | NEW |
| (Empty) |
1 // Copyright (C) 2013 Google Inc. | |
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 // The interface to be implemented by the user of the library to enable storing | |
16 // the downloaded validation rules (e.g. on disk). | |
17 | |
18 #ifndef I18N_ADDRESSINPUT_STORAGE_H_ | |
19 #define I18N_ADDRESSINPUT_STORAGE_H_ | |
20 | |
21 #include <libaddressinput/callback.h> | |
22 #include <libaddressinput/util/scoped_ptr.h> | |
23 | |
24 #include <string> | |
25 | |
26 namespace i18n { | |
27 namespace addressinput { | |
28 | |
29 // Stores downloaded validation rules. Sample usage: | |
30 // class MyStorage : public Storage { | |
31 // public: | |
32 // virtual void Put(const std::string& key, const std::string& data) { | |
33 // ... | |
34 // } | |
35 // | |
36 // virtual void Get(const std::string& key, | |
37 // scoped_ptr<Callback> data_ready) const { | |
38 // bool success = ... | |
39 // std::string data = ... | |
40 // (*data_ready)(success, key, data); | |
41 // } | |
42 // }; | |
43 class Storage { | |
44 public: | |
45 typedef i18n::addressinput::Callback<void(std::string, std::string)> Callback; | |
46 | |
47 virtual ~Storage() {} | |
48 | |
49 // Stores |data| for |key|. | |
50 virtual void Put(const std::string& key, scoped_ptr<std::string> data) = 0; | |
51 | |
52 // Retrieves the data for |key| and invokes the |data_ready| callback. | |
53 virtual void Get(const std::string& key, | |
54 scoped_ptr<Callback> data_ready) const = 0; | |
55 }; | |
56 | |
57 } // namespace addressinput | |
58 } // namespace i18n | |
59 | |
60 #endif // I18N_ADDRESSINPUT_STORAGE_H_ | |
OLD | NEW |