Bundle::Bundle()
: impl_(new Impl(this)) {
impl_->handle_ = bundle_create();
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
Bundle::Bundle(BundleRaw raw)
: impl_(new Impl(this)) {
impl_->handle_ = bundle_decode(raw.first.get(), raw.second);
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
Bundle::Bundle(const std::string& raw)
: impl_(new Impl(this)) {
impl_->handle_ = bundle_decode(reinterpret_cast<const bundle_raw*>(
raw.c_str()), raw.length());
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
Bundle::Bundle(bundle* b, bool copy, bool own)
: impl_(new Impl(this, copy, own)) {
- if (!impl_->copy_)
+ if (b == nullptr)
+ throw std::invalid_argument("b cannot be null");
+
+ if (!impl_->copy_) {
impl_->handle_ = b;
- else
+ } else {
impl_->handle_ = bundle_dup(b);
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
+ }
}
Bundle::~Bundle() {
Bundle::Bundle(const Bundle& b)
: impl_(new Impl(this)) {
impl_->handle_ = bundle_dup(b.impl_->handle_);
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
Bundle::KeyInfo::KeyInfo(const bundle_keyval_t* handle, std::string name)
: impl_(new Impl(this)) {
impl_->handle_ = bundle_keyval_dup(k.impl_->handle_);
impl_->name_ = k.impl_->name_;
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
Bundle::KeyInfo& Bundle::KeyInfo::operator = (const Bundle::KeyInfo& k) {
if (this != &k) {
impl_->handle_ = bundle_keyval_dup(k.impl_->handle_);
impl_->name_ = k.impl_->name_;
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
return *this;
}
Bundle& Bundle::operator = (const Bundle& b) {
if (this != &b) {
impl_->handle_ = bundle_dup(b.impl_->handle_);
+ if (impl_->handle_ == nullptr)
+ throw std::bad_alloc();
}
return *this;
}
}
int Bundle::Add(const std::string& key, const std::string& val) {
- return bundle_add_str(impl_->handle_, key.c_str(), val.c_str());
+ int ret = bundle_add_str(impl_->handle_, key.c_str(), val.c_str());
+ if (ret != BUNDLE_ERROR_NONE)
+ LOGE("Add fail key(%s), val(%s), ret(%d)", key.c_str(), val.c_str(), ret);
+ return ret;
}
int Bundle::Add(const std::string& key, const std::vector<std::string>& val) {
v.push_back(i.c_str());
}
- return bundle_add_str_array(impl_->handle_, key.c_str(), v.data(), v.size());
+ int ret = bundle_add_str_array(
+ impl_->handle_, key.c_str(), v.data(), v.size());
+ if (ret != BUNDLE_ERROR_NONE)
+ LOGE("Add fail key(%s), ret(%d)", key.c_str(), ret);
+
+ return ret;
}
int Bundle::Add(const std::string& key, const std::vector<unsigned char>& val) {
- return bundle_add_byte(impl_->handle_, key.c_str(), val.data(), val.size());
+ int ret = bundle_add_byte(impl_->handle_, key.c_str(), val.data(), val.size());
+ if (ret != BUNDLE_ERROR_NONE)
+ LOGE("Add fail key(%s), ret(%d)", key.c_str(), ret);
+ return ret;
}
int Bundle::Delete(const std::string& key) {
- return bundle_del(impl_->handle_, key.c_str());
+ int ret = bundle_del(impl_->handle_, key.c_str());
+ if (ret != BUNDLE_ERROR_NONE)
+ LOGE("Add fail key(%s), ret(%d)", key.c_str(), ret);
+ return ret;
}
std::string Bundle::GetString(const std::string& key) const {
Bundle::BundleRaw Bundle::ToRaw() {
bundle_raw* raw = nullptr;
int len = 0;
- bundle_encode(impl_->handle_, &raw, &len);
+ int ret = bundle_encode(impl_->handle_, &raw, &len);
+ if (raw == nullptr) {
+ LOGE("Fail to encode data (%d)", ret);
+ throw std::bad_alloc();
+ }
return BundleRaw(
std::unique_ptr<bundle_raw, decltype(std::free)*>(raw, std::free), len);