vnl_file_vector.hxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_file_vector.hxx
2 #ifndef vnl_file_vector_hxx_
3 #define vnl_file_vector_hxx_
4 //:
5 // \file
6 
7 #include <fstream>
8 #include <iostream>
9 #include <cstring>
10 #include "vnl_file_vector.h"
11 
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 
16 //: Load vector from filename.
17 template <class T>
19  : vnl_vector<T>() // makes an empty vector.
20 {
21 #ifdef DEBUG
22  std::cerr << "filename=" << filename << "\nsize=" << this->size() << '\n';
23 #endif
24  if (filename && std::strcmp(filename, "-")) {
25  std::ifstream o(filename);
26  ok_ = this->read_ascii(o);
27  }
28  else
29  ok_ = this->read_ascii(std::cin);
30 #ifdef DEBUG
31  std::cerr << "size=" << this->size() << '\n';
32 #endif
33  if (!ok_)
34  std::cerr << "vnl_file_vector: ERROR loading from " << filename << '\n';
35 }
36 
37 //--------------------------------------------------------------------------------
38 
39 #undef VNL_FILE_VECTOR_INSTANTIATE
40 #define VNL_FILE_VECTOR_INSTANTIATE(T) \
41 template class VNL_EXPORT vnl_file_vector<T >
42 
43 #endif // vnl_file_vector_hxx_
vnl_file_vector(char const *filename)
Load vector from filename.
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
bool read_ascii(std::istream &s)
Read from text stream.
Definition: vnl_vector.hxx:276
Load vnl_vector<T> from file.
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16