core/vsl/vsl_b_read_block_old.h
Go to the documentation of this file.
00001 // This is core/vsl/vsl_b_read_block_old.h
00002 #ifndef vsl_b_read_block_old_h_
00003 #define vsl_b_read_block_old_h_
00004 //:
00005 // \file
00006 // \brief Backwards compatibility support only.
00007 // \author Ian Scott (Manchester) May 2003
00008 //
00009 // This file should only be used by existing binary io code that
00010 // wishes to maintain backwards compatibility with existing VSL files.
00011 // Users should have no reason to include this file. 
00012 //
00013 
00014 #include <vxl_config.h>
00015 #include <vcl_iostream.h>
00016 #include <vsl/vsl_binary_io.h>
00017 #include <vsl/vsl_binary_explicit_io.h>
00018 
00019 // IMS Hack: MSVC6.0 has the annoying habit of occasionally forgetting that inline implies static.
00020 #ifdef VCL_VC_6
00021 #define VCL_VC_6_STATIC static
00022 #else
00023 #define VCL_VC_6_STATIC /**/
00024 #endif
00025 
00026 // Whilst this file should not be used by users, it will likely never be deleted,
00027 // and will remain in use by a number of files in vsl and vnl/io to provide
00028 // backwards compatibility. If any of the functions are actually used, a
00029 // deprecation warning will be sent to cerr.
00030 
00031 #include <vcl_deprecated.h>
00032 
00033 // The next declaration should be kept with its non-specialist definition.
00034 // It was this mistake that lead to the full replacement of vsl_b_read_block
00035 // and vsl_b_write_block with vsl_block_binary_{read,write}.
00036 
00037 //: Read a block of values from a vsl_b_istream
00038 // If you want to output a block of fundamental data types very efficiently,
00039 // then just #include <vsl_binary_explicit_io.h>
00040 // \deprecated in favour of vsl_block_binary_read
00041 template <class T>
00042 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, T* begin, vcl_size_t nelems)
00043 {
00044   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00045   while (nelems--)
00046     vsl_b_read(is, *(begin++));
00047 }
00048 
00049 /////////////////////////////////////////////////////////////////////////
00050 
00051 //: Read a block of doubles from a vsl_b_istream
00052 // This function is very speed efficient.
00053 // \deprecated in favour of vsl_block_binary_read
00054 VCL_DEFINE_SPECIALIZATION
00055 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, double* begin, vcl_size_t nelems)
00056 {
00057   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00058   is.is().read((char*) begin, (unsigned long)(nelems*sizeof(double)));
00059   vsl_swap_bytes((char *)begin, sizeof(double), nelems);
00060 }
00061 
00062 /////////////////////////////////////////////////////////////////////////
00063 
00064 //: Read a block of floats from a vsl_b_istream
00065 // This function is very speed efficient.
00066 // \deprecated in favour of vsl_block_binary_read
00067 VCL_DEFINE_SPECIALIZATION
00068 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, float* begin, vcl_size_t nelems)
00069 {
00070   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00071   is.is().read((char*) begin, (unsigned long)(nelems*sizeof(float)));
00072   vsl_swap_bytes((char *)begin, sizeof(float), nelems);
00073 }
00074 
00075 /////////////////////////////////////////////////////////////////////////
00076 
00077 //: Read a block of signed ints from a vsl_b_istream
00078 // This function is very speed efficient, but
00079 // temporarily allocates a block of memory the about 1.2 times
00080 // size of the block being read.
00081 // \deprecated in favour of vsl_block_binary_read
00082 VCL_DEFINE_SPECIALIZATION
00083 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, int* begin, vcl_size_t nelems)
00084 {
00085   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00086   if (!is) return;
00087   vcl_size_t nbytes;
00088   vsl_b_read(is, nbytes);
00089   if (nbytes)
00090   {
00091     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(int)) * nelems];
00092     is.is().read(block, nbytes);
00093     vcl_size_t n_bytes_converted =
00094     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00095     delete [] block;
00096     if (n_bytes_converted != nbytes)
00097     {
00098       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., int*,..) :\n"
00099                << " Corrupted data stream\n";
00100       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00101     }
00102   }
00103 }
00104 
00105 
00106 /////////////////////////////////////////////////////////////////////////
00107 
00108 //: Read a block of unsigned ints from a vsl_b_istream
00109 // This function is very speed efficient, but
00110 // temporarily allocates a block of memory the about 1.2 times
00111 // size of the block being read.
00112 // \deprecated in favour of vsl_block_binary_read
00113 VCL_DEFINE_SPECIALIZATION
00114 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, unsigned int* begin, vcl_size_t nelems)
00115 {
00116   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00117   vcl_size_t nbytes;
00118   vsl_b_read(is, nbytes);
00119   if (nbytes)
00120   {
00121     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(unsigned int)) * nelems];
00122     is.is().read(block, nbytes);
00123     vcl_size_t n_bytes_converted =
00124     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00125     delete [] block;
00126     if (n_bytes_converted != nbytes)
00127     {
00128       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., unsigned int*,..) :\n"
00129                << " Corrupted data stream\n";
00130       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00131     }
00132   }
00133 }
00134 
00135 
00136 /////////////////////////////////////////////////////////////////////////
00137 
00138 
00139 //: Read a block of signed shorts from a vsl_b_istream
00140 // This function is very speed efficient, but
00141 // temporarily allocates a block of memory the about 1.2 times
00142 // size of the block being read.
00143 // \deprecated in favour of vsl_block_binary_read
00144 VCL_DEFINE_SPECIALIZATION
00145 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, short* begin, vcl_size_t nelems)
00146 {
00147   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00148   vcl_size_t nbytes;
00149   vsl_b_read(is, nbytes);
00150   if (nbytes)
00151   {
00152     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(short)) * nelems];
00153     is.is().read(block, nbytes);
00154     vcl_size_t n_bytes_converted =
00155     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00156     delete [] block;
00157     if (n_bytes_converted != nbytes)
00158     {
00159       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., short*,..) :\n"
00160                << " Corrupted data stream\n";
00161       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00162     }
00163   }
00164 }
00165 
00166 
00167 /////////////////////////////////////////////////////////////////////////
00168 
00169 
00170 //: Read a block of unsigned shorts from a vsl_b_istream
00171 // This function is very speed efficient, but
00172 // temporarily allocates a block of memory the about 1.2 times
00173 // size of the block being read.
00174 // \deprecated in favour of vsl_block_binary_read
00175 VCL_DEFINE_SPECIALIZATION
00176 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, unsigned short* begin, vcl_size_t nelems)
00177 {
00178   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00179   vcl_size_t nbytes;
00180   vsl_b_read(is, nbytes);
00181   if (nbytes)
00182   {
00183     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(unsigned short)) * nelems];
00184     is.is().read(block, nbytes);
00185     vcl_size_t n_bytes_converted =
00186     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00187     delete [] block;
00188     if (n_bytes_converted != nbytes)
00189     {
00190       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., unsigned short*,..) :\n"
00191                << " Corrupted data stream\n";
00192       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00193     }
00194   }
00195 }
00196 
00197 
00198 /////////////////////////////////////////////////////////////////////////
00199 
00200 
00201 //: Read a block of signed longs from a vsl_b_istream
00202 // This function is very speed efficient, but
00203 // temporarily allocates a block of memory the about 1.2 times
00204 // size of the block being read.
00205 // \deprecated in favour of vsl_block_binary_read
00206 VCL_DEFINE_SPECIALIZATION
00207 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, long* begin, vcl_size_t nelems)
00208 {
00209   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00210   vcl_size_t nbytes;
00211   vsl_b_read(is, nbytes);
00212   if (nbytes)
00213   {
00214     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(long)) * nelems];
00215     is.is().read(block, nbytes);
00216     vcl_size_t n_bytes_converted =
00217     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00218     delete [] block;
00219     if (n_bytes_converted != nbytes)
00220     {
00221       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., long*,..) :\n"
00222                << " Corrupted data stream\n";
00223       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00224     }
00225   }
00226 }
00227 
00228 
00229 /////////////////////////////////////////////////////////////////////////
00230 
00231 
00232 //: Read a block of unsigned longs from a vsl_b_istream
00233 // This function is very speed efficient, but
00234 // temporarily allocates a block of memory the about 1.2 times
00235 // size of the block being read.
00236 // \deprecated in favour of vsl_block_binary_read
00237 VCL_DEFINE_SPECIALIZATION
00238 VCL_VC_6_STATIC inline void vsl_b_read_block_old(vsl_b_istream &is, unsigned long* begin, vcl_size_t nelems)
00239 {
00240   VXL_DEPRECATED( "vsl_b_read_block_old()" );
00241   vcl_size_t nbytes;
00242   vsl_b_read(is, nbytes);
00243   if (nbytes)
00244   {
00245     char *block = new char[VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(sizeof(unsigned long)) * nelems];
00246     is.is().read(block, nbytes);
00247     vcl_size_t n_bytes_converted =
00248     vsl_convert_from_arbitrary_length((unsigned char *)block, begin, nelems);
00249     delete [] block;
00250     if (n_bytes_converted != nbytes)
00251     {
00252       vcl_cerr << "\nI/O ERROR: vsl_b_read_block(.., unsigned long*,..) :\n"
00253                << " Corrupted data stream\n";
00254       is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00255     }
00256   }
00257 }
00258 
00259 #endif // vsl_b_read_block_old_h_