[Liblas-commits] hg: Fixed consistent use of integral types in
storate.hpp|cpp an...
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Oct 19 18:49:28 EDT 2009
changeset 845f0ec7b4c3 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=845f0ec7b4c3
summary: Fixed consistent use of integral types in storate.hpp|cpp and lasspatialreference.cpp
diffstat:
include/liblas/index/storage.hpp | 14 ++++---
src/index/storage.cpp | 63 ++++++++++++++++++-------------
src/lasspatialreference.cpp | 10 +---
3 files changed, 47 insertions(+), 40 deletions(-)
diffs (220 lines):
diff -r c321708ea2e5 -r 845f0ec7b4c3 include/liblas/index/storage.hpp
--- a/include/liblas/index/storage.hpp Mon Oct 19 23:25:56 2009 +0100
+++ b/include/liblas/index/storage.hpp Mon Oct 19 23:49:14 2009 +0100
@@ -70,8 +70,8 @@
virtual ~VLRStorageManager();
- virtual void loadByteArray(const SpatialIndex::id_type id, ::uint32_t& len, uint8_t** data);
- virtual void storeByteArray(SpatialIndex::id_type& id, const ::uint32_t len, const uint8_t* const data);
+ virtual void loadByteArray(const SpatialIndex::id_type id, std::size_t& len, uint8_t** data);
+ virtual void storeByteArray(SpatialIndex::id_type& id, const std::size_t len, const uint8_t* const data);
virtual void deleteByteArray(const SpatialIndex::id_type id);
LASVariableRecord* getVLR() const;
@@ -80,7 +80,7 @@
LASVariableRecord m_data;
LASVariableRecord m_ids;
- //
+
// class Entry
// {
// public:
@@ -96,10 +96,12 @@
// ~Entry() { delete[] m_pData; }
// }; // Entry
- LASVariableRecord* makeVLR(const size_t len, const uint8_t* data);
- // std::vector<Entry*> m_buffer;
- std::vector<LASVariableRecord*> m_vlrbuffer;
+ typedef std::vector<LASVariableRecord*> vlrbuffer_t;
+ vlrbuffer_t m_vlrbuffer;
std::stack<SpatialIndex::id_type> m_emptyPages;
+
+ LASVariableRecord* makeVLR(const std::size_t len, const uint8_t* data);
+
}; // MemoryStorageManager
diff -r c321708ea2e5 -r 845f0ec7b4c3 src/index/storage.cpp
--- a/src/index/storage.cpp Mon Oct 19 23:25:56 2009 +0100
+++ b/src/index/storage.cpp Mon Oct 19 23:49:14 2009 +0100
@@ -73,40 +73,40 @@
VLRStorageManager::~VLRStorageManager()
{
-
- // uint32_t vlrsize=0;
- for (std::vector<LASVariableRecord*>::iterator vit = m_vlrbuffer.begin(); vit != m_vlrbuffer.end(); vit++) {
- // vlrsize = vlrsize+(*vit)->GetRecordLength();
+ for (vlrbuffer_t::iterator vit = m_vlrbuffer.begin(); vit != m_vlrbuffer.end(); ++vit)
+ {
delete *vit;
}
-
}
-void VLRStorageManager::loadByteArray(const SpatialIndex::id_type id, ::uint32_t& len, uint8_t** data)
+void VLRStorageManager::loadByteArray(const SpatialIndex::id_type id, std::size_t& len, uint8_t** data)
{
- LASVariableRecord* v;
+ LASVariableRecord* v = 0;
try
{
- v = m_vlrbuffer.at(id);
+ v = m_vlrbuffer.at(static_cast<vlrbuffer_t::size_type>(id));
if (v == 0) throw SpatialIndex::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw SpatialIndex::InvalidPageException(id);
}
+ assert(0 != v);
- len = v->GetRecordLength();
+ len = static_cast<std::size_t>(v->GetRecordLength());
*data = new uint8_t[len];
- memcpy(*data, (uint8_t*)&(v->GetData()[0]), len);
+ std::vector<uint8_t> const& vlrdata = v->GetData();
+ std::memcpy(*data, &vlrdata[0], len);
}
-void VLRStorageManager::storeByteArray(SpatialIndex::id_type& id, const ::uint32_t len, const uint8_t* const data)
+void VLRStorageManager::storeByteArray(SpatialIndex::id_type& id, const std::size_t len, const uint8_t* const data)
{
if (id == SpatialIndex::StorageManager::NewPage)
{
- LASVariableRecord* v = makeVLR(len,data);
+ LASVariableRecord* v = makeVLR(len, data);
+ assert(0 != v);
if (m_emptyPages.empty())
{
@@ -115,58 +115,67 @@
}
else
{
- id = m_emptyPages.top(); m_emptyPages.pop();
- m_vlrbuffer[id] = v;
+ id = m_emptyPages.top();
+ m_emptyPages.pop();
+ m_vlrbuffer[static_cast<vlrbuffer_t::size_type>(id)] = v;
}
}
else
{
- LASVariableRecord* v_old;
+ LASVariableRecord* v_old = 0;
try
{
- v_old = m_vlrbuffer.at(id);
- if (v_old == 0) throw SpatialIndex::InvalidPageException(id);
+ v_old = m_vlrbuffer.at(static_cast<vlrbuffer_t::size_type>(id));
+ if (v_old == 0)
+ throw SpatialIndex::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw SpatialIndex::InvalidPageException(id);
}
- LASVariableRecord* v = makeVLR(len,data);
+ LASVariableRecord* v = makeVLR(len, data);
+ assert(0 != v);
delete v_old;
- m_vlrbuffer[id] = v;
+ m_vlrbuffer[static_cast<vlrbuffer_t::size_type>(id)] = v;
}
}
void VLRStorageManager::deleteByteArray(const SpatialIndex::id_type id)
{
- LASVariableRecord* v;
+ LASVariableRecord* v = 0;
try
{
- v = m_vlrbuffer.at(id);
- if (v == 0) throw SpatialIndex::InvalidPageException(id);
+ v = m_vlrbuffer.at(static_cast<vlrbuffer_t::size_type>(id));
+ if (v == 0)
+ throw SpatialIndex::InvalidPageException(id);
}
catch (std::out_of_range)
{
throw SpatialIndex::InvalidPageException(id);
}
- m_vlrbuffer[id] = 0;
+ m_vlrbuffer[static_cast<vlrbuffer_t::size_type>(id)] = 0;
m_emptyPages.push(id);
delete v;
}
-LASVariableRecord* VLRStorageManager::makeVLR(const size_t len, const uint8_t* data)
+LASVariableRecord* VLRStorageManager::makeVLR(const std::size_t len, const uint8_t* data)
{
LASVariableRecord* v = new LASVariableRecord();
- v->SetRecordLength(len);
+ v->SetRecordLength(static_cast<uint16_t>(len));
v->SetUserId("liblas.org");
v->SetRecordId(2112);
- std::vector<uint8_t> d;
- for (size_t i=0;i<len;i++){d.push_back(data[i]);}
+
+ typedef std::vector<uint8_t> data_t;
+ data_t d;
+ for (data_t::size_type i = 0; i < len; ++i)
+ {
+ d.push_back(data[i]);
+ }
v->SetData(d);
return v;
}
diff -r c321708ea2e5 -r 845f0ec7b4c3 src/lasspatialreference.cpp
--- a/src/lasspatialreference.cpp Mon Oct 19 23:25:56 2009 +0100
+++ b/src/lasspatialreference.cpp Mon Oct 19 23:49:14 2009 +0100
@@ -197,8 +197,7 @@
std::vector<uint8_t> data;
// Shorts are 2 bytes in length
- uint16_t length = 2*kcount;
-
+ uint16_t length = 2 * static_cast<uint16_t>(kcount);
record.SetRecordLength(length);
// Copy the data into the data vector
@@ -227,7 +226,7 @@
std::vector<uint8_t> data;
// Doubles are 8 bytes in length
- uint16_t length = 8*dcount;
+ uint16_t length = 8 * static_cast<uint16_t>(dcount);
record.SetRecordLength(length);
// Copy the data into the data vector
@@ -272,18 +271,15 @@
"than r1531 (libgeotiff 1.2.6)");
}
- uint16_t length = acount;
+ uint16_t length = static_cast<uint16_t>(acount);
record.SetRecordLength(length);
// Copy the data into the data vector
for (i=0; i<acount;i++)
{
avalue = adata[i];
-
uint8_t* v = reinterpret_cast<uint8_t*>(&avalue);
-
data.push_back(v[0]);
-
}
record.SetData(data);
m_vlrs.push_back(record);
More information about the Liblas-commits
mailing list