Go to the documentation of this file.00001
00002 #ifndef vpgl_list_txx_
00003 #define vpgl_list_txx_
00004
00005
00006 #include "vpgl_list.h"
00007
00008 #include <vcl_fstream.h>
00009
00010
00011 template <class T>
00012 bool
00013 vpgl_write_list(
00014 const vcl_vector<T>& list,
00015 vcl_string file )
00016 {
00017 vcl_ofstream ofp( file.c_str() );
00018 if ( !ofp.good() )
00019 return false;
00020 for ( unsigned int i = 0; i < list.size(); ++i )
00021 ofp << "Frame " << i << '\n' << list[i].get_matrix() << '\n';
00022 return true;
00023 }
00024
00025
00026
00027 template <class T>
00028 bool
00029 vpgl_read_list(
00030 vcl_vector<T>& list,
00031 vcl_string file )
00032 {
00033 vcl_ifstream ifp( file.c_str() );
00034 if ( !ifp.good() )
00035 return false;
00036
00037 char line_buffer[256];
00038 while ( ifp.eof() == 0 ){
00039 char nc = (char)ifp.peek();
00040 if ( nc == '-' || (nc >= '0' && nc <= '9') ) {
00041 T new_object;
00042 ifp >> new_object;
00043 list.push_back( new_object );
00044 }
00045 else
00046 ifp.getline(line_buffer,256);
00047 }
00048 return true;
00049 }
00050
00051 #define VPGL_LIST_INSTANTIATE(T) \
00052 template bool vpgl_read_list(vcl_vector<T >&, vcl_string ); \
00053 template bool vpgl_write_list(const vcl_vector<T >&, vcl_string )
00054
00055 #endif // vpgl_list_txx_