Cheetah Software  1.0
save_file.h
Go to the documentation of this file.
1 #ifndef SAVE_FILE_H
2 #define SAVE_FILE_H
3 
4 #include <Configuration.h>
5 #include <cppTypes.h>
6 #include <stdio.h>
7 #include <sys/stat.h>
8 #include <algorithm>
9 #include <fstream>
10 #include <iostream>
11 #include <list>
12 #include <string>
13 
14 static std::list<std::string> gs_fileName_string; // global & static
15 
16 void cleaning_file(const std::string& folder_name, const std::string& file_name,
17  std::string& full_ret_file);
18 
19 void create_folder(const std::string& folder_name);
20 
21 template <typename T>
22 void saveVector(const DVec<T>& _vec, const std::string& folder_name,
23  const std::string& file_name) {
24  std::string full_file_name;
25  cleaning_file(folder_name, file_name, full_file_name);
26 
27  std::ofstream savefile(full_file_name.c_str(), std::ios::app);
28  for (int i(0); i < _vec.rows(); ++i) {
29  savefile << _vec(i) << "\t";
30  }
31  savefile << "\n";
32  savefile.flush();
33 }
34 
35 template <typename T>
36 void saveVector(const Vec3<T>& _vec, const std::string& folder_name,
37  const std::string& file_name) {
38  saveVector((DVec<T>)_vec, folder_name, file_name);
39 }
40 
41 template <typename T>
42 void saveVector(const std::vector<T>& _vec, const std::string& folder_name,
43  const std::string& file_name) {
44  std::string full_file_name;
45  cleaning_file(folder_name, file_name, full_file_name);
46  std::ofstream savefile(full_file_name.c_str(), std::ios::app);
47 
48  for (unsigned int i(0); i < _vec.size(); ++i) {
49  savefile << _vec[i] << "\t";
50  }
51  savefile << "\n";
52  savefile.flush();
53 }
54 
55 template <typename T>
56 void saveVector(T* _vec, const std::string& folder_name,
57  const std::string& file_name, int size) {
58  std::string full_file_name;
59  cleaning_file(folder_name, file_name, full_file_name);
60  std::ofstream savefile(full_file_name.c_str(), std::ios::app);
61  for (int i(0); i < size; ++i) {
62  savefile << _vec[i] << "\t";
63  }
64  savefile << "\n";
65  savefile.flush();
66 }
67 
68 template <typename T>
69 void saveValue(T _value, const std::string& folder_name,
70  const std::string& file_name) {
71  std::string full_file_name;
72  cleaning_file(folder_name, file_name, full_file_name);
73  std::ofstream savefile(full_file_name.c_str(), std::ios::app);
74 
75  savefile << _value << "\n";
76  savefile.flush();
77 }
78 
79 #endif
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
static std::list< std::string > gs_fileName_string
Definition: save_file.h:14
void saveVector(const DVec< T > &_vec, const std::string &folder_name, const std::string &file_name)
Definition: save_file.h:22
void cleaning_file(const std::string &folder_name, const std::string &file_name, std::string &full_ret_file)
Definition: save_file.cpp:3
std::string folder_name
Definition: test_spline.cpp:13
void create_folder(const std::string &folder_name)
Definition: save_file.cpp:16
void saveValue(T _value, const std::string &folder_name, const std::string &file_name)
Definition: save_file.h:69
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition: cppTypes.h:102