OpenShot Library | libopenshot-audio 0.2.0
juce_ArrayAllocationBase.h
1
2/** @weakgroup juce_core-containers
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 Implements some basic array storage allocation functions.
33
34 This class isn't really for public use - it used to be part of the
35 container classes but has since been superseded by ArrayBase. Eventually
36 it will be removed from the API.
37
38 @tags{Core}
39*/
40template <class ElementType, class TypeOfCriticalSectionToUse>
41class ArrayAllocationBase : public TypeOfCriticalSectionToUse
42{
43public:
44 //==============================================================================
45 /** Creates an empty array. */
47
48 /** Destructor. */
50
52 : elements (std::move (other.elements)),
53 numAllocated (other.numAllocated)
54 {
55 }
56
58 {
59 elements = std::move (other.elements);
60 numAllocated = other.numAllocated;
61 return *this;
62 }
63
64 //==============================================================================
65 /** Changes the amount of storage allocated.
66
67 This will retain any data currently held in the array, and either add or
68 remove extra space at the end.
69
70 @param numElements the number of elements that are needed
71 */
73 {
74 if (numAllocated != numElements)
75 {
76 if (numElements > 0)
77 elements.realloc ((size_t) numElements);
78 else
79 elements.free();
80
81 numAllocated = numElements;
82 }
83 }
84
85 /** Increases the amount of storage allocated if it is less than a given amount.
86
87 This will retain any data currently held in the array, but will add
88 extra space at the end to make sure there it's at least as big as the size
89 passed in. If it's already bigger, no action is taken.
90
91 @param minNumElements the minimum number of elements that are needed
92 */
94 {
95 if (minNumElements > numAllocated)
97
98 jassert (numAllocated <= 0 || elements != nullptr);
99 }
100
101 /** Minimises the amount of storage allocated so that it's no more than
102 the given number of elements.
103 */
105 {
106 if (maxNumElements < numAllocated)
108 }
109
110 /** Swap the contents of two objects. */
112 {
113 elements.swapWith (other.elements);
114 std::swap (numAllocated, other.numAllocated);
115 }
116
117 //==============================================================================
118 HeapBlock<ElementType> elements;
119 int numAllocated = 0;
120
121private:
122 JUCE_DECLARE_NON_COPYABLE (ArrayAllocationBase)
123};
124
125} // namespace juce
126
127/** @}*/
Implements some basic array storage allocation functions.
void shrinkToNoMoreThan(int maxNumElements)
Minimises the amount of storage allocated so that it's no more than the given number of elements.
ArrayAllocationBase()=default
Creates an empty array.
~ArrayAllocationBase()=default
Destructor.
void ensureAllocatedSize(int minNumElements)
Increases the amount of storage allocated if it is less than a given amount.
void setAllocatedSize(int numElements)
Changes the amount of storage allocated.
void swapWith(ArrayAllocationBase &other) noexcept
Swap the contents of two objects.
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
Definition juce_Array.h:578