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
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
69 KeyInfo(const bundle_keyval_t* handle, std::string name);
78 * @brief Copy-constructor.
80 * @param[in] b The object to copy
82 KeyInfo(const KeyInfo& b);
87 * @param[in] b The object to copy
89 KeyInfo& operator = (const KeyInfo& b);
92 * @brief Move-constructor.
94 * @param[in] b The object to move
96 KeyInfo(KeyInfo&& b) noexcept;
101 * @param[in] b The object to move
103 KeyInfo& operator = (KeyInfo&& b) noexcept;
106 * @brief Gets the type of a key-value pair.
110 bundle_type GetType() const;
113 * @brief Determines whether the type of a key-value pair is an array.
115 * @return True when it is an array
117 bool IsArray() const;
120 * @brief Gets the key string.
122 * @return The key string
124 const std::string& GetName() const;
128 std::unique_ptr<Impl> impl_;
132 * @brief Constructor.
138 * @brief Constructor.
140 * @param[in] raw The object for BundleRaw
142 explicit Bundle(BundleRaw raw);
145 * @brief Constructor.
147 * @param[in] raw The string object for raw bundle
149 explicit Bundle(const std::string& raw);
152 * @brief Constructor.
154 * @param[in] b The handle for bundle
155 * @param[in] copy True if this object wants to copy it from the handle
156 * @param[in] own True if this object owns the handle
158 explicit Bundle(bundle* b, bool copy = true, bool own = true);
167 * @brief Copy-constructor.
169 * @param[in] b The object to copy
171 Bundle(const Bundle& b);
176 * @param[in] b The object to copy
178 Bundle& operator = (const Bundle& b);
181 * @brief Move-constructor.
183 * @param[in] b The object to move
185 Bundle(Bundle&& b) noexcept;
190 * @param[in] b The object to move
192 Bundle& operator = (Bundle&& b) noexcept;
195 * @brief Check the bundle is empty or not.
197 * @return true if the bundle is empty
199 bool IsEmpty() const noexcept;
202 * @brief Gets keys in bundle object.
204 * @return A string array of object KeyInfo
206 std::vector<KeyInfo> GetKeys();
209 * @brief Adds a string type key-value pair into a bundle.
211 * @param[in] key The string key
212 * @param[in] val The string value
213 * @return The operation result
214 * @retval BUNDLE_ERROR_NONE Success
215 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
216 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
217 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
219 int Add(const std::string& key, const std::string& val);
222 * @brief Adds a string type key-value pair into a bundle.
224 * @param[in] key The string key
225 * @param[in] val The array of strings
226 * @return The operation result
227 * @retval BUNDLE_ERROR_NONE Success
228 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
229 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
230 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
232 int Add(const std::string& key, const std::vector<std::string>& val);
235 * @brief Adds a string type key-value pair into a bundle.
237 * @param[in] key The string key
238 * @param[in] val The array of bytes
239 * @return The operation result
240 * @retval BUNDLE_ERROR_NONE Success
241 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
242 * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
243 * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
245 int Add(const std::string& key, const std::vector<unsigned char>& val);
248 * @brief Deletes a key-value object with the given key.
250 * @param[in] key The string key
251 * @return The operation result
252 * @retval BUNDLE_ERROR_NONE Success
253 * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
254 * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
256 int Delete(const std::string& key);
259 * @brief Gets a string from the key.
261 * @param[in] key The string key
264 std::string GetString(const std::string& key) const;
267 * @brief Gets strings from the key.
269 * @param[in] key The string key
270 * @return The array of strings
272 std::vector<std::string> GetStringArray(const std::string& key) const;
275 * @brief Gets bytes from the key.
277 * @param[in] key The string key
280 std::vector<unsigned char> GetByte(const std::string& key) const;
283 * @brief Converts this object to BundleRaw type.
285 * @return The object of BundleRaw
290 * @brief Gets the count of keys.
294 int GetCount() const;
297 * @brief Gets the data type from the key.
299 * @param[in] key The string key
300 * @return The data type
302 bundle_type GetType(const std::string& key) const;
305 * @brief Gets the handle for bundle APIs.
307 * @return The handle for bundle
309 bundle* GetHandle() const;
312 * @brief Moves this object into the bundle handle.
314 * @return The handle for bundle
320 std::unique_ptr<Impl> impl_;
323 } // namespace tizen_base
329 #endif // BUNDLE_CPP_H_