Use std::unordered_map instead of std::map
[platform/core/base/bundle.git] / src / bundle-internal.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef BUNDLE_INTERNAL_H_
18 #define BUNDLE_INTERNAL_H_
19
20 #include <list>
21 #include <memory>
22 #include <string>
23 #include <unordered_map>
24 #include <vector>
25
26 #include "include/bundle.h"
27
28 #include "key-info-internal.h"
29
30 namespace tizen_base {
31 namespace internal {
32
33 static const char TAG_IMPORT_EXPORT_CHECK[] = "`zaybxcwdveuftgsh`";
34
35 class Bundle {
36  public:
37   enum Property {
38     Array = BUNDLE_TYPE_ARRAY,
39     Primitive = BUNDLE_TYPE_PRIMITIVE,
40     Measurable = BUNDLE_TYPE_MEASURABLE,
41   };
42
43   enum Type {
44     None = BUNDLE_TYPE_NONE,
45     Any = BUNDLE_TYPE_ANY,
46     String = BUNDLE_TYPE_STR,
47     StringArray = BUNDLE_TYPE_STR_ARRAY,
48     Byte = BUNDLE_TYPE_BYTE,
49     ByteArray = BUNDLE_TYPE_BYTE_ARRAY,
50   };
51
52   Bundle();
53   Bundle(unsigned char* raw, int size, bool base64 = true);
54   Bundle(int argc, char** argv);
55   virtual ~Bundle();
56
57   Bundle(const Bundle& b);
58   Bundle& operator = (const Bundle& b);
59   Bundle(Bundle&& b) noexcept;
60   Bundle& operator = (Bundle&& b) noexcept;
61
62   bool operator == (const Bundle& b);
63
64   void Remove(const std::string& key);
65   void Add(std::shared_ptr<KeyInfo> key_info);
66   void Set(const std::string& key, int index, std::vector<unsigned char> value);
67
68   std::shared_ptr<KeyInfo>& Get(const std::string& key);
69   int GetSize();
70   int GetType(const std::string& key);
71
72   unsigned char* Encode();
73   unsigned char* EncodeRaw(int* size);
74   int DecodeRaw(unsigned char* raw, int size);
75   const std::unordered_map<std::string, std::shared_ptr<KeyInfo>>& GetMap() const;
76   std::vector<std::string> Export();
77
78  private:
79   int Decode(unsigned char* raw, int size);
80   int Import(int argc, char** argv);
81
82  private:
83   std::unordered_map<std::string, std::shared_ptr<KeyInfo>> map_;
84   std::list<std::shared_ptr<KeyInfo>> list_;
85 };
86
87 }  // namespace internal
88 }  // namespace tizen_base
89
90 #endif  // BUNDLE_INTERNAL_H_