1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_CPP_RESOURCE_H_
6 #define PPAPI_CPP_RESOURCE_H_
8 #include "ppapi/c/pp_resource.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/pass_ref.h"
13 /// This file defines a <code>Resource</code> type representing data associated
17 /// A reference counted module resource.
20 /// The default constructor.
23 /// A constructor for copying a resource.
25 /// @param[in] other A <code>Resource</code>.
26 Resource(const Resource
& other
);
31 /// This function assigns one <code>Resource</code> to another
32 /// <code>Resource</code>.
34 /// @param[in] other A Resource.
36 /// @return A Resource containing the assigned Resource.
37 Resource
& operator=(const Resource
& other
);
39 /// This functions determines if this resource is invalid or
42 /// @return true if this resource is invalid or uninitialized.
43 bool is_null() const { return !pp_resource_
; }
45 PP_Resource
pp_resource() const { return pp_resource_
; }
47 /// This function releases ownership of this resource and returns it to the
50 /// Note that the reference count on the resource is unchanged and the caller
51 /// needs to release the resource.
53 /// @return The detached <code>PP_Resource</code>.
57 /// A constructor used when a <code>PP_Resource</code> is provided as a
58 /// return value whose reference count we need to increment.
60 /// @param[in] resource A <code>PP_Resource</code> corresponding to a
62 explicit Resource(PP_Resource resource
);
64 /// Constructor used when a <code>PP_Resource</code> already has a ref count
65 /// assigned. Add additional refcount is not taken.
66 Resource(PassRef
, PP_Resource resource
);
68 /// PassRefFromConstructor is called by derived class' constructors to
69 /// initialize this <code>Resource</code> with a <code>PP_Resource</code>
70 /// that has already had its reference count incremented by
71 /// <code>Core::AddRefResource</code>. It also assumes this object has no
74 /// The intended usage of this function that the derived class constructor
75 /// will call the default <code>Resource</code> constructor, then make a call
76 /// to create a resource. It then wants to assign the new resource (which,
77 /// since it was returned by the browser, already had its reference count
80 /// @param[in] resource A <code>PP_Resource</code> corresponding to a
82 void PassRefFromConstructor(PP_Resource resource
);
85 PP_Resource pp_resource_
;
90 inline bool operator==(const pp::Resource
& lhs
, const pp::Resource
& rhs
) {
91 return lhs
.pp_resource() == rhs
.pp_resource();
94 inline bool operator!=(const pp::Resource
& lhs
, const pp::Resource
& rhs
) {
98 #endif // PPAPI_CPP_RESOURCE_H_