Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / cpp / include / libaddressinput / storage.h
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 // address metadata (e.g. on disk).
17
18 #ifndef I18N_ADDRESSINPUT_STORAGE_H_
19 #define I18N_ADDRESSINPUT_STORAGE_H_
20
21 #include <libaddressinput/callback.h>
22
23 #include <string>
24
25 namespace i18n {
26 namespace addressinput {
27
28 // Stores address metadata. The data must be allocated on the heap, passing
29 // ownership to the called function. Sample usage:
30 //
31 //    class MyStorage : public Storage {
32 //     public:
33 //      virtual void Put(const std::string& key, std::string* data) {
34 //        ...
35 //        delete data;
36 //      }
37 //
38 //      virtual void Get(const std::string& key,
39 //                       const Callback& data_ready) const {
40 //        bool success = ...
41 //        std::string* data = new ...
42 //        data_ready(success, key, data);
43 //      }
44 //    };
45 class Storage {
46  public:
47   typedef i18n::addressinput::Callback<const std::string&,
48                                        std::string*> Callback;
49
50   virtual ~Storage() {}
51
52   // Stores |data| for |key|, where |data| is an object allocated on the heap,
53   // which Storage takes ownership of.
54   virtual void Put(const std::string& key, std::string* data) = 0;
55
56   // Retrieves the data for |key| and invokes the |data_ready| callback.
57   virtual void Get(const std::string& key,
58                    const Callback& data_ready) const = 0;
59 };
60
61 }  // namespace addressinput
62 }  // namespace i18n
63
64 #endif  // I18N_ADDRESSINPUT_STORAGE_H_