| Index: ppapi/cpp/dev/string_wrapper_dev.cc
|
| diff --git a/ppapi/cpp/dev/string_wrapper_dev.cc b/ppapi/cpp/dev/string_wrapper_dev.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e26e259797c23b94e011453aa20e7b484881bf42
|
| --- /dev/null
|
| +++ b/ppapi/cpp/dev/string_wrapper_dev.cc
|
| @@ -0,0 +1,74 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ppapi/cpp/dev/string_wrapper_dev.h"
|
| +
|
| +#include "ppapi/cpp/logging.h"
|
| +#include "ppapi/cpp/var.h"
|
| +
|
| +namespace pp {
|
| +namespace internal {
|
| +
|
| +StringWrapper::StringWrapper(PP_Var* storage, NotOwned)
|
| + : storage_(storage, NOT_OWNED) {
|
| + // TODO(yzshen): consider what if the value is not correct.
|
| + PP_DCHECK(storage_->type == PP_VARTYPE_UNDEFINED);
|
| +}
|
| +
|
| +StringWrapper::StringWrapper(const std::string& value) {
|
| + *storage_ = Var(value).Detach();
|
| +}
|
| +
|
| +StringWrapper::StringWrapper(const StringWrapper& other) {
|
| + // Add one ref.
|
| + *storage_ = Var(*other.storage_).Detach();
|
| +}
|
| +
|
| +StringWrapper::~StringWrapper() {
|
| + Var auto_release(PASS_REF, *storage_);
|
| + *storage_ = PP_MakeUndefined();
|
| +}
|
| +
|
| +StringWrapper& StringWrapper::operator=(const StringWrapper& other) {
|
| + return operator=(*other.storage_);
|
| +}
|
| +
|
| +StringWrapper& StringWrapper::operator=(const PP_Var& other) {
|
| + if (storage_.get() == &other)
|
| + return *this;
|
| +
|
| + Var auto_release(PASS_REF, *storage_);
|
| + // Add one ref.
|
| + *storage_ = Var(other).Detach();
|
| + return *this;
|
| +}
|
| +
|
| +bool StringWrapper::is_set() const {
|
| + PP_DCHECK(storage_->type == PP_VARTYPE_STRING ||
|
| + storage_->type == PP_VARTYPE_UNDEFINED);
|
| + return storage_->type == PP_VARTYPE_STRING;
|
| +}
|
| +
|
| +void StringWrapper::unset() {
|
| + Var auto_release(PASS_REF, *storage_);
|
| + *storage_ = PP_MakeUndefined();
|
| +}
|
| +
|
| +std::string StringWrapper::get() const {
|
| + Var var(*storage_);
|
| + if (var.is_string()) {
|
| + return var.AsString();
|
| + } else {
|
| + PP_NOTREACHED();
|
| + return std::string();
|
| + }
|
| +}
|
| +
|
| +void StringWrapper::set(const std::string& value) {
|
| + Var auto_release(PASS_REF, *storage_);
|
| + *storage_ = Var(value).Detach();
|
| +}
|
| +
|
| +} // namespace internal
|
| +} // namespace pp
|
|
|