[Liblas-commits] r1284 - trunk/include/liblas
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Jun 8 21:52:13 EDT 2009
Author: hobu
Date: Fri May 22 12:52:18 2009
New Revision: 1284
URL: http://liblas.org/changeset/1284
Log:
add stream operations for serializing the data from the VLR
Modified:
trunk/include/liblas/lasvariablerecord.hpp
Modified: trunk/include/liblas/lasvariablerecord.hpp
==============================================================================
--- trunk/include/liblas/lasvariablerecord.hpp (original)
+++ trunk/include/liblas/lasvariablerecord.hpp Fri May 22 12:52:18 2009
@@ -44,9 +44,13 @@
#define LIBLAS_LASVARIABLERECORD_HPP_INCLUDED
#include <liblas/cstdint.hpp>
+#include <liblas/detail/utility.hpp>
+#include <liblas/detail/endian.hpp>
+
// std
#include <string>
#include <vector>
+#include <iostream>
namespace liblas {
@@ -117,7 +121,43 @@
/// Get the total size of the VLR in bytes
uint32_t GetTotalSize() const;
-
+
+ friend std::ostream& operator << ( std::ostream& out, LASVariableRecord const& d)
+ {
+ // std::vector<uint8_t> data = d.GetData();
+ for (size_t i=0;i<d.GetData().size();i++) {
+ out << d.GetData()[i];
+ }
+ return out;
+ }
+ friend std::istream& operator >> ( std::istream& in, LASVariableRecord& d)
+ {
+ std::streampos input_pos = in.tellg();
+ std::vector<uint8_t> data;
+ in.seekg(0, std::ios::end);
+ std::streampos length = in.tellg();
+ in.seekg(input_pos, std::ios::beg);
+
+ uint8_t* buffer = new uint8_t[length];
+
+ liblas::detail::read_n(buffer, in, length);
+
+ // FIXME: This has probably already been properly swapped?
+ // but I'm worried about the case where we have a
+ // stream that is really some sort of zlib or bzip stream
+ // and we don't know the orientation of the bytes - hobu
+ LIBLAS_SWAP_BYTES_N(buffer, length);
+
+ for (size_t i=0; i < length; i++){
+ data.push_back(buffer[i]);
+ }
+ delete buffer;
+
+ d.SetData(data);
+ return in;
+ }
+
+
private:
enum
More information about the Liblas-commits
mailing list