tizen beta release
[framework/web/wrt-plugins-common.git] / src / CommonsJavaScript / ScopedJSStringRef.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #ifndef WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_H_
17 #define WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_H_
18
19 #include <JavaScriptCore/JavaScript.h>
20 #include <dpl/noncopyable.h>
21
22 namespace WrtDeviceApis {
23 namespace CommonsJavaScript {
24 /**
25  * Takes ownership over JSStringRef object to call JSSTringRelease on it
26  * when this object goes out of scope.
27  */
28 class ScopedJSStringRef : private DPL::Noncopyable
29 {
30   public:
31     /**
32      * Creates this class instance.
33      * @param ref JSStringRef to take ownership.
34      * @remarks Takes ownership.
35      */
36     ScopedJSStringRef(JSStringRef ref);
37
38     /**
39      * Destroys instance.
40      * @remarks Releases stored JSStringRef.
41      */
42     ~ScopedJSStringRef();
43
44     /**
45      * Gets stored JSStringRef.
46      * @return JSStringRef object.
47      * @remarks Doesn't pass ownership to caller.
48      */
49     JSStringRef get() const;
50
51   private:
52     JSStringRef m_ref;
53 };
54 } // CommonsJavaScript
55 } // WrtDeviceApis
56
57 #endif /* WRTDEVICEAPIS_COMMONSJAVASCRIPT_SCOPEDJSSTRINGREF_H_ */