libspatialindex API Reference  (git-trunk)
DataStream.cc
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libsidx - A C API wrapper around libspatialindex
3  * Purpose: C++ objects to implement the datastream.
4  * Author: Howard Butler, hobu.inc@gmail.com
5  ******************************************************************************
6  * Copyright (c) 2009, Howard Butler
7  *
8  * All rights reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27 ******************************************************************************/
28 
30 
31 
33  double **pMin,
34  double **pMax,
35  uint32_t *nDimension,
36  const uint8_t** pData,
37  size_t *nDataLength) )
38  : m_pNext(0),
39  m_bDoneReading(false)
40 {
41  iterfunct = readNext;
42 
43  // Read the first one.
44  readData();
45 }
46 
48 {
49  if (m_pNext != 0) delete m_pNext;
50 }
51 
52 bool DataStream::readData()
53 {
55  double *pMin=0;
56  double *pMax=0;
57  uint32_t nDimension=0;
58  uint8_t *p_data=0;
59  size_t nDataLength=0;
60 
61  if (m_bDoneReading == true) {
62  return false;
63  }
64 
65  int ret = iterfunct(&id, &pMin, &pMax, &nDimension, const_cast<const uint8_t**>(&p_data), &nDataLength);
66 
67  // The callback should return anything other than 0
68  // when it is done.
69  if (ret != 0)
70  {
71  m_bDoneReading = true;
72  return false;
73  }
74 
75  SpatialIndex::Region r = SpatialIndex::Region(pMin, pMax, nDimension);
76 
77  // Data gets copied here anyway. We should fix this part of SpatialIndex::RTree::Data's constructor
78  m_pNext = new SpatialIndex::RTree::Data((uint32_t)nDataLength, p_data, r, id);
79 
80  return true;
81 }
82 
83 
85 {
86  if (m_pNext == 0) return 0;
87 
89  m_pNext = 0;
90  readData();
91  return ret;
92 }
93 
95 {
96  return (m_pNext != 0);
97 }
98 
99 uint32_t DataStream::size()
100 {
101  throw Tools::NotSupportedException("Operation not supported.");
102 }
103 
105 {
106  throw Tools::NotSupportedException("Operation not supported.");
107 
108 /* if (m_pNext != 0)
109  {
110  delete m_pNext;
111  m_pNext = 0;
112  }
113 */
114 }
uint32_t size()
Definition: DataStream.cc:99
void rewind()
Definition: DataStream.cc:104
DataStream(int(*readNext)(SpatialIndex::id_type *id, double **pMin, double **pMax, uint32_t *nDimension, const uint8_t **pData, size_t *nDataLength))
Definition: DataStream.cc:32
SpatialIndex::IData * getNext()
Definition: DataStream.cc:84
bool hasNext()
Definition: DataStream.cc:94
SpatialIndex::RTree::Data * m_pNext
Definition: DataStream.h:46
int64_t id_type
Definition: SpatialIndex.h:41