[Bf-blender-cvs] [d22cf2fd774] functions: replace generic Range with IndexRange
Jacques Lucke
noreply at git.blender.org
Thu Sep 5 19:11:34 CEST 2019
Commit: d22cf2fd7742cfdda1b03fc5a9549fe8581f42b3
Author: Jacques Lucke
Date: Thu Sep 5 11:46:55 2019 +0200
Branches: functions
https://developer.blender.org/rBd22cf2fd7742cfdda1b03fc5a9549fe8581f42b3
replace generic Range with IndexRange
===================================================================
M source/blender/blenkernel/BKE_attributes_ref.hpp
M source/blender/blenkernel/intern/attributes_ref.cpp
M source/blender/blenlib/BLI_array_ref.hpp
M source/blender/blenlib/BLI_chunked_range.hpp
M source/blender/blenlib/BLI_range.hpp
M source/blender/blenlib/BLI_task.hpp
M source/blender/blenlib/intern/BLI_range.cpp
M source/blender/functions/core/data_graph.hpp
M source/blender/simulations/bparticles/action_contexts.hpp
M source/blender/simulations/bparticles/action_interface.hpp
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/emitters.cpp
M source/blender/simulations/bparticles/particle_allocator.cpp
M source/blender/simulations/bparticles/particle_allocator.hpp
M source/blender/simulations/bparticles/particle_function_input_providers.cpp
M source/blender/simulations/bparticles/particles_container.hpp
M source/blender/simulations/bparticles/simulate.cpp
M tests/gtests/blenlib/BLI_array_ref_test.cc
M tests/gtests/blenlib/BLI_range_test.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_attributes_ref.hpp b/source/blender/blenkernel/BKE_attributes_ref.hpp
index 88d780ce4b9..6744d1eea14 100644
--- a/source/blender/blenkernel/BKE_attributes_ref.hpp
+++ b/source/blender/blenkernel/BKE_attributes_ref.hpp
@@ -19,7 +19,7 @@ using BLI::float2;
using BLI::float3;
using BLI::MutableArrayRef;
using BLI::Optional;
-using BLI::Range;
+using BLI::IndexRange;
using BLI::rgba_b;
using BLI::rgba_f;
using BLI::SetVector;
@@ -237,9 +237,9 @@ class AttributesInfo {
* Get a range with all attribute indices.
* The range will start at 0.
*/
- Range<uint> attribute_indices() const
+ IndexRange attribute_indices() const
{
- return Range<uint>(0, this->size());
+ return IndexRange(0, this->size());
}
/**
@@ -268,15 +268,15 @@ class AttributesRef {
private:
AttributesInfo *m_info;
ArrayRef<void *> m_buffers;
- Range<uint> m_range;
+ IndexRange m_range;
public:
AttributesRef(AttributesInfo &info, ArrayRef<void *> buffers, uint size)
- : AttributesRef(info, buffers, Range<uint>(0, size))
+ : AttributesRef(info, buffers, IndexRange(0, size))
{
}
- AttributesRef(AttributesInfo &info, ArrayRef<void *> buffers, Range<uint> range)
+ AttributesRef(AttributesInfo &info, ArrayRef<void *> buffers, IndexRange range)
: m_info(&info), m_buffers(buffers), m_range(range)
{
}
@@ -397,13 +397,13 @@ class AttributesRefGroup {
private:
AttributesInfo *m_attributes_info;
Vector<ArrayRef<void *>> m_buffers;
- Vector<Range<uint>> m_ranges;
+ Vector<IndexRange> m_ranges;
uint m_size;
public:
AttributesRefGroup(AttributesInfo &attributes_info,
Vector<ArrayRef<void *>> buffers,
- Vector<Range<uint>> ranges);
+ Vector<IndexRange> ranges);
template<typename T> void set(uint index, ArrayRef<T> data)
{
diff --git a/source/blender/blenkernel/intern/attributes_ref.cpp b/source/blender/blenkernel/intern/attributes_ref.cpp
index 66b2367b665..d483d96d32c 100644
--- a/source/blender/blenkernel/intern/attributes_ref.cpp
+++ b/source/blender/blenkernel/intern/attributes_ref.cpp
@@ -34,14 +34,14 @@ AttributesInfo::AttributesInfo(AttributesDeclaration &builder)
AttributesRefGroup::AttributesRefGroup(AttributesInfo &attributes_info,
Vector<ArrayRef<void *>> buffers,
- Vector<Range<uint>> ranges)
+ Vector<IndexRange> ranges)
: m_attributes_info(&attributes_info),
m_buffers(std::move(buffers)),
m_ranges(std::move(ranges))
{
BLI_assert(buffers.size() == ranges.size());
m_size = 0;
- for (Range<uint> range : m_ranges) {
+ for (IndexRange range : m_ranges) {
m_size += range.size();
}
}
diff --git a/source/blender/blenlib/BLI_array_ref.hpp b/source/blender/blenlib/BLI_array_ref.hpp
index 273690ddcc8..7d0a74f8575 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -87,7 +87,7 @@ template<typename T> class ArrayRef {
return ArrayRef(m_start + start, length);
}
- ArrayRef slice(Range<uint> range) const
+ ArrayRef slice(IndexRange range) const
{
return this->slice(range.start(), range.size());
}
diff --git a/source/blender/blenlib/BLI_chunked_range.hpp b/source/blender/blenlib/BLI_chunked_range.hpp
index 4146ed10705..101f9676f94 100644
--- a/source/blender/blenlib/BLI_chunked_range.hpp
+++ b/source/blender/blenlib/BLI_chunked_range.hpp
@@ -26,14 +26,14 @@
namespace BLI {
-template<typename T> class ChunkedRange {
+class ChunkedIndexRange {
private:
- Range<T> m_total_range;
+ IndexRange m_total_range;
uint m_chunk_size;
uint m_chunk_amount;
public:
- ChunkedRange(Range<T> total_range, uint chunk_size)
+ ChunkedIndexRange(IndexRange total_range, uint chunk_size)
: m_total_range(total_range),
m_chunk_size(chunk_size),
m_chunk_amount(std::ceil(m_total_range.size() / (float)m_chunk_size))
@@ -45,12 +45,12 @@ template<typename T> class ChunkedRange {
return m_chunk_amount;
}
- Range<T> chunk_range(uint index) const
+ IndexRange chunk_range(uint index) const
{
BLI_assert(index < m_chunk_amount);
- T start = m_total_range[index * m_chunk_size];
- T one_after_last = std::min<T>(start + m_chunk_size, m_total_range.one_after_last());
- return Range<T>(start, one_after_last);
+ uint start = m_total_range[index * m_chunk_size];
+ uint one_after_last = std::min<uint>(start + m_chunk_size, m_total_range.one_after_last());
+ return IndexRange(start, one_after_last);
}
};
diff --git a/source/blender/blenlib/BLI_range.hpp b/source/blender/blenlib/BLI_range.hpp
index 3d9b355e486..d0d4c021158 100644
--- a/source/blender/blenlib/BLI_range.hpp
+++ b/source/blender/blenlib/BLI_range.hpp
@@ -35,30 +35,29 @@ namespace BLI {
template<typename T> class ArrayRef;
-template<typename T> class Range {
+class IndexRange {
private:
- T m_start = 0;
- T m_one_after_last = 0;
+ uint m_start = 0;
+ uint m_one_after_last = 0;
public:
- Range() = default;
+ IndexRange() = default;
/**
* Construct a new range.
* Asserts when start is larger than one_after_last.
*/
- Range(T start, T one_after_last) : m_start(start), m_one_after_last(one_after_last)
+ IndexRange(uint start, uint one_after_last) : m_start(start), m_one_after_last(one_after_last)
{
BLI_assert(start <= one_after_last);
}
class Iterator {
private:
- const Range &m_range;
- T m_current;
+ uint m_current;
public:
- Iterator(const Range &range, T current) : m_range(range), m_current(current)
+ Iterator(uint current) : m_current(current)
{
}
@@ -73,7 +72,7 @@ template<typename T> class Range {
return m_current != iterator.m_current;
}
- T operator*() const
+ uint operator*() const
{
return m_current;
}
@@ -81,18 +80,18 @@ template<typename T> class Range {
Iterator begin() const
{
- return Iterator(*this, m_start);
+ return Iterator(m_start);
}
Iterator end() const
{
- return Iterator(*this, m_one_after_last);
+ return Iterator(m_one_after_last);
}
/**
* Access an element in the range.
*/
- T operator[](uint index) const
+ uint operator[](uint index) const
{
BLI_assert(index < this->size());
return m_start + index;
@@ -101,9 +100,10 @@ template<typename T> class Range {
/**
* Two ranges compare equal when they contain the same numbers.
*/
- friend bool operator==(Range<T> a, Range<T> b)
+ friend bool operator==(IndexRange a, IndexRange b)
{
- return a.m_start == b.m_start && a.m_one_after_last == b.m_one_after_last;
+ return (a.m_start == b.m_start && a.m_one_after_last == b.m_one_after_last) ||
+ (a.size() == 0 && b.size() == 0);
}
/**
@@ -117,24 +117,24 @@ template<typename T> class Range {
/**
* Create a new range starting at the end of the current one.
*/
- Range after(uint n) const
+ IndexRange after(uint n) const
{
- return Range(m_one_after_last, m_one_after_last + n);
+ return IndexRange(m_one_after_last, m_one_after_last + n);
}
/**
* Create a new range that ends at the start of the current one.
*/
- Range before(uint n) const
+ IndexRange before(uint n) const
{
- return Range(m_start - n, m_start);
+ return IndexRange(m_start - n, m_start);
}
/**
* Get the first element in the range.
* Asserts when the range is empty.
*/
- T first() const
+ uint first() const
{
BLI_assert(this->size() > 0);
return m_start;
@@ -144,7 +144,7 @@ template<typename T> class Range {
* Get the last element in the range.
* Asserts when the range is empty.
*/
- T last() const
+ uint last() const
{
BLI_assert(this->size() > 0);
return m_one_after_last - 1;
@@ -153,7 +153,7 @@ template<typename T> class Range {
/**
* Get the element one after the end. The returned value is undefined when the range is empty.
*/
- T one_after_last() const
+ uint one_after_last() const
{
return m_one_after_last;
}
@@ -161,7 +161,7 @@ template<typename T> class Range {
/**
* Get the first element in the range. The returned value is undefined when the range is empty.
*/
- T start() const
+ uint start() const
{
return m_start;
}
@@ -169,23 +169,23 @@ template<typename T> class Range {
/**
* Returns true when the range contains a certain number, otherwise false.
*/
- bool contains(T value) const
+ bool contains(uint value) const
{
return value >= m_start && value < m_one_after_last;
}
- Range<T> slice(uint start, uint size) const
+ IndexRange slice(uint start, uint size) const
{
uint new_start = m_start + start;
BLI_assert(new_start + size <= m_one_after_last || size == 0);
- return Range<T>(new_start, new_start + size);
+ return IndexRange(new_start, new_start + size);
}
/**
* Get read-only access to a memory buffer that contains the range as actual numbers. This only
* works for some ranges. The range must be within [0, RANGE_AS_ARRAY_REF_MAX_LEN].
*/
- ArrayRef<T> as_array_ref() const;
+ ArrayRef<uint> as_array_ref() const;
};
} // namespace BLI
diff --git a/source/blender/blenlib/BLI_task.hpp b/source/blender/blenlib/BLI_task.hpp
index c0cc1810cef..b51c6a2877e 100644
--- a/source/blender/blenlib/BLI_task.hpp
+++ b/source/blender/blenlib/BLI_task.hpp
@@ -131,7 +131,7 @@ static void parallel_array_elements(ArrayRef<T> array,
}
template<typename ProcessRange>
-static void parallel_range(Range<uint> total_range,
+static void parallel_range(IndexRange total_range,
uint chunk_size,
ProcessRange process_range,
bool use_threading = true)
@@ -145,9 +145,9 @@ static void parallel_range(Range<uint> total_range,
BLI_parallel_range_settings_defaults(&settings);
struct ParallelData {
- ChunkedRange<uint> chunks;
+ ChunkedIndexRange chunks;
Proce
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list