diff --git a/src/shape/shapefile.cc b/src/shape/shapefile.cc index 3942b2bf1..35e1d283b 100644 --- a/src/shape/shapefile.cc +++ b/src/shape/shapefile.cc @@ -56,79 +56,4 @@ void shape_file::close() } -int shape_file::read_xdr_integer() -{ -#ifndef WORDS_BIGENDIAN - char b[4]; - file_.read(b, 4); - return b[3] & 0xffu | (b[2] & 0xffu) << 8 | - (b[1] & 0xffu) << 16 | (b[0] & 0xffu) << 24; -#else -#error "TODO: big-endian " -#endif -} - -int shape_file::read_ndr_integer() -{ -#ifndef WORDS_BIGENDIAN - char b[4]; - file_.read(b,4); - return b[0]&0xffu | (b[1]&0xffu) << 8 | - (b[2]&0xffu) << 16 | (b[3]&0xffu) << 24; -#else -#error "TODO: big-endian " -#endif -} - - -double shape_file::read_double() -{ -#ifndef WORDS_BIGENDIAN - double val; - file_.read(reinterpret_cast(&val),sizeof(val)); - return val; -#else -#error "TODO: big-endian " -#endif -} - -void shape_file::read_envelope(Envelope& envelope) -{ -#ifndef WORDS_BIGENDIAN - file_.read(reinterpret_cast(&envelope),sizeof(envelope)); -#else -#error "TODO: big-endian" -#endif -} - - -void shape_file::skip(int bytes) -{ - file_.seekg(bytes,std::ios::cur); -} - - -void shape_file::rewind() -{ - seek(100); -} - - -void shape_file::seek(long pos) -{ - file_.seekg(pos,std::ios::beg); -} - - -long shape_file::pos() -{ - return file_.tellg(); -} - - -bool shape_file::is_eof() -{ - return file_.eof(); -} - diff --git a/src/shape/shapefile.hh b/src/shape/shapefile.hh index ff60f876b..d29f172b2 100644 --- a/src/shape/shapefile.hh +++ b/src/shape/shapefile.hh @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +//$Id$ + #ifndef SHAPEFILE_HH #define SHAPEFILE_HH @@ -26,6 +28,20 @@ using namespace mapnik; class shape_file { + // POD structure to hold shape record + struct shape_record + { + unsigned char* data; + size_t size; + explicit shape_record(size_t size) + : data(static_cast(::operator new(sizeof(unsigned char)*size))), + size(size) {} + ~shape_record() + { + ::operator delete(data); + } + }; + std::ifstream file_; static const int buffer_size = 16; char buff_[buffer_size]; @@ -36,12 +52,9 @@ public: bool open(const std::string& file_name); bool is_open(); void close(); - int read_xdr_integer(); - int read_ndr_integer(); - double read_double(); - + template - void shape_file::read_coord(coord& coord) + inline void shape_file::read_coord(coord& coord) { #ifndef WORDS_BIGENDIAN file_.read(reinterpret_cast(&coord),sizeof(coord)); @@ -51,7 +64,7 @@ public: } template - void shape_file::read_coords(coord_array &ar) + inline void shape_file::read_coords(coord_array &ar) { #ifndef WORDS_BIGENDIAN file_.read(reinterpret_cast(&ar[0]),sizeof(T)*ar.size()); @@ -61,12 +74,80 @@ public: } - void read_envelope(Envelope &envelope); - void skip(int bytes); - void rewind(); - void seek(long pos); - long pos(); - bool is_eof(); + inline int read_xdr_integer() + { +#ifndef WORDS_BIGENDIAN + char b[4]; + file_.read(b, 4); + return b[3] & 0xffu | (b[2] & 0xffu) << 8 | + (b[1] & 0xffu) << 16 | (b[0] & 0xffu) << 24; +#else +#error "TODO: big-endian " +#endif + } + + inline int read_ndr_integer() + { +#ifndef WORDS_BIGENDIAN + char b[4]; + file_.read(b,4); + return b[0]&0xffu | (b[1]&0xffu) << 8 | + (b[2]&0xffu) << 16 | (b[3]&0xffu) << 24; +#else +#error "TODO: big-endian " +#endif + } + + inline double read_double() + { +#ifndef WORDS_BIGENDIAN + double val; + file_.read(reinterpret_cast(&val),sizeof(val)); + return val; +#else +#error "TODO: big-endian " +#endif + } + + inline void read_envelope(Envelope& envelope) + { +#ifndef WORDS_BIGENDIAN + file_.read(reinterpret_cast(&envelope),sizeof(envelope)); +#else +#error "TODO: big-endian" +#endif + } + + + inline void skip(int bytes) + { + file_.seekg(bytes,std::ios::cur); + } + + + inline void rewind() + { + seek(100); + } + + + inline void seek(long pos) + { + file_.seekg(pos,std::ios::beg); + } + + + inline long pos() + { + return file_.tellg(); + } + + + inline bool is_eof() + { + return file_.eof(); + } + private: shape_file(const shape_file&); shape_file& operator=(const shape_file&);