Skip to content

Commit ac608bf

Browse files
committed
Update C API point view iterators to return pdal::PointViewPtr
1 parent 0724bf6 commit ac608bf

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

source/pdal/capi/PointViewCollection.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace pdal
1818
return (mItr != mViews.cend());
1919
}
2020

21-
const pdal::PointView *PointViewCollection::next()
21+
const pdal::PointViewPtr PointViewCollection::next()
2222
{
23-
return hasNext() ? (mItr++)->get() : nullptr;
23+
return hasNext() ? *(mItr++) : nullptr;
2424
}
2525

2626
void PointViewCollection::reset()
@@ -40,7 +40,19 @@ namespace pdal
4040
PDALPointViewPtr PDALGetNextPointView(PDALPointViewCollectionPtr collection)
4141
{
4242
auto ptr = reinterpret_cast<pdal::capi::PointViewCollection *>(collection);
43-
return ptr ? (PDALPointViewPtr) ptr->next() : nullptr;
43+
PDALPointViewPtr view = nullptr;
44+
45+
if (ptr)
46+
{
47+
pdal::PointViewPtr v = ptr->next();
48+
49+
if (v)
50+
{
51+
view = new pdal::PointViewPtr(std::move(v));
52+
}
53+
}
54+
55+
return view;
4456
}
4557

4658
void PDALResetPointViewCollection(PDALPointViewCollectionPtr collection)

source/pdal/capi/PointViewCollection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (c) Simverge Software LLC - All Rights Reserved
33
*/
4-
#ifndef PDAL_CAPI_POINTCLOUDVIEWCOLLECTION_H
5-
#define PDAL_CAPI_POINTCLOUDVIEWCOLLECTION_H
4+
#ifndef PDAL_CAPI_POINTVIEWCOLLECTION_H
5+
#define PDAL_CAPI_POINTVIEWCOLLECTION_H
66

77
#include "Forward.h"
88

@@ -18,7 +18,7 @@ namespace pdal
1818
public:
1919
PointViewCollection(const pdal::PointViewSet& views);
2020
bool hasNext() const;
21-
const pdal::PointView *next();
21+
const pdal::PointViewPtr next();
2222
void reset();
2323

2424
private:

tests/pdal/capi/PointViewCollectionTest.c.in

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
SUITE(PointViewCollectionTest);
1515

16+
static PDALPipelinePtr gPipeline = NULL;
1617
static PDALPointViewCollectionPtr gPointViewCollection = NULL;
1718

1819
static void setupPointViewCollectionTest(void *arg)
@@ -31,22 +32,25 @@ static void setupPointViewCollectionTest(void *arg)
3132
{
3233
fread(json, 1, length, file);
3334
json[length] = '\0';
34-
}
3535

36-
fclose(file);
37-
}
36+
gPipeline = PDALCreatePipeline(json);
3837

39-
PDALPipelinePtr pipeline = PDALCreatePipeline(json);
38+
if (gPipeline && PDALExecutePipeline(gPipeline))
39+
{
40+
gPointViewCollection = PDALGetPointViews(gPipeline);
41+
}
4042

41-
if (pipeline && PDALExecutePipeline(pipeline))
42-
{
43-
gPointViewCollection = PDALGetPointViews(pipeline);
43+
free(json);
44+
}
45+
46+
fclose(file);
4447
}
4548
}
4649

4750
static void teardownPointViewCollectionTest(void *arg)
4851
{
4952
PDALDisposePointViewCollection(gPointViewCollection);
53+
PDALDisposePipeline(gPipeline);
5054
}
5155

5256
TEST testPDALHasNextPointView(void)
@@ -61,28 +65,35 @@ TEST testPDALHasNextPointView(void)
6165
PASS();
6266
}
6367

64-
TEST testPDALNextPointView(void)
68+
TEST testPDALGetNextPointView(void)
6569
{
70+
PDALPointViewPtr view = PDALGetNextPointView(NULL);
71+
ASSERT_EQ(NULL, view);
72+
6673
ASSERT_FALSE(gPointViewCollection == NULL);
74+
PDALResetPointViewCollection(gPointViewCollection);
6775
bool hasNext = PDALHasNextPointView(gPointViewCollection);
6876
ASSERT_FALSE(!hasNext);
6977

70-
PDALPointViewPtr view = PDALGetNextPointView(gPointViewCollection);
78+
view = PDALGetNextPointView(gPointViewCollection);
7179
ASSERT_FALSE(view == NULL);
7280

7381
if (PDALHasNextPointView(gPointViewCollection))
7482
{
7583
PDALPointViewPtr anotherView = PDALGetNextPointView(gPointViewCollection);
7684
ASSERT_FALSE(anotherView == NULL);
7785
ASSERT_FALSE(anotherView == view);
86+
PDALDisposePointView(anotherView);
7887
}
7988

89+
PDALDisposePointView(view);
8090
PASS();
8191
}
8292

8393
TEST testPDALResetPointViewCollection(void)
8494
{
8595
ASSERT_FALSE(gPointViewCollection == NULL);
96+
PDALResetPointViewCollection(gPointViewCollection);
8697
bool hasNext = PDALHasNextPointView(gPointViewCollection);
8798
ASSERT_FALSE(!hasNext);
8899

@@ -94,15 +105,20 @@ TEST testPDALResetPointViewCollection(void)
94105
PDALPointViewPtr anotherView = PDALGetNextPointView(gPointViewCollection);
95106
ASSERT_FALSE(anotherView == NULL);
96107
ASSERT_FALSE(anotherView == view);
108+
PDALDisposePointView(anotherView);
97109
}
98110

111+
PDALDisposePointView(view);
112+
99113
view = PDALGetNextPointView(gPointViewCollection);
100114
ASSERT_EQ(NULL, view);
115+
PDALDisposePointView(view);
101116

102117
PDALResetPointViewCollection(gPointViewCollection);
103118

104119
view = PDALGetNextPointView(gPointViewCollection);
105120
ASSERT_FALSE(view == NULL);
121+
PDALDisposePointView(view);
106122

107123
PASS();
108124
}
@@ -113,7 +129,7 @@ GREATEST_SUITE(PointViewCollectionTest)
113129
SET_TEARDOWN(teardownPointViewCollectionTest, NULL);
114130

115131
RUN_TEST(testPDALHasNextPointView);
116-
RUN_TEST(testPDALNextPointView);
132+
RUN_TEST(testPDALGetNextPointView);
117133
RUN_TEST(testPDALResetPointViewCollection);
118134

119135
SET_SETUP(NULL, NULL);

0 commit comments

Comments
 (0)