2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @brief This file declares API of the bundle C++ library.
26 * @addtogroup CORE_LIB_BUNDLE_CPP_MODULE
43 #define LOG_TAG "BUNDLE"
46 #define EXPORT_API __attribute__((visibility("default")))
49 namespace tizen_base {
52 * @brief The class for bundle APIs.
55 class EXPORT_API Bundle final {
58 * @brief The type for raw bundle.
62 std::pair<std::unique_ptr<bundle_raw, decltype(std::free)*>, int>;
65 * @brief The class for information of keys.
73 * @param[in] handle The handle for type bundle_keyval_t
74 * @param[in] name The key string
76 KeyInfo(const bundle_keyval_t* handle, std::string name);
91 * @brief Copy-constructor.
93 * @param[in] b The object to copy
95 KeyInfo(const KeyInfo& b);
100 * @param[in] b The object to copy
102 KeyInfo& operator = (const KeyInfo& b);
105 * @brief Move-constructor.
107 * @param[in] b The object to move
109 KeyInfo(KeyInfo&& b) noexcept;
114 * @param[in] b The object to move
116 KeyInfo& operator = (KeyInfo&& b) noexcept;
119 * @brief Gets the type of a key-value pair.
123 bundle_type GetType() const;
126 * @brief Determines whether the type of a key-value pair is an array.
128 * @return True when it is an array
130 bool IsArray() const;
133 * @brief Gets the key string.
135 * @return The key string
137 const std::string& GetName() const;
141 std::unique_ptr<Impl> impl_;
145 * @brief Constructor.
151 * @brief Constructor.
153 * @param[in] raw The object for BundleRaw
155 explicit Bundle(BundleRaw raw);
158 * @brief Constructor.
160 * @param[in] raw The string object for raw bundle
162 explicit Bundle(const std::string& raw);
165 * @brief Constructor.
167 * @param[in] b The handle for bundle
168 * @param[in] copy True if this object wants to copy it from the handle
169 * @param[in] own True if this object owns the handle
171 explicit Bundle(bundle* b, bool copy = true, bool own = true);
180 * @brief Copy-constructor.
182 * @param[in] b The object to copy
184 Bundle(const Bundle& b);
189 * @param[in] b The object to copy
191 Bundle& operator = (const Bundle& b);
194 * @brief Move-constructor.
196 * @param[in] b The object to move
198 Bundle(Bundle&& b) noexcept;
203 * @param[in] b The object to move
205 Bundle& operator = (Bundle&& b) noexcept;
208 * @brief Gets keys in bundle object.
210 * @return A string array of object KeyInfo
212 std::vector<KeyInfo> GetKeys();
215 * @brief Adds a string type key-value pair into a bundle.
217 * @param[in] key The string key
218 * @param[in] val The string value
219 * @return The operation result
220 * @retval BUNDLE_ERROR_NONE Success
221 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
222 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
223 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
225 int Add(const std::string& key, const std::string& val);
228 * @brief Adds a string type key-value pair into a bundle.
230 * @param[in] key The string key
231 * @param[in] val The array of strings
232 * @return The operation result
233 * @retval BUNDLE_ERROR_NONE Success
234 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
235 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
236 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
238 int Add(const std::string& key, const std::vector<std::string>& val);
241 * @brief Adds a string type key-value pair into a bundle.
243 * @param[in] key The string key
244 * @param[in] val The array of bytes
245 * @return The operation result
246 * @retval BUNDLE_ERROR_NONE Success
247 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
248 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
249 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
251 int Add(const std::string& key, const std::vector<unsigned char>& val);
254 * @brief Deletes a key-value object with the given key.
256 * @param[in] key The string key
257 * @return The operation result
258 * @retval BUNDLE_ERROR_NONE Success
259 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
260 * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
262 int Delete(const std::string& key);
265 * @brief Gets a string from the key.
267 * @param[in] key The string key
270 std::string GetString(const std::string& key) const;
273 * @brief Gets strings from the key.
275 * @param[in] key The string key
276 * @return The array of strings
278 std::vector<std::string> GetStringArray(const std::string& key) const;
281 * @brief Gets bytes from the key.
283 * @param[in] key The string key
286 std::vector<unsigned char> GetByte(const std::string& key) const;
289 * @brief Converts this object to BundleRaw type.
291 * @return The object of BundleRaw
296 * @brief Gets the count of keys.
300 int GetCount() const;
303 * @brief Gets the data type from the key.
305 * @param[in] key The string key
306 * @return The data type
308 bundle_type GetType(const std::string& key) const;
311 * @brief Gets the handle for bundle APIs.
313 * @return The handle for bundle
315 bundle* GetHandle() const;
318 * @brief Moves this object into the bundle handle.
320 * @return The handle for bundle
326 std::unique_ptr<Impl> impl_;
329 } // namespace tizen_base
335 #endif // BUNDLE_CPP_H_