38 #if (defined _WIN32 || defined _WIN64 || defined WIN32 || defined WIN64) 44 #if !defined(_POSIX_THREADS) 52 s <<
"Invalid index " << i;
58 return "IndexOutOfBoundsException: " + m_error;
67 return "IllegalArgumentException: " + m_error;
76 return "IllegalStateException: " + m_error;
85 return "EndOfStreamException: " + m_error;
94 return "ResourceLockedException: " + m_error;
103 return "NotSupportedException: " + m_error;
111 loadFromByteArray(data);
121 m_propertySet.clear();
123 uint32_t numberOfProperties;
124 memcpy(&numberOfProperties, ptr,
sizeof(uint32_t));
125 ptr +=
sizeof(uint32_t);
129 for (uint32_t cIndex = 0; cIndex < numberOfProperties; ++cIndex)
131 std::string s(reinterpret_cast<const char*>(ptr));
140 memcpy(&st, ptr,
sizeof(int16_t));
141 ptr +=
sizeof(int16_t);
146 memcpy(&l, ptr,
sizeof(int32_t));
147 ptr +=
sizeof(int32_t);
152 memcpy(&ll, ptr,
sizeof(int64_t));
153 ptr +=
sizeof(int64_t);
158 memcpy(&b, ptr,
sizeof(uint8_t));
159 ptr +=
sizeof(uint8_t);
164 memcpy(&f, ptr,
sizeof(
float));
165 ptr +=
sizeof(float);
170 memcpy(&d, ptr,
sizeof(
double));
171 ptr +=
sizeof(double);
176 memcpy(&c, ptr,
sizeof(
char));
182 memcpy(&us, ptr,
sizeof(uint16_t));
183 ptr +=
sizeof(uint16_t);
188 memcpy(&ul, ptr,
sizeof(uint32_t));
189 ptr +=
sizeof(uint32_t);
194 memcpy(&ull, ptr,
sizeof(uint64_t));
195 ptr +=
sizeof(uint64_t);
200 memcpy(&bl, ptr,
sizeof(uint8_t));
201 ptr +=
sizeof(uint8_t);
206 "Tools::PropertySet::PropertySet: Deserialization problem." 210 m_propertySet.insert(std::pair<std::string, Variant>(s, v));
216 uint32_t size =
sizeof(uint32_t);
218 for (
auto it = m_propertySet.begin(); it != m_propertySet.end(); ++it)
220 switch ((*it).second.m_varType)
223 size +=
sizeof(int16_t);
226 size +=
sizeof(int32_t);
229 size +=
sizeof(int64_t);
232 size +=
sizeof(uint8_t);
235 size +=
sizeof(float);
238 size +=
sizeof(double);
241 size +=
sizeof(char);
244 size +=
sizeof(uint16_t);
247 size +=
sizeof(uint32_t);
250 size +=
sizeof(uint64_t);
253 size +=
sizeof(uint8_t);
257 "Tools::PropertySet::getSize: Unknown type." 260 size +=
static_cast<uint32_t
>((*it).first.size()) + 1 +
sizeof(
VariantType);
268 length = getByteArraySize();
269 *data =
new uint8_t[length];
270 uint8_t* ptr = *data;
272 uint32_t numberOfProperties =
static_cast<uint32_t
>(m_propertySet.size());
273 memcpy(ptr, &numberOfProperties,
sizeof(uint32_t));
274 ptr +=
sizeof(uint32_t);
277 for (
auto it = m_propertySet.begin(); it != m_propertySet.end(); ++it)
279 size_t strSize = (*it).first.size();
280 memcpy(ptr, (*it).first.c_str(), strSize);
285 memcpy(ptr, &((*it).second.m_varType),
sizeof(
VariantType));
288 switch ((*it).second.m_varType)
291 memcpy(ptr, &((*it).second.m_val.iVal),
sizeof(int16_t));
292 ptr +=
sizeof(int16_t);
295 memcpy(ptr, &((*it).second.m_val.lVal),
sizeof(int32_t));
296 ptr +=
sizeof(int32_t);
299 memcpy(ptr, &((*it).second.m_val.llVal),
sizeof(int64_t));
300 ptr +=
sizeof(int64_t);
303 memcpy(ptr, &((*it).second.m_val.bVal),
sizeof(uint8_t));
304 ptr +=
sizeof(uint8_t);
307 memcpy(ptr, &((*it).second.m_val.fltVal),
sizeof(
float));
308 ptr +=
sizeof(float);
311 memcpy(ptr, &((*it).second.m_val.dblVal),
sizeof(
double));
312 ptr +=
sizeof(double);
315 memcpy(ptr, &((*it).second.m_val.cVal),
sizeof(
char));
319 memcpy(ptr, &((*it).second.m_val.uiVal),
sizeof(uint16_t));
320 ptr +=
sizeof(uint16_t);
323 memcpy(ptr, &((*it).second.m_val.ulVal),
sizeof(uint32_t));
324 ptr +=
sizeof(uint32_t);
327 memcpy(ptr, &((*it).second.m_val.ullVal),
sizeof(uint64_t));
328 ptr +=
sizeof(uint64_t);
332 bl = (*it).second.m_val.blVal;
333 memcpy(ptr, &bl,
sizeof(uint8_t));
334 ptr +=
sizeof(uint8_t);
338 "Tools::PropertySet::getData: Cannot serialize a variant of this type." 343 assert(ptr == (*data) + length);
348 const auto& it = m_propertySet.find(property);
350 if (it != m_propertySet.end())
return (*it).second;
356 std::pair<std::map<std::string, Variant>::iterator,
bool> ret;
357 std::map<std::string, Variant>::iterator it;
359 ret = m_propertySet.insert(std::pair<std::string, Variant>(property, v));
363 if (ret.second ==
false) ret.first->second = v;
368 auto it = m_propertySet.find(property);
369 if (it != m_propertySet.end()) m_propertySet.erase(it);
408 m_low >= iv.
m_low - std::numeric_limits<double>::epsilon() &&
409 m_low <= iv.
m_low + std::numeric_limits<double>::epsilon() &&
410 m_high >= iv.
m_high - std::numeric_limits<double>::epsilon() &&
411 m_high <= iv.
m_high + std::numeric_limits<double>::epsilon())
419 return ! (*
this == iv);
449 "Tools::Interval::intersectsInterval: high boundary is smaller than low boundary." 503 "Tools::Interval::containsInterval: high boundary is smaller than low boundary." 510 if (m_low < low && m_high > high)
return true;
544 initDrand(static_cast<uint32_t>(time(
nullptr)), 0xD31A);
550 initDrand(seed, xsubi0);
558 void Tools::Random::initDrand(uint32_t seed, uint16_t xsubi0)
560 m_pBuffer =
new uint16_t[3];
561 m_pBuffer[0] =
static_cast<uint16_t
>(xsubi0);
562 uint32_t mask = 0xFFFF;
563 m_pBuffer[1] =
static_cast<uint16_t
>(seed & mask);
565 m_pBuffer[2] =
static_cast<uint16_t
>((seed & mask) >> 16);
567 #ifdef BUILD_OS_CYGWIN 568 srand48(*(reinterpret_cast<uint32_t*>(m_pBuffer)));
583 return static_cast<uint32_t
>(nextUniformLong());
588 return low +
static_cast<int32_t
>((high - low) * nextUniformDouble());
593 return low +
static_cast<uint32_t
>((high - low) * nextUniformDouble());
598 return static_cast<int64_t
>(nextUniformUnsignedLongLong());
603 uint64_t lh =
static_cast<uint64_t
>(nextUniformLong());
604 uint64_t ll =
static_cast<uint64_t
>(nextUniformLong());
605 uint64_t ret = (lh << 32) | ll;
611 return low +
static_cast<int64_t
>((high - low) * nextUniformDouble());
616 return low +
static_cast<uint64_t
>((high - low) * nextUniformDouble());
621 return static_cast<int16_t
>(nextUniformUnsignedShort());
626 return nextUniformUnsignedLong() >> 16;
632 uint16_t* xsubi =
reinterpret_cast<uint16_t*
>(m_pBuffer);
638 return (high - low) * nextUniformDouble() + low;
643 if (nextUniformDouble() < 0.5)
return true;
650 for (
auto it = p.m_propertySet.begin(); it != p.m_propertySet.end(); ++it)
652 if (it != p.m_propertySet.begin()) os <<
", ";
654 switch ((*it).second.m_varType)
657 os << (*it).first <<
": " << (*it).second.m_val.lVal;
660 os << (*it).first <<
": " << (*it).second.m_val.llVal;
663 os << (*it).first <<
": " << (*it).second.m_val.bVal;
666 os << (*it).first <<
": " << (*it).second.m_val.iVal;
669 os << (*it).first <<
": " << (*it).second.m_val.fltVal;
672 os << (*it).first <<
": " << (*it).second.m_val.dblVal;
675 os << (*it).first <<
": " << (*it).second.m_val.cVal;
678 os << (*it).first <<
": " << (*it).second.m_val.uiVal;
681 os << (*it).first <<
": " << (*it).second.m_val.ulVal;
684 os << (*it).first <<
": " << (*it).second.m_val.ullVal;
687 os << (*it).first <<
": " << (*it).second.m_val.blVal;
690 os << (*it).first <<
": " << (*it).second.m_val.pcVal;
693 os << (*it).first <<
": ?";
696 os << (*it).first <<
": empty";
699 os << (*it).first <<
": unknown";
716 : m_buffer(new char[u32BufferSize]), m_u32BufferSize(u32BufferSize)
754 m_file.open(sFileName.c_str(), std::ios_base::in | std::ios_base::binary);
756 throw std::ios_base::failure(
"Tools::BufferedFileReader::BufferedFileReader: Cannot open file.");
767 m_file.seekg(0, std::ios_base::beg);
769 throw std::ios_base::failure(
"Tools::BufferedFileReader::rewind: seek failed.");
778 m_file.seekg(offset, std::ios_base::beg);
780 throw std::ios_base::failure(
"Tools::BufferedFileReader::seek: seek failed.");
788 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(uint8_t));
802 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(uint16_t));
816 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(uint32_t));
830 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(uint64_t));
844 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(
float));
858 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(
double));
872 m_file.read(reinterpret_cast<char*>(&ret),
sizeof(
bool));
886 m_file.read(reinterpret_cast<char*>(&len),
sizeof(uint32_t));
893 std::string::value_type* buf =
new std::string::value_type[len];
894 m_file.read(reinterpret_cast<char*>(buf), len *
sizeof(std::string::value_type));
902 std::string ret(buf, len);
912 *pData =
new uint8_t[u32Len];
913 m_file.read(reinterpret_cast<char*>(*pData), u32Len);
933 open(sFileName, mode);
948 m_file.open(sFileName.c_str(), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
950 throw std::ios_base::failure(
"Tools::BufferedFileWriter::open: Cannot open file.");
958 m_file.open(sFileName.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
962 m_file.open(sFileName.c_str(), std::ios_base::out | std::ios_base::binary);
964 throw std::ios_base::failure(
"Tools::BufferedFileWriter::open: Cannot open file.");
968 m_file.seekp(0, std::ios_base::end);
970 throw std::ios_base::failure(
"Tools::BufferedFileWriter::open: Cannot open file.");
981 m_file.seekp(0, std::ios_base::beg);
983 throw std::ios_base::failure(
"Tools::BufferedFileWriter::rewind: seek failed.");
990 m_file.seekp(offset, std::ios_base::beg);
992 throw std::ios_base::failure(
"Tools::BufferedFileWriter::seek: seek failed.");
997 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(uint8_t));
998 if (!
m_file.good())
throw std::ios_base::failure(
"");
1003 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(uint16_t));
1004 if (!
m_file.good())
throw std::ios_base::failure(
"");
1009 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(uint32_t));
1010 if (!
m_file.good())
throw std::ios_base::failure(
"");
1015 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(uint64_t));
1016 if (!
m_file.good())
throw std::ios_base::failure(
"");
1021 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(
float));
1022 if (!
m_file.good())
throw std::ios_base::failure(
"");
1027 m_file.write(reinterpret_cast<const char*>(&i),
sizeof(
double));
1028 if (!
m_file.good())
throw std::ios_base::failure(
"");
1033 m_file.write(reinterpret_cast<const char*>(&b),
sizeof(
bool));
1034 if (!
m_file.good())
throw std::ios_base::failure(
"");
1039 uint32_t len =
static_cast<uint32_t
>(s.size());
1040 m_file.write(reinterpret_cast<const char*>(&len),
sizeof(uint32_t));
1041 if (!
m_file.good())
throw std::ios_base::failure(
"");
1042 m_file.write(reinterpret_cast<const char*>(s.c_str()), len *
sizeof(std::string::value_type));
1043 if (!
m_file.good())
throw std::ios_base::failure(
"");
1048 m_file.write(reinterpret_cast<const char*>(pData), u32Len);
1049 if (!
m_file.good())
throw std::ios_base::failure(
"");
1063 char* tmpName = NULL;
1064 tmpName = tmpnam( NULL );
1066 if (tmpName == NULL)
1067 throw std::ios_base::failure(
"Tools::TemporaryFile: Cannot create temporary file name.");
1070 char tmpName[L_tmpnam_s];
1071 errno_t err = tmpnam_s(tmpName, L_tmpnam_s);
1073 throw std::ios_base::failure(
"Tools::TemporaryFile: Cannot create temporary file name.");
1076 if (tmpName[0] ==
'\\')
1077 m_sFile = std::string(tmpName + 1);
1079 m_sFile = std::string(tmpName);
1083 const char* val =
nullptr;
1085 (val = std::getenv(
"TMPDIR" )) ||
1086 (val = std::getenv(
"TMP" )) ||
1087 (val = std::getenv(
"TEMP" )) ||
1088 (val = std::getenv(
"TEMPDIR"));
1091 const char* default_tmp =
"/data/local/tmp";
1093 const char* default_tmp =
"/tmp";
1095 std::string tempDir ((val !=
nullptr) ? val : default_tmp);
1098 std::string tempName = tempDir +
"/spatialindex-XXXXXX";
1099 char* tmpName = strdup(tempName.c_str());
1100 if (!tmpName || mkstemp(tmpName) == -1)
1101 throw std::ios_base::failure(
"Tools::TemporaryFile: Cannot create temporary file name.");
1114 _unlink(m_sFile.c_str());
1116 std::remove(m_sFile.c_str());
1146 return m_pFile->eof();
1158 throw std::ios_base::failure(
"Tools::TemporaryFile::readUInt8: file not open for reading.");
1167 throw std::ios_base::failure(
"Tools::TemporaryFile::readUInt16: file not open for reading.");
1176 throw std::ios_base::failure(
"Tools::TemporaryFile::readUInt32: file not open for reading.");
1185 throw std::ios_base::failure(
"Tools::TemporaryFile::readUInt64: file not open for reading.");
1194 throw std::ios_base::failure(
"Tools::TemporaryFile::readFloat: file not open for reading.");
1203 throw std::ios_base::failure(
"Tools::TemporaryFile::readDouble: file not open for reading.");
1212 throw std::ios_base::failure(
"Tools::TemporaryFile::readString: file not open for reading.");
1221 throw std::ios_base::failure(
"Tools::TemporaryFile::readString: file not open for reading.");
1230 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1232 return bw->
write(i);
1239 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1241 return bw->
write(i);
1248 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1250 return bw->
write(i);
1257 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1259 return bw->
write(i);
1266 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1268 return bw->
write(i);
1275 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1277 return bw->
write(i);
1284 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1286 return bw->
write(s);
1293 throw std::ios_base::failure(
"Tools::TemporaryFile::write: file not open for writing.");
1295 return bw->
write(u32Len, pData);
double erand48(unsigned short xseed[3]) __THROW
long jrand48(unsigned short xseed[3]) __THROW
void srand48(long int seed) __THROW