core/vsl/vsl_block_binary.h

Go to the documentation of this file.
00001 // This is core/vsl/vsl_block_binary.h
00002 #ifndef vsl_block_binary_io_h_
00003 #define vsl_block_binary_io_h_
00004 //:
00005 // \file
00006 // \brief Set of functions to do binary IO on a block of values.
00007 // \author Ian Scott, ISBE Manchester, Feb 2003
00008 
00009 #include <vsl/vsl_binary_io.h>
00010 #include <vsl/vsl_binary_explicit_io.h>
00011 
00012 //: Error checking.
00013 void vsl_block_binary_read_confirm_specialisation(vsl_b_istream &is, bool specialised);
00014 
00015 //: Write a block of values to a vsl_b_ostream, potentially very efficiently for fundamental types.
00016 template <class T>
00017 inline void vsl_block_binary_write(vsl_b_ostream &os, const T* begin, vcl_size_t nelems);
00018 
00019 //: Read a block of values from a vsl_b_ostream, potentially very efficiently for fundamental types.
00020 template <class T>
00021 inline void vsl_block_binary_read(vsl_b_istream &is, T* begin, vcl_size_t nelems);
00022 
00023 
00024 /////////////////////////////////////////////////////////////////////////
00025 
00026 // Internal implementation
00027 template <class T>
00028   void vsl_block_binary_write_float_impl(vsl_b_ostream &os, const T* begin, vcl_size_t nelems);
00029 
00030 // Internal implementation
00031 template <class T>
00032   void vsl_block_binary_read_float_impl(vsl_b_istream &is, T* begin, vcl_size_t nelems);
00033 
00034 
00035 /////////////////////////////////////////////////////////////////////////
00036 //: Write a block of doubles to a vsl_b_ostream
00037 // This function is very speed efficient, but
00038 // temporarily allocates a block of memory the size of the
00039 // block being read.
00040 VCL_DEFINE_SPECIALIZATION
00041 inline void vsl_block_binary_write(vsl_b_ostream &os, const double* begin, vcl_size_t nelems)
00042 {
00043   vsl_block_binary_write_float_impl(os, begin, nelems);
00044 }
00045 
00046 //: Read a block of doubles from a vsl_b_istream
00047 // This function is very speed efficient.
00048 VCL_DEFINE_SPECIALIZATION
00049 inline void vsl_block_binary_read(vsl_b_istream &is, double* begin, vcl_size_t nelems)
00050 {
00051   vsl_block_binary_read_float_impl(is, begin, nelems);
00052 }
00053 
00054 /////////////////////////////////////////////////////////////////////////
00055 
00056 //: Write a block of floats to a vsl_b_ostream
00057 // This function is very speed efficient, but
00058 // temporarily allocates a block of memory the size of the
00059 // block being read.
00060 VCL_DEFINE_SPECIALIZATION
00061 inline void vsl_block_binary_write(vsl_b_ostream &os, const float* begin, vcl_size_t nelems)
00062 {
00063   vsl_block_binary_write_float_impl(os, begin, nelems);
00064 }
00065 
00066 //: Read a block of floats from a vsl_b_istream
00067 // This function is very speed efficient.
00068 VCL_DEFINE_SPECIALIZATION
00069 inline void vsl_block_binary_read(vsl_b_istream &is, float* begin, vcl_size_t nelems)
00070 {
00071   vsl_block_binary_read_float_impl(is, begin, nelems);
00072 }
00073 
00074 /////////////////////////////////////////////////////////////////////////
00075 
00076 // Internal implementation
00077 template <class T>
00078   void vsl_block_binary_write_int_impl(vsl_b_ostream &os, const T* begin, vcl_size_t nelems);
00079 
00080 // Internal implementation
00081 template <class T>
00082   void vsl_block_binary_read_int_impl(vsl_b_istream &is, T* begin, vcl_size_t nelems);
00083   
00084 /////////////////////////////////////////////////////////////////////////
00085 
00086 //: Write a block of signed ints to a vsl_b_ostream
00087 // This function is very speed efficient, but
00088 // temporarily allocates a block of memory the about 1.2 times
00089 // size of the block being read.
00090 VCL_DEFINE_SPECIALIZATION
00091 inline void vsl_block_binary_write(vsl_b_ostream &os, const int* begin, vcl_size_t nelems)
00092 {
00093   vsl_block_binary_write_int_impl(os, begin, nelems);
00094 }
00095 
00096 //: Read a block of signed ints from a vsl_b_istream
00097 // This function is very speed efficient, but
00098 // temporarily allocates a block of memory the about 1.2 times
00099 // size of the block being read.
00100 VCL_DEFINE_SPECIALIZATION
00101 inline void vsl_block_binary_read(vsl_b_istream &is, int* begin, vcl_size_t nelems)
00102 {
00103   vsl_block_binary_read_int_impl(is, begin, nelems);
00104 }
00105 
00106 /////////////////////////////////////////////////////////////////////////
00107 
00108 //: Write a block of unsigned ints to a vsl_b_ostream
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 VCL_DEFINE_SPECIALIZATION
00113 inline void vsl_block_binary_write(vsl_b_ostream &os, const unsigned int* begin, vcl_size_t nelems)
00114 {
00115   vsl_block_binary_write_int_impl(os, begin, nelems);
00116 }
00117 
00118 //: Read a block of unsigned ints from a vsl_b_istream
00119 // This function is very speed efficient, but
00120 // temporarily allocates a block of memory the about 1.2 times
00121 // size of the block being read.
00122 VCL_DEFINE_SPECIALIZATION
00123 inline void vsl_block_binary_read(vsl_b_istream &is, unsigned int* begin, vcl_size_t nelems)
00124 {
00125   vsl_block_binary_read_int_impl(is, begin, nelems);
00126 }
00127 
00128 
00129 /////////////////////////////////////////////////////////////////////////
00130 
00131 //: Write a block of signed shorts to a vsl_b_ostream
00132 // This function is very speed efficient, but
00133 // temporarily allocates a block of memory the about 1.2 times
00134 // size of the block being read.
00135 VCL_DEFINE_SPECIALIZATION
00136 inline void vsl_block_binary_write(vsl_b_ostream &os, const short* begin, vcl_size_t nelems)
00137 {
00138   vsl_block_binary_write_int_impl(os, begin, nelems);
00139 }
00140 
00141 //: Read a block of signed shorts from a vsl_b_istream
00142 // This function is very speed efficient, but
00143 // temporarily allocates a block of memory the about 1.2 times
00144 // size of the block being read.
00145 VCL_DEFINE_SPECIALIZATION
00146 inline void vsl_block_binary_read(vsl_b_istream &is, short* begin, vcl_size_t nelems)
00147 {
00148   vsl_block_binary_read_int_impl(is, begin, nelems);
00149 }
00150 
00151 
00152 /////////////////////////////////////////////////////////////////////////
00153 
00154 //: Write a block of unsigned shorts to a vsl_b_ostream
00155 // This function is very speed efficient, but
00156 // temporarily allocates a block of memory the about 1.2 times
00157 // size of the block being read.
00158 VCL_DEFINE_SPECIALIZATION
00159 inline void vsl_block_binary_write(vsl_b_ostream &os, const unsigned short* begin, vcl_size_t nelems)
00160 {
00161   vsl_block_binary_write_int_impl(os, begin, nelems);
00162 }
00163 
00164 //: Read a block of unsigned shorts from a vsl_b_istream
00165 // This function is very speed efficient, but
00166 // temporarily allocates a block of memory the about 1.2 times
00167 // size of the block being read.
00168 VCL_DEFINE_SPECIALIZATION
00169 inline void vsl_block_binary_read(vsl_b_istream &is, unsigned short* begin, vcl_size_t nelems)
00170 {
00171   vsl_block_binary_read_int_impl(is, begin, nelems);
00172 }
00173 
00174 
00175 /////////////////////////////////////////////////////////////////////////
00176 
00177 //: Write a block of signed longs to a vsl_b_ostream
00178 // This function is very speed efficient, but
00179 // temporarily allocates a block of memory the about 1.2 times
00180 // size of the block being read.
00181 VCL_DEFINE_SPECIALIZATION
00182 inline void vsl_block_binary_write(vsl_b_ostream &os, const long* begin, vcl_size_t nelems)
00183 {
00184   vsl_block_binary_write_int_impl(os, begin, nelems);
00185 }
00186 
00187 //: Read a block of signed longs from a vsl_b_istream
00188 // This function is very speed efficient, but
00189 // temporarily allocates a block of memory the about 1.2 times
00190 // size of the block being read.
00191 VCL_DEFINE_SPECIALIZATION
00192 inline void vsl_block_binary_read(vsl_b_istream &is, long* begin, vcl_size_t nelems)
00193 {
00194   vsl_block_binary_read_int_impl(is, begin, nelems);
00195 }
00196 
00197 
00198 /////////////////////////////////////////////////////////////////////////
00199 
00200 //: Write a block of unsigned longs to a vsl_b_ostream
00201 // This function is very speed efficient, but
00202 // temporarily allocates a block of memory the about 1.2 times
00203 // size of the block being read.
00204 VCL_DEFINE_SPECIALIZATION
00205 inline void vsl_block_binary_write(vsl_b_ostream &os, const unsigned long* begin, vcl_size_t nelems)
00206 {
00207   vsl_block_binary_write_int_impl(os, begin, nelems);
00208 }
00209 
00210 //: Read a block of unsigned longs from a vsl_b_istream
00211 // This function is very speed efficient, but
00212 // temporarily allocates a block of memory the about 1.2 times
00213 // size of the block being read.
00214 VCL_DEFINE_SPECIALIZATION
00215 inline void vsl_block_binary_read(vsl_b_istream &is, unsigned long* begin, vcl_size_t nelems)
00216 {
00217   vsl_block_binary_read_int_impl(is, begin, nelems);
00218 }
00219 
00220 
00221 /////////////////////////////////////////////////////////////////////////
00222 
00223 #if 0
00224 // This test will be replaced with !VCL_PTRDIFF_T_IS_A_STANDARD_TYPE
00225 // When that macro is working.
00226 
00227 //: Write a block of vcl_ptrdiff_ts to a vsl_b_ostream
00228 // This function is very speed efficient, but
00229 // temporarily allocates a block of memory the about 1.2 times
00230 // size of the block being read.
00231 VCL_DEFINE_SPECIALIZATION
00232 inline void vsl_block_binary_write(vsl_b_ostream &os, const vcl_ptrdiff_t* begin, vcl_size_t nelems)
00233 {
00234   vsl_block_binary_write_int_impl(os, begin, nelems);
00235 }
00236 
00237 //: Read a block of vcl_ptrdiff_ts from a vsl_b_istream
00238 // This function is very speed efficient, but
00239 // temporarily allocates a block of memory the about 1.2 times
00240 // size of the block being read.
00241 VCL_DEFINE_SPECIALIZATION
00242 inline void vsl_block_binary_read(vsl_b_istream &is, vcl_ptrdiff_t* begin, vcl_size_t nelems)
00243 {
00244   vsl_block_binary_read_int_impl(is, begin, nelems);
00245 }
00246 
00247 
00248 /////////////////////////////////////////////////////////////////////////
00249 
00250 //: Write a block of vcl_size_ts to a vsl_b_ostream
00251 // This function is very speed efficient, but
00252 // temporarily allocates a block of memory the about 1.2 times
00253 // size of the block being read.
00254 VCL_DEFINE_SPECIALIZATION
00255 inline void vsl_block_binary_write(vsl_b_ostream &os, const vcl_size_t* begin, vcl_size_t nelems)
00256 {
00257   vsl_block_binary_write_int_impl(os, begin, nelems);
00258 }
00259 
00260 //: Read a block of vcl_size_ts from a vsl_b_istream
00261 // This function is very speed efficient, but
00262 // temporarily allocates a block of memory the about 1.2 times
00263 // size of the block being read.
00264 VCL_DEFINE_SPECIALIZATION
00265 inline void vsl_block_binary_read(vsl_b_istream &is, vcl_size_t* begin, vcl_size_t nelems)
00266 {
00267   vsl_block_binary_read_int_impl(is, begin, nelems);
00268 }
00269 
00270 #endif // 0
00271 
00272 
00273 //: Write a block of values to a vsl_b_ostream
00274 // If you want to output a block of fundamental data types very efficiently,
00275 // then just #include <vsl_binary_explicit_io.h>
00276 template <class T>
00277 inline void vsl_block_binary_write(vsl_b_ostream &os, const T* begin, vcl_size_t nelems)
00278 {
00279   vsl_b_write(os, false); // Error check that this is a specialised version
00280   while (nelems--)
00281     vsl_b_write(os, *(begin++));
00282 }
00283 
00284 //: Read a block of values from a vsl_b_istream
00285 // If you want to output a block of fundamental data types very efficiently,
00286 // then just #include <vsl_binary_explicit_io.h>
00287 template <class T>
00288 inline void vsl_block_binary_read(vsl_b_istream &is, T* begin, vcl_size_t nelems)
00289 {
00290   vsl_block_binary_read_confirm_specialisation(is, false);
00291   if (!is) return;
00292   while (nelems--)
00293     vsl_b_read(is, *(begin++));
00294 }
00295 
00296 #endif // vsl_block_binary_io_h_

Generated on Fri Aug 29 05:05:52 2008 for core/vsl by  doxygen 1.5.1