Chromium Code Reviews| Index: ppapi/shared_impl/scoped_pp_var.h |
| diff --git a/ppapi/shared_impl/scoped_pp_var.h b/ppapi/shared_impl/scoped_pp_var.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39ab2ecd7e5b6e770d8a5fc524f3bb3062e564eb |
| --- /dev/null |
| +++ b/ppapi/shared_impl/scoped_pp_var.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#ifndef PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
| +#define PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
| + |
| +#include "ppapi/c/pp_var.h" |
| +#include "ppapi/shared_impl/ppapi_shared_export.h" |
| + |
| +namespace ppapi { |
| + |
| +class PPAPI_SHARED_EXPORT ScopedPPVar { |
| + public: |
| + struct PassRef {}; |
| + |
| + ScopedPPVar(); |
| + |
| + // Takes one reference to the given resource. |
| + ScopedPPVar(const PP_Var& v); |
|
dmichael (off chromium)
2012/06/18 20:09:16
probably should be explicit?
|
| + |
| + // Assumes responsibility for one ref that the var already has. |
| + ScopedPPVar(const PassRef&, const PP_Var& v); |
| + |
| + // Implicit copy constructor allowed. |
| + ScopedPPVar(const ScopedPPVar& other); |
| + |
| + ~ScopedPPVar(); |
| + |
| + ScopedPPVar& operator=(const PP_Var& r); |
| + ScopedPPVar& operator=(const ScopedPPVar& other) { |
| + return operator=(other.var_); |
| + } |
| + |
| + const PP_Var& get() const { return var_; } |
| + operator PP_Var() const { return var_; } |
|
dmichael (off chromium)
2012/06/18 20:09:16
This might be dangerous. Should we force people to
|
| + |
| + // Returns the PP_Var, passing the reference to the caller. This class |
| + // will no longer hold the var. |
| + PP_Var Release(); |
| + |
| + private: |
| + PP_Var var_; |
| +}; |
| + |
| +} // namespace ppapi |
| + |
| +#endif // PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |