~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/recastnavigation/Recast/Include/RecastAlloc.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
 
3
//
 
4
// This software is provided 'as-is', without any express or implied
 
5
// warranty.  In no event will the authors be held liable for any damages
 
6
// arising from the use of this software.
 
7
// Permission is granted to anyone to use this software for any purpose,
 
8
// including commercial applications, and to alter it and redistribute it
 
9
// freely, subject to the following restrictions:
 
10
// 1. The origin of this software must not be misrepresented; you must not
 
11
//    claim that you wrote the original software. If you use this software
 
12
//    in a product, an acknowledgment in the product documentation would be
 
13
//    appreciated but is not required.
 
14
// 2. Altered source versions must be plainly marked as such, and must not be
 
15
//    misrepresented as being the original software.
 
16
// 3. This notice may not be removed or altered from any source distribution.
 
17
//
 
18
 
 
19
#ifndef RECASTALLOC_H
 
20
#define RECASTALLOC_H
 
21
 
 
22
/// Provides hint values to the memory allocator on how long the
 
23
/// memory is expected to be used.
 
24
enum rcAllocHint
 
25
{
 
26
        RC_ALLOC_PERM,          ///< Memory will persist after a function call.
 
27
        RC_ALLOC_TEMP           ///< Memory used temporarily within a function.
 
28
};
 
29
 
 
30
/// A memory allocation function.
 
31
//  @param[in] size         The size, in bytes of memory, to allocate.
 
32
//  @param[in] rcAllocHint  A hint to the allocator on how long the memory is expected to be in use.
 
33
//  @return A pointer to the beginning of the allocated memory block, or null if the allocation failed.
 
34
///  @see rcAllocSetCustom
 
35
typedef void* (rcAllocFunc)(int size, rcAllocHint hint);
 
36
 
 
37
/// A memory deallocation function.
 
38
/// @see rcAllocSetCustom
 
39
//  @param[in] ptr 
 
40
typedef void (rcFreeFunc)(void* ptr);
 
41
 
 
42
/// Sets the base custom allocation functions to be used by Recast.
 
43
///  @param[in] allocFunc  The memory allocation function to be used by #rcAlloc
 
44
///  @param[in] freeFunc   The memory de-allocation function to be used by #rcFree
 
45
void rcAllocSetCustom(rcAllocFunc *allocFunc, rcFreeFunc *freeFunc);
 
46
 
 
47
/// Allocates a memory block.
 
48
///  @param[in] size  The size, in bytes of memory, to allocate.
 
49
///  @param[in] hint  A hint to the allocator on how long the memory is expected to be in use.
 
50
///  @return A pointer to the beginning of the allocated memory block, or null if the allocation failed.
 
51
void* rcAlloc(int size, rcAllocHint hint);
 
52
 
 
53
/// Deallocates a memory block.
 
54
///  @param[in] ptr A pointer to a memory block previously allocated using #rcAlloc.
 
55
void rcFree(void* ptr);
 
56
 
 
57
 
 
58
/// A simple dynamic array of integers.
 
59
class rcIntArray
 
60
{
 
61
        int* m_data;
 
62
        int m_size, m_cap;
 
63
        inline rcIntArray(const rcIntArray&);
 
64
        inline rcIntArray& operator=(const rcIntArray&);
 
65
public:
 
66
 
 
67
        /// Constructs an instance with an initial array size of zero.
 
68
        inline rcIntArray() : m_data(0), m_size(0), m_cap(0) {}
 
69
 
 
70
        /// Constructs an instance initialized to the specified size.
 
71
        ///  @param[in] n The initial size of the integer array.
 
72
        inline rcIntArray(int n) : m_data(0), m_size(0), m_cap(0) { resize(n); }
 
73
        inline ~rcIntArray() { rcFree(m_data); }
 
74
 
 
75
        /// Specifies the new size of the integer array.
 
76
        ///  @param[in] n  The new size of the integer array.
 
77
        void resize(int n);
 
78
 
 
79
        /// Push the specified integer onto the end of the array and increases the size by one.
 
80
        ///  @param[in] item  The new value.
 
81
        inline void push(int item) { resize(m_size+1); m_data[m_size-1] = item; }
 
82
 
 
83
        /// Returns the value at the end of the array and reduces the size by one.
 
84
        ///  @return The value at the end of the array.
 
85
        inline int pop() { if (m_size > 0) m_size--; return m_data[m_size]; }
 
86
 
 
87
        /// The value at the specified array index.
 
88
        /// @warning Does not provide overflow protection.
 
89
        ///  @param[in] i  The index of the value.
 
90
        inline const int& operator[](int i) const { return m_data[i]; }
 
91
 
 
92
        /// The value at the specified array index.
 
93
        /// @warning Does not provide overflow protection.
 
94
        ///  @param[in] i  The index of the value.
 
95
        inline int& operator[](int i) { return m_data[i]; }
 
96
 
 
97
        /// The current size of the integer array.
 
98
        inline int size() const { return m_size; }
 
99
};
 
100
 
 
101
/// A simple helper class used to delete an array when it goes out of scope.
 
102
/// @note This class is rarely if ever used by the end user.
 
103
template<class T> class rcScopedDelete
 
104
{
 
105
        T* ptr;
 
106
        inline T* operator=(T* p);
 
107
public:
 
108
 
 
109
        /// Constructs an instance with a null pointer.
 
110
        inline rcScopedDelete() : ptr(0) {}
 
111
 
 
112
        /// Constructs an instance with the specified pointer.
 
113
        ///  @param[in] p  An pointer to an allocated array.
 
114
        inline rcScopedDelete(T* p) : ptr(p) {}
 
115
        inline ~rcScopedDelete() { rcFree(ptr); }
 
116
 
 
117
        /// The root array pointer.
 
118
        ///  @return The root array pointer.
 
119
        inline operator T*() { return ptr; }
 
120
};
 
121
 
 
122
#endif