g4tools  5.4.0
Classes | Functions
tools::file Namespace Reference

Classes

class  reader
 

Functions

bool exists (const std::string &a_string)
 
bool write (const std::string &a_file, const std::string &a_string)
 
bool write (const std::string &a_file, const std::vector< std::string > &a_text)
 
bool make_empty (const std::string &a_file)
 
bool read_buff (FILE *a_file, char *a_buff, unsigned int a_lbuf, size_t &a_length)
 
bool read_cstring (FILE *a_file, char *a_buff, unsigned int a_lbuf, size_t &a_length)
 
bool read (FILE *a_FILE, std::vector< std::string > &a_text)
 
bool read (const std::string &a_file, std::vector< std::string > &a_text)
 
bool read_num (const std::string &a_file, std::vector< std::string >::size_type a_num, std::vector< std::string > &a_text, const std::string &a_cmt="")
 
bool read_bytes (const std::string &a_file, char *&a_buffer, long &a_length)
 
bool write_bytes (const std::string &a_file, const char *a_buffer, size_t a_length)
 
bool num_csv_doubles (const std::string &a_string, char &a_sep, unsigned int &a_number)
 
bool is_hippo (const std::string &a_file, bool &a_is)
 
bool is_csv (const std::vector< std::string > &a_txt, bool &a_is)
 
bool is_csv (const std::string &a_file, bool &a_is)
 
bool is_lua (const std::string &a_file, bool &a_is)
 
bool is_py (const std::string &a_file, bool &a_is)
 
bool is_kumac (const std::string &a_file, bool &a_is)
 
bool is_insh (const std::string &a_file, bool &a_is)
 
bool mime_type (const std::string &a_file, std::string &a_mime)
 
bool found (const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
 
bool std_remove (const std::string &a_file)
 
bool std_remove (std::vector< std::string > &a_files)
 
bool std_rename (const std::string &a_from, const std::string &a_to)
 
bool copy_bytes (const std::string &a_from, const std::string &a_to)
 
 TOOLS_GLOBAL_STRING (format_dst) inline void formats(std
 
std::string ext_fmt (const std::string &a_ext)
 
bool need_placement (const std::string &a_format)
 
bool is_paper_format (const std::string &a_format)
 
bool is_inzb_format (const std::string &a_format)
 
bool paper_format_extension (const std::string &a_format, std::string &a_ext)
 
bool is_zip (const std::string &a_file, bool &a_is)
 
bool is_jpeg (const std::string &a_file, bool &a_is)
 
bool is_ico (const std::string &a_file, bool &a_is)
 
bool is_png (const std::string &a_file, bool &a_is)
 
bool is_root (const std::string &a_file, bool &a_is)
 
bool is_iv (const std::string &a_file, bool &a_is)
 
bool is_wrl (const std::string &a_file, bool &a_is)
 
bool is_fog (const std::string &a_file, bool &a_is)
 
bool is_dot (const std::string &a_file, bool &a_is)
 
bool is_dcm (const std::string &a_file, bool &a_is)
 
bool is_gdml (const std::string &a_file, bool &a_is)
 
bool is_exsg (unsigned int a_sz, const char *a_buffer)
 
bool is_exsg (const std::string &a_file, bool &a_is)
 
bool is_bsg (unsigned int a_sz, const char *a_buffer)
 
bool is_bsg (const std::string &a_file, bool &a_is)
 
bool is_scenarios (const std::string &a_file, bool &a_is)
 
bool is_slides (const std::string &a_file, bool &a_is)
 
bool is_fits (const std::string &a_file, bool &a_is)
 
bool is_hdf (const std::string &a_file, bool &a_is)
 
bool is_ps (const std::string &a_file, bool &a_is)
 
bool is_simbad (const std::string &a_file, bool &a_is)
 
bool is_aida (const std::string &a_file, bool &a_is)
 
bool is_jive (const std::string &a_file, bool &a_is)
 
bool is_heprep (const std::string &a_file, bool &a_is)
 
bool is_shp (const std::string &a_file, bool &a_is)
 
bool size (const std::string &a_file, long &a_size)
 
bool is_empty (const std::string &a_file)
 
bool is_gzip (const std::string &a_file, bool &a_is)
 
bool gzip_usize (const std::string &a_file, unsigned int &a_usz)
 
bool extension_paper_format (const std::string &a_file, std::string &a_fmt)
 
bool signature (const std::string &a_file, unsigned char a_head[], unsigned int &a_num)
 

Function Documentation

◆ copy_bytes()

bool tools::file::copy_bytes ( const std::string &  a_from,
const std::string &  a_to 
)
inline

Definition at line 544 of file file.

544  {
545  if(a_to==a_from) return true;
546  char* buffer;
547  long length;
548  if(!read_bytes(a_from,buffer,length)) return false;
549  bool status = write_bytes(a_to,buffer,(size_t)length);
550  delete [] buffer;
551 #ifdef TOOLS_MEM
552  mem::decrement(s_new().c_str());
553 #endif
554  return status;
555 }

◆ exists()

bool tools::file::exists ( const std::string &  a_string)
inline

Definition at line 23 of file file.

23  {
24  FILE* file = ::fopen(a_string.c_str(),"rb");
25  if(!file) return false;
26  ::fclose(file);
27  return true;
28 }

◆ ext_fmt()

std::string tools::file::ext_fmt ( const std::string &  a_ext)
inline

Definition at line 127 of file file_format.

127  {
128  if(a_ext==s_ext_fits()) return s_format_fits();
129  if(a_ext==s_ext_aida()) return s_format_aida();
130  if(a_ext==s_ext_root()) return s_format_root();
131  if(a_ext==s_ext_dst()) return s_format_dst();
132  if(a_ext==s_ext_csv()) return s_format_csv();
133  if(a_ext==s_ext_tnt()) return s_format_hippo();
134  if(a_ext==s_ext_hiptxt()) return s_format_hippo();
135  if(a_ext==s_ext_hdf5()) return s_format_hdf5();
136  if(a_ext==s_ext_jpeg()) return s_format_jpeg();
137  if(a_ext==s_ext_jpg()) return s_format_jpeg();
138  if(a_ext==s_ext_png()) return s_format_png();
139  if(a_ext==s_ext_fog()) return s_format_fog();
140  if(a_ext==s_ext_dot()) return s_format_dot();
141  if(a_ext==s_ext_dcm()) return s_format_dcm();
142  if(a_ext==s_ext_iv()) return s_format_iv();
143  if(a_ext==s_ext_hiv()) return s_format_iv();
144  if(a_ext==s_ext_wrl()) return s_format_wrl();
145  if(a_ext==s_ext_exsg()) return s_format_exsg();
146  if(a_ext==s_ext_bsg()) return s_format_bsg();
147  if(a_ext==s_ext_scenarios()) return s_format_scenarios();
148  if(a_ext==s_ext_slides()) return s_format_slides();
149  if(a_ext==s_ext_zvid()) return s_format_zvid();
150  if(a_ext==s_ext_gdml()) return s_format_gdml();
151  if(a_ext==s_ext_mac()) return s_format_mac();
152  if(a_ext==s_ext_cmnd()) return s_format_cmnd();
153  if(a_ext==s_ext_jive()) return s_format_jive();
154  if(a_ext==s_ext_heprep()) return s_format_heprep();
155  if(a_ext==s_ext_zheprep()) return s_format_zheprep();
156  if(a_ext==s_ext_lua()) return s_format_lua();
157  if(a_ext==s_ext_py()) return s_format_py();
158  if(a_ext==s_ext_kumac()) return s_format_kumac();
159  if(a_ext==s_ext_insh()) return s_format_insh();
160  if(a_ext==s_ext_shp()) return s_format_shp();
161  if(a_ext==s_ext_simbad()) return s_format_simbad();
162  return s_format_guessed();
163 }

◆ extension_paper_format()

bool tools::file::extension_paper_format ( const std::string &  a_file,
std::string &  a_fmt 
)
inline

Definition at line 16 of file paper_format.

16  {
17  std::string path,name,suffix;
18  if(!path_name_suffix(a_file,path,name,suffix)) {a_fmt.clear();return false;}
20  if((suffix=="ps")||(suffix=="eps")) {
21  a_fmt = "inzb_ps";
22  return true;
23  } else if(suffix=="png") {
24  a_fmt = "inzb_png";
25  return true;
26  } else if((suffix=="jpg")||(suffix=="jpeg")) {
27  a_fmt = "inzb_jpeg";
28  return true;
29 
30  } else if(suffix=="pdf") {
31  a_fmt = "gl2ps_pdf";
32  return true;
33  } else if(suffix=="svg") {
34  a_fmt = "gl2ps_svg";
35  return true;
36  } else if(suffix=="pgf") {
37  a_fmt = "gl2ps_pgf";
38  return true;
39  } else if(suffix=="tex") {
40  a_fmt = "gl2ps_tex";
41  return true;
42  }
43  a_fmt.clear();
44  return false;
45 }

◆ found()

bool tools::file::found ( const std::string &  a_file,
const std::string &  a_what,
std::vector< std::string > &  a_found 
)
inline

Definition at line 507 of file file.

507  {
508  a_found.clear();
509  std::vector<std::string> text;
510  if(!file::read(a_file,text)) return false;
511  tools_vforcit(std::string,text,it) {
512  if((*it).find(a_what)!=std::string::npos) {
513  a_found.push_back(*it);
514  }
515  }
516  return true;
517 }

◆ gzip_usize()

bool tools::file::gzip_usize ( const std::string &  a_file,
unsigned int &  a_usz 
)
inline

Definition at line 25 of file gzip.

25  {
26  bool is;
27  if(!is_gzip(a_file,is)) {a_usz=0;return false;}
28  if(!is) {a_usz=0;return false;}
29  FILE* file = ::fopen(a_file.c_str(),"rb");
30  if(!file) {a_usz=0;return false;}
31  ::fseek(file,-4,SEEK_END);
32  unsigned char buf[4];
33  size_t n = ::fread(buf,1,4,file);
34  ::fclose(file);
35  if(n!=4) {a_usz=0;return false;}
36  unsigned int b4 = buf[0];
37  unsigned int b3 = buf[1];
38  unsigned int b2 = buf[2];
39  unsigned int b1 = buf[3];
40  a_usz = (b1 << 24) | ((b2 << 16) + (b3 << 8) + b4);
41  return true;
42 }

◆ is_aida()

bool tools::file::is_aida ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 296 of file fileis.

296  {
297  long sz;
298  if(!size(a_file,sz)) {a_is = false;return false;}
299 
300  //NOTE : it assumes that the file is not compressed.
301  unsigned char head[1024];
302  {unsigned int num = 1024;
303  if(!signature(a_file,head,num)) {a_is = false;return false;}
304  if(num!=1024) {a_is = false;return true;}}
305  head[1023] = 0; //to have a C string.
306  a_is = ::strstr((const char*)head,"<aida")?true:false;
307  return true;
308 }

◆ is_bsg() [1/2]

bool tools::file::is_bsg ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 185 of file fileis.

185  {
186  unsigned char head[7];
187  {unsigned int num = 7;
188  if(!signature(a_file,head,num)) {a_is = false;return false;}
189  if(num!=7) {a_is = false;return true;}}
190  a_is = is_bsg(7,(const char*)head);
191  return true;
192 }

◆ is_bsg() [2/2]

bool tools::file::is_bsg ( unsigned int  a_sz,
const char *  a_buffer 
)
inline

Definition at line 173 of file fileis.

173  {
174  if(a_sz<7) return false;
175  if(a_buffer[0]!='i') return false;
176  if(a_buffer[1]!='n') return false;
177  if(a_buffer[2]!='e') return false;
178  if(a_buffer[3]!='x') return false;
179  if(a_buffer[4]!='b') return false;
180  if(a_buffer[5]!='s') return false;
181  if(a_buffer[6]!='g') return false;
182  return true;
183 }

◆ is_csv() [1/2]

bool tools::file::is_csv ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 327 of file file.

327  {
328  // look at suffix. Some file can't be guessed.
329  if(suffix(a_file)=="csv") {a_is = true;return true;}
330  //try to guess :
331  std::vector<std::string> txt;
332  if(!file::read_num(a_file,3,txt,"#")) {a_is=false;return false;}
333  return is_csv(txt,a_is);
334 }

◆ is_csv() [2/2]

bool tools::file::is_csv ( const std::vector< std::string > &  a_txt,
bool &  a_is 
)
inline

Definition at line 277 of file file.

277  {
278  //a_sep = 0;
279  a_is = false;
280  if(a_txt.empty()) return true;
281 
282  //guess sep from first data line :
283  char sep = 0;
284  {const char* buffer = a_txt[0].c_str();
285  //::printf("debug : |%s|\n",buffer);
286  const char* pos = buffer;
287  char* end;
288  {double d = ::strtod(pos,&end);(void)d;}
289  //::printf("debug : d first %g\n",d);
290  if(end==pos) return true; //not starting with a number.
291  //end==mx is ok, one column only.
292  sep = *end;}
293 
294  //::printf("debug : %d\n",sep);
295 
296  unsigned int first_coln = 0;
297 
298  tools_vforcit(std::string,a_txt,it) {
299  const char* buffer = (*it).c_str();
300  //::printf("debug : |%s|\n",buffer);
301  const char* pos = buffer;
302  const char* mx = buffer+(*it).size();
303  unsigned int coln = 0;
304  while(true) {
305  char* end;
306  {double d = ::strtod(pos,&end);(void)d;}
307  if(end==pos) break;
308  //::printf("debug : d %g\n",d);
309  if(*end!=sep) return true;
310  coln++;
311  pos = end+1;
312  if(pos>mx) break;
313  }
314  //::printf("debug : coln %d\n",coln);
315  if(it==a_txt.begin()) {
316  first_coln = coln;
317  } else {
318  if(coln!=first_coln) return true;
319  }
320  }
321 
322  //a_sep = sep;
323  a_is = true;
324  return true;
325 }

◆ is_dcm()

bool tools::file::is_dcm ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 130 of file fileis.

130  {
131  unsigned char head[132];
132  {unsigned int num = 132;
133  if(!signature(a_file,head,num)) {a_is = false;return false;}
134  if(num!=132) {a_is = false;return true;}}
135  if(head[128]!='D') {a_is = false;return true;}
136  if(head[129]!='I') {a_is = false;return true;}
137  if(head[130]!='C') {a_is = false;return true;}
138  if(head[131]!='M') {a_is = false;return true;}
139  a_is = true;
140  return true;
141 }

◆ is_dot()

bool tools::file::is_dot ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 120 of file fileis.

120  {
121  unsigned char head[8];
122  {unsigned int num = 7;
123  if(!signature(a_file,head,num)) {a_is = false;return false;}
124  if(num!=7) {a_is = false;return true;}}
125  head[7] = 0; //to have a C string.
126  a_is = ::strcmp((const char*)head,"digraph")?false:true;
127  return true;
128 }

◆ is_empty()

bool tools::file::is_empty ( const std::string &  a_file)
inline

Definition at line 26 of file fsize.

26  {
27  long sz;
28  if(!size(a_file,sz)) return true; //if not existing, consider it empty.
29  return (sz==0L)?true:false;
30 }

◆ is_exsg() [1/2]

bool tools::file::is_exsg ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 164 of file fileis.

164  {
165  unsigned char head[5];
166  {unsigned int num = 5;
167  if(!signature(a_file,head,num)) {a_is = false;return false;}
168  if(num!=5) {a_is = false;return true;}}
169  a_is = is_exsg(5,(const char*)head);
170  return true;
171 }

◆ is_exsg() [2/2]

bool tools::file::is_exsg ( unsigned int  a_sz,
const char *  a_buffer 
)
inline

Definition at line 154 of file fileis.

154  {
155  if(a_sz<5) return false;
156  if(a_buffer[0]!='<') return false;
157  if(a_buffer[1]!='e') return false;
158  if(a_buffer[2]!='x') return false;
159  if(a_buffer[3]!='s') return false;
160  if(a_buffer[4]!='g') return false;
161  return true;
162 }

◆ is_fits()

bool tools::file::is_fits ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 229 of file fileis.

229  {
230  unsigned char head[6];
231  {unsigned int num = 6;
232  if(!signature(a_file,head,num)) {a_is = false;return false;}
233  if(num!=6) {a_is = false;return true;}}
234  if(head[0]!='S') {a_is = false;return true;}
235  if(head[1]!='I') {a_is = false;return true;}
236  if(head[2]!='M') {a_is = false;return true;}
237  if(head[3]!='P') {a_is = false;return true;}
238  if(head[4]!='L') {a_is = false;return true;}
239  if(head[5]!='E') {a_is = false;return true;}
240  a_is = true;
241  return true;
242 }

◆ is_fog()

bool tools::file::is_fog ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 110 of file fileis.

110  {
111  unsigned char head[256];
112  {unsigned int num = 256;
113  if(!signature(a_file,head,num)) {a_is = false;return false;}
114  if(num!=256) {a_is = false;return true;}}
115  head[255] = 0; //to have a C string.
116  a_is = ::strstr((const char*)head,"#nb super-volumes")?true:false;
117  return true;
118 }

◆ is_gdml()

bool tools::file::is_gdml ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 143 of file fileis.

143  {
144  //NOTE : it assumes that the file is not compressed.
145  unsigned char head[1024];
146  {unsigned int num = 1024;
147  if(!signature(a_file,head,num)) {a_is = false;return false;}
148  if(num!=1024) {a_is = false;return true;}}
149  head[1023] = 0; //to have a C string.
150  a_is = ::strstr((const char*)head,"<gdml")?true:false;
151  return true;
152 }

◆ is_gzip()

bool tools::file::is_gzip ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 12 of file gzip.

12  {
13  unsigned char head[4];
14  {unsigned int num = 4;
15  if(!signature(a_file,head,num)) {a_is = false;return false;}
16  if(num!=4) {a_is = false;return true;}}
17  if(head[0]!=31) {a_is = false;return true;}
18  if(head[1]!=139) {a_is = false;return true;}
19  //if(head[2]!=8) {a_is = false;return true;}
20  //if(head[3]!=8) {a_is = false;return true;}
21  a_is = true;
22  return true;
23 }

◆ is_hdf()

bool tools::file::is_hdf ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 244 of file fileis.

244  {
245  unsigned char head[4];
246  {unsigned int num = 4;
247  if(!signature(a_file,head,num)) {a_is = false;return false;}
248  if(num!=4) {a_is = false;return true;}}
249  if(head[0]!=137) {a_is = false;return true;}
250  if(head[1]!='H') {a_is = false;return true;}
251  if(head[2]!='D') {a_is = false;return true;}
252  if(head[3]!='F') {a_is = false;return true;}
253  a_is = true;
254  return true;
255 }

◆ is_heprep()

bool tools::file::is_heprep ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 325 of file fileis.

325  {
326  long sz;
327  if(!size(a_file,sz)) {a_is = false;return false;}
328 
329  //NOTE : it assumes that the file is not compressed.
330  unsigned char head[1024];
331  {unsigned int num = 1024;
332  if(!signature(a_file,head,num)) {a_is = false;return false;}
333  if(num!=1024) {a_is = false;return true;}}
334  head[1023] = 0; //to have a C string.
335  a_is = ::strstr((const char*)head,"<heprep")?true:false;
336  return true;
337 }

◆ is_hippo()

bool tools::file::is_hippo ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 246 of file file.

246  {
247  //if((suffix(a_file)=="hiptxt")||(suffix(a_file)=="tnt")) {
248  // a_is = true;
249  // return true;
250  //}
251  // An hippo file as :
252  // one line for title.
253  // one line with n labels separated by \t
254  // data lines with n numbers separated by a char sep (not necessary \t) (at least one data line expected).
255  std::vector<std::string> txt;
256  if(!file::read_num(a_file,3,txt)) {a_is=false;return false;}
257  if(txt.size()<3) {a_is=false;return true;}
258  char csep;
259  unsigned int number;
260  if(!num_csv_doubles(txt[2],csep,number)) {a_is=false;return true;}
261  std::vector<std::string> ws;
262  words(txt[1],"\t",false,ws);
263  if(ws.size()!=number) {a_is=false;return true;}
264  bool all_doubles = true;
265  tools_vforcit(std::string,ws,it) {
266  const char* pos = (*it).c_str();
267  char* end;
268  double d = ::strtod(pos,&end);(void)d;
269  if(end==pos) {all_doubles=false;break;}
270  }
271  a_is = all_doubles?false:true; //all_double=false then we assume the second line is labels of columns.
272  return true;
273 }

◆ is_ico()

bool tools::file::is_ico ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 39 of file fileis.

39  {
40  unsigned char head[4];
41  {unsigned int num = 4;
42  if(!signature(a_file,head,num)) {a_is = false;return false;}
43  if(num!=4) {a_is = false;return true;}}
44  if(head[0]!=0) {a_is = false;return true;}
45  if(head[1]!=0) {a_is = false;return true;}
46  if(head[2]!=1) {a_is = false;return true;}
47  if(head[3]!=0) {a_is = false;return true;}
48  a_is = true;
49  return true;
50 }

◆ is_insh()

bool tools::file::is_insh ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 360 of file file.

360  {
361  if(suffix(a_file)=="insh") {a_is = true;return true;}
362  unsigned char head[6];
363  {unsigned int num = 6;
364  if(!signature(a_file,head,num)) {a_is = false;return false;}
365  if(num!=6) {a_is = false;return true;}}
366  if(head[0]!='#') {a_is = false;return true;}
367  if(head[1]!='!') {a_is = false;return true;}
368  if(head[2]!='i') {a_is = false;return true;}
369  if(head[3]!='n') {a_is = false;return true;}
370  if(head[4]!='s') {a_is = false;return true;}
371  if(head[5]!='h') {a_is = false;return true;}
372  a_is = true;
373  return true;
374 }

◆ is_inzb_format()

bool tools::file::is_inzb_format ( const std::string &  a_format)
inline

Definition at line 216 of file file_format.

216  {
217  if(a_format=="inzb_ps") return true;
218  if(a_format=="inzb_jpeg") return true;
219  if(a_format=="inzb_png") return true;
220  return false;
221 }

◆ is_iv()

bool tools::file::is_iv ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 78 of file fileis.

78  {
79  unsigned char head[9];
80  {unsigned int num = 9;
81  if(!signature(a_file,head,num)) {a_is = false;return false;}
82  if(num!=9) {a_is = false;return true;}}
83  if(head[0]!='#') {a_is = false;return true;}
84  if(head[1]!='I') {a_is = false;return true;}
85  if(head[2]!='n') {a_is = false;return true;}
86  if(head[3]!='v') {a_is = false;return true;}
87  if(head[4]!='e') {a_is = false;return true;}
88  if(head[5]!='n') {a_is = false;return true;}
89  if(head[6]!='t') {a_is = false;return true;}
90  if(head[7]!='o') {a_is = false;return true;}
91  if(head[8]!='r') {a_is = false;return true;}
92  a_is = true;
93  return true;
94 }

◆ is_jive()

bool tools::file::is_jive ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 310 of file fileis.

310  {
311  long sz;
312  if(!size(a_file,sz)) {a_is = false;return false;}
313 
314  //NOTE : it assumes that the file is not compressed.
315  unsigned char head[1024];
316  {unsigned int num = 1024;
317  if(!signature(a_file,head,num)) {a_is = false;return false;}
318  if(num!=1024) {a_is = false;return true;}}
319  head[1023] = 0; //to have a C string.
320  if(::strstr((const char*)head,"<?ATLAS")) {a_is = true;return true;}
321  a_is = ::strstr((const char*)head,"<!DOCTYPE Event")?true:false;
322  return true;
323 }

◆ is_jpeg()

bool tools::file::is_jpeg ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 26 of file fileis.

26  {
27  unsigned char head[4];
28  {unsigned int num = 4;
29  if(!signature(a_file,head,num)) {a_is = false;return false;}
30  if(num!=4) {a_is = false;return true;}}
31  if(head[0]!=255) {a_is = false;return true;}
32  if(head[1]!=216) {a_is = false;return true;}
33  if(head[2]!=255) {a_is = false;return true;}
34  //if(head[3]!=224) {a_is = false;return true;} //LRI.jpg is 225 !
35  a_is = true;
36  return true;
37 }

◆ is_kumac()

bool tools::file::is_kumac ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 352 of file file.

352  {
353  // look at suffix. Some file can't be guessed.
354  if(suffix(a_file)=="kumac") {a_is = true;return true;}
355  //try to guess ?
356  a_is = false;
357  return true;
358 }

◆ is_lua()

bool tools::file::is_lua ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 336 of file file.

336  {
337  // look at suffix. Some file can't be guessed.
338  if(suffix(a_file)=="lua") {a_is = true;return true;}
339  //try to guess ?
340  a_is = false;
341  return true;
342 }

◆ is_paper_format()

bool tools::file::is_paper_format ( const std::string &  a_format)
inline

Definition at line 203 of file file_format.

203  {
204  if(a_format=="gl2ps_eps") return true;
205  if(a_format=="gl2ps_ps") return true;
206  if(a_format=="gl2ps_pdf") return true;
207  if(a_format=="gl2ps_svg") return true;
208  if(a_format=="gl2ps_tex") return true;
209  if(a_format=="gl2ps_pgf") return true;
210  if(a_format=="inzb_ps") return true;
211  if(a_format=="inzb_jpeg") return true;
212  if(a_format=="inzb_png") return true;
213  return false;
214 }

◆ is_png()

bool tools::file::is_png ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 52 of file fileis.

52  {
53  unsigned char head[4];
54  {unsigned int num = 4;
55  if(!signature(a_file,head,num)) {a_is = false;return false;}
56  if(num!=4) {a_is = false;return true;}}
57  if(head[0]!=137) {a_is = false;return true;}
58  if(head[1]!='P') {a_is = false;return true;}
59  if(head[2]!='N') {a_is = false;return true;}
60  if(head[3]!='G') {a_is = false;return true;}
61  a_is = true;
62  return true;
63 }

◆ is_ps()

bool tools::file::is_ps ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 257 of file fileis.

257  {
258  unsigned char head[4];
259  {unsigned int num = 4;
260  if(!signature(a_file,head,num)) {a_is = false;return false;}
261  if(num!=4) {a_is = false;return true;}}
262  if(head[0]!='%') {a_is = false;return true;}
263  if(head[1]!='!') {a_is = false;return true;}
264  if(head[2]!='P') {a_is = false;return true;}
265  if(head[3]!='S') {a_is = false;return true;}
266  a_is = true;
267  return true;
268 }

◆ is_py()

bool tools::file::is_py ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 344 of file file.

344  {
345  // look at suffix. Some file can't be guessed.
346  if(suffix(a_file)=="py") {a_is = true;return true;}
347  //try to guess ?
348  a_is = false;
349  return true;
350 }

◆ is_root()

bool tools::file::is_root ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 65 of file fileis.

65  {
66  unsigned char head[4];
67  {unsigned int num = 4;
68  if(!signature(a_file,head,num)) {a_is = false;return false;}
69  if(num!=4) {a_is = false;return true;}}
70  if(head[0]!='r') {a_is = false;return true;}
71  if(head[1]!='o') {a_is = false;return true;}
72  if(head[2]!='o') {a_is = false;return true;}
73  if(head[3]!='t') {a_is = false;return true;}
74  a_is = true;
75  return true;
76 }

◆ is_scenarios()

bool tools::file::is_scenarios ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 194 of file fileis.

194  {
195  unsigned char head[10];
196  {unsigned int num = 10;
197  if(!signature(a_file,head,num)) {a_is = false;return false;}
198  if(num!=10) {a_is = false;return true;}}
199  if(head[0]!='<') {a_is = false;return true;}
200  if(head[1]!='s') {a_is = false;return true;}
201  if(head[2]!='c') {a_is = false;return true;}
202  if(head[3]!='e') {a_is = false;return true;}
203  if(head[4]!='n') {a_is = false;return true;}
204  if(head[5]!='a') {a_is = false;return true;}
205  if(head[6]!='r') {a_is = false;return true;}
206  if(head[7]!='i') {a_is = false;return true;}
207  if(head[8]!='o') {a_is = false;return true;}
208  if(head[9]!='s') {a_is = false;return true;}
209  a_is = true;
210  return true;
211 }

◆ is_shp()

bool tools::file::is_shp ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 346 of file fileis.

346  {
347  long sz;
348  if(!size(a_file,sz)) {a_is = false;return false;}
349  // below logic from shapelib-1.5.0/shpopen.c.
350  unsigned char head[100];
351  {unsigned int num = 100;
352  if(!signature(a_file,head,num)) {a_is = false;return false;}
353  if(num!=100) {a_is = false;return true;}}
354  unsigned int _sz = (static_cast<unsigned int>(head[24])<<24)|(head[25]<<16)|(head[26]<<8)|head[27];
355  if(_sz<(UINT_MAX/2)) _sz *= 2;
356  else _sz = (UINT_MAX/2)*2;
357  a_is = sz==long(_sz)?true:false;
358  return true;
359 }

◆ is_simbad()

bool tools::file::is_simbad ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 270 of file fileis.

270  {
271  unsigned char head[10];
272  {unsigned int num = 10;
273  if(!signature(a_file,head,num)) {a_is = false;return false;}
274  if(num!=10) {a_is = false;return true;}}
275  if(head[0]!=':') {a_is = false;return true;}
276  if(head[1]!=':') {a_is = false;return true;}
277  if(head[2]!='s') {a_is = false;return true;}
278  if(head[3]!='c') {a_is = false;return true;}
279  if(head[4]!='r') {a_is = false;return true;}
280  if(head[5]!='i') {a_is = false;return true;}
281  if(head[6]!='p') {a_is = false;return true;}
282  if(head[7]!='t') {a_is = false;return true;}
283  if(head[8]!=':') {a_is = false;return true;}
284  if(head[9]!=':') {a_is = false;return true;}
285  a_is = true;
286  return true;
287 }

◆ is_slides()

bool tools::file::is_slides ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 213 of file fileis.

213  {
214  unsigned char head[7];
215  {unsigned int num = 7;
216  if(!signature(a_file,head,num)) {a_is = false;return false;}
217  if(num!=7) {a_is = false;return true;}}
218  if(head[0]!='<') {a_is = false;return true;}
219  if(head[1]!='s') {a_is = false;return true;}
220  if(head[2]!='l') {a_is = false;return true;}
221  if(head[3]!='i') {a_is = false;return true;}
222  if(head[4]!='d') {a_is = false;return true;}
223  if(head[5]!='e') {a_is = false;return true;}
224  if(head[6]!='s') {a_is = false;return true;}
225  a_is = true;
226  return true;
227 }

◆ is_wrl()

bool tools::file::is_wrl ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 96 of file fileis.

96  {
97  unsigned char head[5];
98  {unsigned int num = 5;
99  if(!signature(a_file,head,num)) {a_is = false;return false;}
100  if(num!=5) {a_is = false;return true;}}
101  if(head[0]!='#') {a_is = false;return true;}
102  if(head[1]!='V') {a_is = false;return true;}
103  if(head[2]!='R') {a_is = false;return true;}
104  if(head[3]!='M') {a_is = false;return true;}
105  if(head[4]!='L') {a_is = false;return true;}
106  a_is = true;
107  return true;
108 }

◆ is_zip()

bool tools::file::is_zip ( const std::string &  a_file,
bool &  a_is 
)
inline

Definition at line 13 of file fileis.

13  {
14  unsigned char head[4];
15  {unsigned int num = 4;
16  if(!signature(a_file,head,num)) {a_is = false;return false;}
17  if(num!=4) {a_is = false;return true;}}
18  if(head[0]!='P') {a_is = false;return true;}
19  if(head[1]!='K') {a_is = false;return true;}
20  if(head[2]!=3) {a_is = false;return true;}
21  if(head[3]!=4) {a_is = false;return true;}
22  a_is = true;
23  return true;
24 }

◆ make_empty()

bool tools::file::make_empty ( const std::string &  a_file)
inline

Definition at line 55 of file file.

55  {
56  FILE* file = ::fopen(a_file.c_str(),"wb");
57  if(!file) return false;
58  ::fclose(file);
59  return true;
60 }

◆ mime_type()

bool tools::file::mime_type ( const std::string &  a_file,
std::string &  a_mime 
)
inline

Definition at line 383 of file file.

383  {
385  // binaries :
387  {bool is;
388  if(is_jpeg(a_file,is)&&is) {
389  a_mime = "image/jpeg";
390  return true;
391  }}
392 
393  {bool is;
394  if(is_png(a_file,is)&&is) {
395  a_mime = "image/png";
396  return true;
397  }}
398 
399  {bool is;
400  if(is_ico(a_file,is)&&is) {
401  a_mime = "image/vnd.microsoft.icon";
402  return true;
403  }}
404 
405  {bool is;
406  if(is_fits(a_file,is)&&is) {
407  a_mime = "image/fits";
408  return true;
409  }}
410 
411  {bool is;
412  if(is_gzip(a_file,is)&&is) {
413  a_mime = "application/gzip";
414  return true;
415  }}
416 
417  {bool is;
418  if(is_zip(a_file,is)&&is) {
419  a_mime = "application/zip";
420  return true;
421  }}
422 
423  {bool is;
424  if(is_root(a_file,is)&&is) {
425  a_mime = "application/octet-stream";
426  return true;
427  }}
428 
430  // text :
432  {bool is;
433  if(is_aida(a_file,is)&&is) {
434  a_mime = "text/xml";
435  return true;
436  }}
437  {bool is;
438  if(is_exsg(a_file,is)&&is) {
439  a_mime = "text/xml";
440  return true;
441  }}
442  {bool is;
443  if(is_scenarios(a_file,is)&&is) {
444  a_mime = "text/xml";
445  return true;
446  }}
447  {bool is;
448  if(is_slides(a_file,is)&&is) {
449  a_mime = "text/xml";
450  return true;
451  }}
452  {bool is;
453  if(is_gdml(a_file,is)&&is) {
454  a_mime = "text/xml";
455  return true;
456  }}
457 
458  {bool is;
459  if(is_ps(a_file,is)&&is) {
460  a_mime = "application/postscript";
461  return true;
462  }}
463 
464  {bool is;
465  if(is_fog(a_file,is)&&is) {
466  a_mime = "text/plain";
467  return true;
468  }}
469 
470  {bool is;
471  if(is_csv(a_file,is)&&is) {
472  a_mime = "text/csv";
473  return true;
474  }}
475 
476  {bool is;
477  if(is_hippo(a_file,is)&&is) {
478  a_mime = "text/plain";
479  return true;
480  }}
481 
482  {bool is;
483  if(is_dot(a_file,is)&&is) {
484  a_mime = "text/plain";
485  return true;
486  }}
487 
488  {bool is;
489  if(is_iv(a_file,is)&&is) {
490  a_mime = "application/octet-stream";
491  return true;
492  }}
493 
494  a_mime = "application/octet-stream";
495  return false;
496 }

◆ need_placement()

bool tools::file::need_placement ( const std::string &  a_format)
inline

Definition at line 165 of file file_format.

165  {
166  if(a_format==s_format_guessed()) return true;
167 //if(a_format==s_format_hdf5()) return true;
168 //if(a_format==s_format_fits()) return true;
169 //if(a_format==s_format_fog()) return true; //load in static_sg.
170 //if(a_format==s_format_dot()) return true;
171 //if(a_format==s_format_dcm()) return true;
172 //if(a_format==s_format_iv()) return true; //load in static_sg.
173 //if(a_format==s_format_wrl()) return true; //load in static_sg.
174 //if(a_format==s_format_jpeg()) return true;
175 //if(a_format==s_format_png()) return true;
176 //if(a_format==s_format_root()) return true;
177 //if(a_format==s_format_dst()) return true;
178 //if(a_format==s_format_csv()) return true;
179 //if(a_format==s_format_hippo()) return true;
180 //if(a_format==s_format_scenarios()) return true;
181 //if(a_format==s_format_slides()) return true;
182 //if(a_format==s_format_zvid()) return true;
183  if(a_format==s_format_exsg()) return true;
184 //if(a_format==s_format_gdml()) return true; //load in static_sg.
185 //if(a_format==s_format_mac()) return true;
186 //if(a_format==s_format_cmnd()) return true;
187 //if(a_format==s_format_aida()) return true;
188  if(a_format==s_format_bsg()) return true;
189 //if(a_format==s_format_jive()) return true; //load in dynamic_sg.
190 //if(a_format==s_format_heprep()) return true; //load in static_sg.
191 //if(a_format==s_format_zheprep()) return true; //load in static_sg.
192 //if(a_format==s_format_lua()) return true;
193 //if(a_format==s_format_py()) return true;
194 //if(a_format==s_format_kumac()) return true;
195 //if(a_format==s_format_insh()) return true;
196 //if(a_format==s_format_shp()) return true; //load in static_sg.
197 //if(a_format==s_format_simbad()) return true; //load in arg sep.
198  return false;
199 }

◆ num_csv_doubles()

bool tools::file::num_csv_doubles ( const std::string &  a_string,
char &  a_sep,
unsigned int &  a_number 
)
inline

Definition at line 194 of file file.

194  {
195  if(a_string.empty()) {a_sep=0;a_number=0;return true;} //it is ok.
196 
197  //guess sep :
198  char sep = 0;
199  {const char* buffer = a_string.c_str();
200  //::printf("debug : |%s|\n",buffer);
201  const char* pos = buffer;
202  const char* mx = buffer+a_string.size();
203  char* end;
204  {double d = ::strtod(pos,&end);(void)d;}
205  //::printf("debug : d first %g\n",d);
206  if(end==pos) {a_sep=0;a_number=0;return false;} //not starting with a number.
207  if(end==mx) {a_sep=0;a_number=1;return true;} //is ok, one number only.
208  sep = *end;}
209 
210  //::printf("debug : %d\n",sep);
211 
212  unsigned int number = 0;
213 
214  const char* buffer = a_string.c_str();
215  //::printf("debug : |%s|\n",buffer);
216  const char* pos = buffer;
217  const char* mx = buffer+a_string.size();
218  while(true) {
219  char* end;
220  {double d = ::strtod(pos,&end);(void)d;}
221  if(end==pos) {
222  if(end>=mx) break;
223  a_sep = sep;
224  a_number = number;
225  return false; //since a number expected.
226  }
227  //::printf("debug : d %g\n",d);
228  number++;
229  if(*end!=sep) {
230  if(end>=mx) break;
231  a_sep = sep;
232  a_number = number;
233  return false; //since a sep is expected.
234  }
235  pos = end+1;
236  if(pos>mx) break;
237  }
238 
239  a_sep = sep;
240  a_number = number;
241  return true;
242 }

◆ paper_format_extension()

bool tools::file::paper_format_extension ( const std::string &  a_format,
std::string &  a_ext 
)
inline

Definition at line 223 of file file_format.

223  {
224  if(a_format=="gl2ps_eps") {a_ext = "eps";return true;}
225  if(a_format=="gl2ps_ps") {a_ext = "ps";return true;}
226  if(a_format=="gl2ps_pdf") {a_ext = "pdf";return true;}
227  if(a_format=="gl2ps_svg") {a_ext = "svg";return true;}
228  if(a_format=="gl2ps_tex") {a_ext = "tex";return true;}
229  if(a_format=="gl2ps_pgf") {a_ext = "pgf";return true;}
230  if(a_format=="inzb_ps") {a_ext = "ps";return true;}
231  if(a_format=="inzb_jpeg") {a_ext = "jpeg";return true;}
232  if(a_format=="inzb_png") {a_ext = "png";return true;}
233  a_ext.clear();
234  return false;
235 }

◆ read() [1/2]

bool tools::file::read ( const std::string &  a_file,
std::vector< std::string > &  a_text 
)
inline

Definition at line 103 of file file.

103  {
104  FILE* file = ::fopen(a_file.c_str(),"rb");
105  if(!file) {a_text.clear();return false;}
106  bool status = read(file,a_text);
107  ::fclose(file);
108  return status;
109 }

◆ read() [2/2]

bool tools::file::read ( FILE *  a_FILE,
std::vector< std::string > &  a_text 
)
inline

Definition at line 89 of file file.

89  {
90  a_text.clear();
91  unsigned int BUFSIZE = 65536;
92  char* buffer = new char[BUFSIZE+1];
93  if(!buffer) return false;
94  while(true) {
95  size_t l;
96  if(!read_cstring(a_FILE,buffer,BUFSIZE,l)) break; // EOF.
97  a_text.push_back(buffer);
98  }
99  delete [] buffer;
100  return true;
101 }

◆ read_buff()

bool tools::file::read_buff ( FILE *  a_file,
char *  a_buff,
unsigned int  a_lbuf,
size_t &  a_length 
)
inline

Definition at line 62 of file file.

62  {
63  a_length = ::fread(a_buff,1,a_lbuf,a_file);
64  return true;
65 }

◆ read_bytes()

bool tools::file::read_bytes ( const std::string &  a_file,
char *&  a_buffer,
long &  a_length 
)
inline

Definition at line 133 of file file.

133  {
134  // Returned buffer should be deleted with delete [].
135  FILE* file = ::fopen(a_file.c_str(),"rb");
136  if(!file) {
137  a_buffer = 0;
138  a_length = 0L;
139  return false;
140  }
141  // Get file size :
142  ::fseek(file,0L,SEEK_END);
143  long filesize = ::ftell(file);
144  if(!filesize) {
145  ::fclose(file);
146  a_buffer = new char[1];
147 #ifdef TOOLS_MEM
148  mem::increment(s_new().c_str());
149 #endif
150  a_length = 0L;
151  return true; //empty file.
152  }
153  // Add one byte to be able to add \n if file contain lines.
154  a_buffer = new char[filesize+1];
155  if(!a_buffer) {
156  ::fclose(file);
157  a_buffer = 0;
158  a_length = 0L;
159  return false;
160  }
161 #ifdef TOOLS_MEM
162  mem::increment(s_new().c_str());
163 #endif
164  ::rewind(file);
165  size_t nitem = ::fread(a_buffer,(size_t)filesize,(size_t)1,file);
166  if(nitem!=1){
167  ::fclose(file);
168  delete [] a_buffer;
169 #ifdef TOOLS_MEM
170  mem::decrement(s_new().c_str());
171 #endif
172  a_buffer = 0;
173  a_length = 0L;
174  return false;
175  }
176  ::fclose(file);
177  a_buffer[filesize] = 0;
178  a_length = filesize;
179  return true;
180 }

◆ read_cstring()

bool tools::file::read_cstring ( FILE *  a_file,
char *  a_buff,
unsigned int  a_lbuf,
size_t &  a_length 
)
inline

Definition at line 67 of file file.

67  {
68  if(::fgets(a_buff,a_lbuf,a_file)==NULL) {
69  a_length = 0;
70  return false; //EOF
71  }
72 
73  size_t l = ::strlen(a_buff);
74  // On Windows, editors when saving binary files,
75  // put \r\n at place of \n ; we then look for \r\n.
76  if( (l>=2) && (a_buff[l-2]=='\r') && (a_buff[l-1]=='\n') ) {
77  a_buff[l-2] = '\0';
78  l -= 2;
79  } else if( (l>=1) && (a_buff[l-1]=='\n') ) {
80  a_buff[l-1] = '\0';
81  l -= 1;
82  }
83 
84  a_length = l;
85  return true;
86 }

◆ read_num()

bool tools::file::read_num ( const std::string &  a_file,
std::vector< std::string >::size_type  a_num,
std::vector< std::string > &  a_text,
const std::string &  a_cmt = "" 
)
inline

Definition at line 111 of file file.

111  {
112  a_text.clear();
113  FILE* file = ::fopen(a_file.c_str(),"rb");
114  if(!file) return false;
115  unsigned int BUFSIZE = 65536;
116  char* buffer = new char[BUFSIZE+1];
117  if(!buffer) {::fclose(file);return false;}
118  while(true) {
119  size_t l;
120  if(!read_cstring(file,buffer,BUFSIZE,l)) break; // EOF.
121  if(a_cmt.size()&&(!strncmp(a_cmt.c_str(),buffer,a_cmt.size()))) continue;
122  if(a_text.size()<a_num) {
123  a_text.push_back(buffer);
124  } else {
125  break;
126  }
127  }
128  delete [] buffer;
129  ::fclose(file);
130  return true;
131 }

◆ signature()

bool tools::file::signature ( const std::string &  a_file,
unsigned char  a_head[],
unsigned int &  a_num 
)
inline

Definition at line 13 of file signature.

13  { //it is assumed a_head[] can contain a_num chars.
14  FILE* file = ::fopen(a_file.c_str(),"rb");
15  if(!file) {a_num=0;return false;}
16  a_num = (unsigned int)::fread(a_head,1,a_num,file);
17  ::fclose(file);
18  return true;
19 }

◆ size()

bool tools::file::size ( const std::string &  a_file,
long &  a_size 
)
inline

Definition at line 13 of file fsize.

13  {
14  FILE* file = ::fopen(a_file.c_str(),"rb");
15  if(!file) {
16  a_size = 0L;
17  return false;
18  }
19  //::rewind(file);
20  ::fseek(file,0L,SEEK_END);
21  a_size = ::ftell(file);
22  ::fclose(file);
23  return true;
24 }

◆ std_remove() [1/2]

bool tools::file::std_remove ( const std::string &  a_file)
inline

Definition at line 519 of file file.

519  {
520  if(a_file.empty()) return true;
521  return (::remove(a_file.c_str()) ==0 ? true : false);
522 }

◆ std_remove() [2/2]

bool tools::file::std_remove ( std::vector< std::string > &  a_files)
inline

Definition at line 524 of file file.

524  {
525  bool status = true;
526  tools_vforit(std::string,a_files,it) {
527  if(!std_remove(*it)) status = false;
528  }
529  a_files.clear();
530  return status;
531 }

◆ std_rename()

bool tools::file::std_rename ( const std::string &  a_from,
const std::string &  a_to 
)
inline

Definition at line 533 of file file.

533  {
534  //NOTE : a_from must not be a path !
535  // Darwin is ok with a path but not Linux !
536  // For example :
537  // ::rename("/tmp/tmp01","x");
538  // return -1 on Linux.
539  // To do the upper then someone must use move.
540  // But there is no move in the standard lib C !
541  return (::rename(a_from.c_str(),a_to.c_str()) == 0 ? true : false);
542 }

◆ TOOLS_GLOBAL_STRING()

tools::file::TOOLS_GLOBAL_STRING ( format_dst  )

Definition at line 26 of file file_format.

49  {\
50  static const std::string s_v("."+std::string(#a_name));\
51  return s_v;\
52 }
53 
54 TOOLS_GLOBAL_EXT(hdf5)
55 TOOLS_GLOBAL_EXT(fits)
62 TOOLS_GLOBAL_EXT(jpeg)
65 TOOLS_GLOBAL_EXT(root)
68 TOOLS_GLOBAL_EXT(hiptxt)
70 TOOLS_GLOBAL_EXT(scenarios)
71 TOOLS_GLOBAL_EXT(slides)
72 TOOLS_GLOBAL_EXT(zvid)
73 TOOLS_GLOBAL_EXT(exsg)
74 TOOLS_GLOBAL_EXT(gdml)
76 TOOLS_GLOBAL_EXT(cmnd)
77 TOOLS_GLOBAL_EXT(aida)
79 TOOLS_GLOBAL_EXT(jive)
80 TOOLS_GLOBAL_EXT(heprep)
81 TOOLS_GLOBAL_EXT(zheprep)
84 TOOLS_GLOBAL_EXT(kumac)
85 TOOLS_GLOBAL_EXT(insh)
87 TOOLS_GLOBAL_EXT(simbad)
88 
89 #undef TOOLS_GLOBAL_EXT
90 
91 inline void formats(std::vector<std::string>& a_v) {
92  a_v.clear();
93  a_v.push_back(s_format_guessed());
94  a_v.push_back(s_format_hdf5());
95  a_v.push_back(s_format_fits());
96  a_v.push_back(s_format_fog());
97  a_v.push_back(s_format_dot());
98  a_v.push_back(s_format_dcm());
99  a_v.push_back(s_format_iv());
100  a_v.push_back(s_format_wrl());
101  a_v.push_back(s_format_jpeg());
102  a_v.push_back(s_format_png());
103  a_v.push_back(s_format_root());
104  a_v.push_back(s_format_dst());
105  a_v.push_back(s_format_csv());
106  a_v.push_back(s_format_hippo());
107  a_v.push_back(s_format_scenarios());
108  a_v.push_back(s_format_slides());
109  a_v.push_back(s_format_zvid());
110  a_v.push_back(s_format_exsg());
111  a_v.push_back(s_format_bsg());
112  a_v.push_back(s_format_gdml());
113  a_v.push_back(s_format_mac());
114  a_v.push_back(s_format_cmnd());
115  a_v.push_back(s_format_aida());
116  a_v.push_back(s_format_jive());
117  a_v.push_back(s_format_heprep());
118  a_v.push_back(s_format_zheprep());
119  a_v.push_back(s_format_lua());
120  a_v.push_back(s_format_py());
121  a_v.push_back(s_format_kumac());
122  a_v.push_back(s_format_insh());
123  a_v.push_back(s_format_shp());
124  a_v.push_back(s_format_simbad());
125 }

◆ write() [1/2]

bool tools::file::write ( const std::string &  a_file,
const std::string &  a_string 
)
inline

Definition at line 30 of file file.

30  {
31  // a_string could contain \n separated lines.
32  FILE* file = ::fopen(a_file.c_str(),"wb");
33  if(!file) return false;
34  if(::fprintf(file,"%s",a_string.c_str())<0) {
35  ::fclose(file);
36  return false;
37  }
38  ::fclose(file);
39  return true;
40 }

◆ write() [2/2]

bool tools::file::write ( const std::string &  a_file,
const std::vector< std::string > &  a_text 
)
inline

Definition at line 42 of file file.

42  {
43  FILE* file = ::fopen(a_file.c_str(),"wb");
44  if(!file) return false;
45  tools_vforcit(std::string,a_text,it) {
46  if(::fprintf(file,"%s\n",(*it).c_str())<0) {
47  ::fclose(file);
48  return false;
49  }
50  }
51  ::fclose(file);
52  return true;
53 }

◆ write_bytes()

bool tools::file::write_bytes ( const std::string &  a_file,
const char *  a_buffer,
size_t  a_length 
)
inline

Definition at line 182 of file file.

182  {
183  FILE* file = ::fopen(a_file.c_str(),"wb");
184  if(!file) return false;
185  if(!a_length) {
186  ::fclose(file);
187  return true;
188  }
189  size_t nitem = ::fwrite((char*)a_buffer,a_length,(size_t)1,file);
190  ::fclose(file);
191  return (nitem!=1?false:true);
192 }
TOOLS_GLOBAL_EXT
#define TOOLS_GLOBAL_EXT(a_name)
tools::jpeg::is
bool is(const std::string &a_file)
Definition: jpeg:216
tools::file::is_exsg
bool is_exsg(const std::string &a_file, bool &a_is)
Definition: fileis:164
tools::remove
bool remove(std::vector< T > &a_vals, const T &a_elem)
Definition: vmanip:119
tools::file::read
bool read(const std::string &a_file, std::vector< std::string > &a_text)
Definition: file:103
tools::file::is_png
bool is_png(const std::string &a_file, bool &a_is)
Definition: fileis:52
tools::file::write_bytes
bool write_bytes(const std::string &a_file, const char *a_buffer, size_t a_length)
Definition: file:182
tools::file::is_exsg
bool is_exsg(unsigned int a_sz, const char *a_buffer)
Definition: fileis:154
tools::file::is_ico
bool is_ico(const std::string &a_file, bool &a_is)
Definition: fileis:39
tools::file::is_csv
bool is_csv(const std::string &a_file, bool &a_is)
Definition: file:327
tools::file::is_gzip
bool is_gzip(const std::string &a_file, bool &a_is)
Definition: gzip:12
tools::file::is_fits
bool is_fits(const std::string &a_file, bool &a_is)
Definition: fileis:229
tools::file::is_dot
bool is_dot(const std::string &a_file, bool &a_is)
Definition: fileis:120
tools::file::read_bytes
bool read_bytes(const std::string &a_file, char *&a_buffer, long &a_length)
Definition: file:133
tools::file::is_hippo
bool is_hippo(const std::string &a_file, bool &a_is)
Definition: file:246
tools::tolowercase
void tolowercase(std::string &a_string)
Definition: touplow:11
tools::suffix
void suffix(const std::string &a_string, std::string &a_value, bool a_back=true)
Definition: path:11
tools::mx
T mx(const T &a, const T &b)
Definition: mnmx:13
tools::file::is_zip
bool is_zip(const std::string &a_file, bool &a_is)
Definition: fileis:13
tools::file::is_root
bool is_root(const std::string &a_file, bool &a_is)
Definition: fileis:65
tools::file::is_jpeg
bool is_jpeg(const std::string &a_file, bool &a_is)
Definition: fileis:26
tools::file::is_gdml
bool is_gdml(const std::string &a_file, bool &a_is)
Definition: fileis:143
tools::path_name_suffix
bool path_name_suffix(const std::string &a_string, std::string &a_path, std::string &a_name, std::string &a_suffix)
Definition: path:115
tools::file::std_remove
bool std_remove(std::vector< std::string > &a_files)
Definition: file:524
tools::file::size
bool size(const std::string &a_file, long &a_size)
Definition: fsize:13
tools::file::is_slides
bool is_slides(const std::string &a_file, bool &a_is)
Definition: fileis:213
tools::file::is_aida
bool is_aida(const std::string &a_file, bool &a_is)
Definition: fileis:296
tools::file::num_csv_doubles
bool num_csv_doubles(const std::string &a_string, char &a_sep, unsigned int &a_number)
Definition: file:194
tools::file::is_fog
bool is_fog(const std::string &a_file, bool &a_is)
Definition: fileis:110
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::file::read_cstring
bool read_cstring(FILE *a_file, char *a_buff, unsigned int a_lbuf, size_t &a_length)
Definition: file:67
tools::file::signature
bool signature(const std::string &a_file, unsigned char a_head[], unsigned int &a_num)
Definition: signature:13
tools::file::read_num
bool read_num(const std::string &a_file, std::vector< std::string >::size_type a_num, std::vector< std::string > &a_text, const std::string &a_cmt="")
Definition: file:111
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
tools::waxml::end
void end(std::ostream &a_writer)
Definition: begend:31
tools::sep
const std::string & sep()
Definition: sep:11
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::file::is_bsg
bool is_bsg(const std::string &a_file, bool &a_is)
Definition: fileis:185
tools::file::is_scenarios
bool is_scenarios(const std::string &a_file, bool &a_is)
Definition: fileis:194
tools::file::is_ps
bool is_ps(const std::string &a_file, bool &a_is)
Definition: fileis:257
tools::file::is_iv
bool is_iv(const std::string &a_file, bool &a_is)
Definition: fileis:78