2 * Copyright (c) 2019 - 2020 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
39 #define EXPORT_API __attribute__((visibility("default")))
42 namespace tizen_base {
45 * @brief The class for bundle APIs.
48 class EXPORT_API Bundle final {
51 * @brief The type for raw bundle.
55 std::pair<std::unique_ptr<bundle_raw, decltype(std::free)*>, int>;
58 * @brief The class for information of keys.
66 * @param[in] handle The handle for type bundle_keyval_t
67 * @param[in] name The key string
68 * @param[in] own True if this object owns the handle
70 KeyInfo(const bundle_keyval_t* handle, std::string name, bool own = false);
79 * @brief Copy-constructor.
81 * @param[in] b The object to copy
83 KeyInfo(const KeyInfo& b);
88 * @param[in] b The object to copy
90 KeyInfo& operator = (const KeyInfo& b);
93 * @brief Move-constructor.
95 * @param[in] b The object to move
97 KeyInfo(KeyInfo&& b) noexcept;
102 * @param[in] b The object to move
104 KeyInfo& operator = (KeyInfo&& b) noexcept;
107 * @brief Gets the type of a key-value pair.
111 bundle_type GetType() const;
114 * @brief Determines whether the type of a key-value pair is an array.
116 * @return True when it is an array
118 bool IsArray() const;
121 * @brief Gets the key string.
123 * @return The key string
125 const std::string& GetName() const;
129 std::unique_ptr<Impl> impl_;
133 * @brief Constructor.
139 * @brief Constructor.
141 * @param[in] raw The object for BundleRaw
142 * @param[in] base64 @c true, @a raw is the encoded raw data using base64-encoding
144 explicit Bundle(BundleRaw raw, bool base64 = true);
147 * @brief Constructor.
149 * @param[in] raw The string object for raw bundle
151 explicit Bundle(const std::string& raw);
154 * @brief Constructor.
156 * @param[in] b The handle for bundle
157 * @param[in] copy True if this object wants to copy it from the handle
158 * @param[in] own True if this object owns the handle
160 explicit Bundle(bundle* b, bool copy = true, bool own = true);
169 * @brief Copy-constructor.
171 * @param[in] b The object to copy
173 Bundle(const Bundle& b);
178 * @param[in] b The object to copy
180 Bundle& operator = (const Bundle& b);
183 * @brief Move-constructor.
185 * @param[in] b The object to move
187 Bundle(Bundle&& b) noexcept;
192 * @param[in] b The object to move
194 Bundle& operator = (Bundle&& b) noexcept;
197 * @brief Check the bundle is empty or not.
199 * @return true if the bundle is empty
201 bool IsEmpty() const noexcept;
204 * @brief Gets keys in bundle object.
206 * @return A string array of object KeyInfo
208 std::vector<KeyInfo> GetKeys();
211 * @brief Adds a string type key-value pair into a bundle.
213 * @param[in] key The string key
214 * @param[in] val The string value
215 * @return The operation result
216 * @retval BUNDLE_ERROR_NONE Success
217 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
218 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
219 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
221 int Add(const std::string& key, const std::string& val);
224 * @brief Adds a string type key-value pair into a bundle.
226 * @param[in] key The string key
227 * @param[in] val The array of strings
228 * @return The operation result
229 * @retval BUNDLE_ERROR_NONE Success
230 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
231 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
232 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
234 int Add(const std::string& key, const std::vector<std::string>& val);
237 * @brief Adds a string type key-value pair into a bundle.
239 * @param[in] key The string key
240 * @param[in] val The array of bytes
241 * @return The operation result
242 * @retval BUNDLE_ERROR_NONE Success
243 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
244 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
245 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
247 int Add(const std::string& key, const std::vector<unsigned char>& val);
250 * @brief Deletes a key-value object with the given key.
252 * @param[in] key The string key
253 * @return The operation result
254 * @retval BUNDLE_ERROR_NONE Success
255 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
256 * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
258 int Delete(const std::string& key);
261 * @brief Gets a string from the key.
263 * @param[in] key The string key
266 std::string GetString(const std::string& key) const;
269 * @brief Gets strings from the key.
271 * @param[in] key The string key
272 * @return The array of strings
274 std::vector<std::string> GetStringArray(const std::string& key) const;
277 * @brief Gets bytes from the key.
279 * @param[in] key The string key
282 std::vector<unsigned char> GetByte(const std::string& key) const;
285 * @brief Converts this object to BundleRaw type.
287 * @param[in] base64 @c true, the BundleRaw will be encoded using base64-encoding.
288 * @return The object of BundleRaw
290 BundleRaw ToRaw(bool base64 = true);
293 * @brief Gets the count of keys.
297 int GetCount() const;
300 * @brief Gets the data type from the key.
302 * @param[in] key The string key
303 * @return The data type
305 bundle_type GetType(const std::string& key) const;
308 * @brief Gets the handle for bundle APIs.
310 * @return The handle for bundle
312 bundle* GetHandle() const;
315 * @brief Moves this object into the bundle handle.
317 * @return The handle for bundle
322 * @brief Exports bundle to an argument vector.
324 * @return The argument vector
326 std::vector<std::string> Export() const;
330 std::unique_ptr<Impl> impl_;
333 } // namespace tizen_base
339 #endif // BUNDLE_CPP_H_