Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / core / include / dpl / scoped_array.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 /*!
17  * @file        scoped_ptr.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of scoped array RAII
21  *
22  * This module is deprecated, please use standard C++11 feature: std::unique_ptr<Type[]>
23  */
24 #ifndef DPL_SCOPED_ARRAY_H
25 #define DPL_SCOPED_ARRAY_H
26
27 #include <cstddef>
28
29 #include <dpl/assert.h>
30 #include <dpl/scoped_resource.h>
31 #include <dpl/availability.h>
32
33 namespace DPL {
34 template<typename Class>
35 struct ScopedArrayPolicy
36 {
37     typedef Class* Type;
38     static Type NullValue()
39     {
40         return NULL;
41     }
42     static void Destroy(Type ptr)
43     {
44         delete[] ptr;
45     }
46 };
47
48 template<typename Class>
49 class ScopedArray : public ScopedResource<ScopedArrayPolicy<Class> >
50 {
51     typedef ScopedArrayPolicy<Class> Policy;
52     typedef ScopedResource<Policy> BaseType;
53
54   public:
55     explicit ScopedArray(Class *ptr = Policy::NullValue()) : BaseType(ptr) { }
56
57     Class &operator [](std::ptrdiff_t k) const
58     {
59         Assert(this->m_value != Policy::NullValue() &&
60                "Dereference of scoped NULL array!");
61         Assert(k >= 0 && "Negative array index");
62
63         return this->m_value[k];
64     }
65 } DPL_DEPRECATED_WITH_MESSAGE("use standard C++11 feature: std::unique_ptr<Type[]>");
66 } // namespace DPL
67
68 #endif // DPL_SCOPED_PTR_H