PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
openFileStream.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include <iostream>
9 #include "convertToString.h"
10 #include "openFileStream.h"
11 
12 
14 
18 bool openFileStream(std::ofstream & fs, const PPath & fileName){
19  fs.open(fileName.c_str());
20  if(!fs.is_open()){
21  std::cerr << "openFileStream : can't open file '" << fileName << "'" << std::endl;
22  return false;
23  }else return true;
24 }
25 
27 
31 bool openFileStream(std::ifstream & fs, const PPath & fileName){
32  fs.open(fileName.c_str());
33  if(!fs.is_open()){
34  std::cerr << "openFileStream : can't open file '" << fileName << "'" << std::endl;
35  return false;
36  }else return true;
37 }
38 
40 
45 bool openFileStream(PVecOFStream & fs, const PPath & fileName, size_t nbFile){
46  if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
47  PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
48  if(extention != ""){extention = PString("." + extention);}
49  fs.resize(nbFile);
50  bool b(true);
51  size_t i(0lu);
52  for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
53  PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
54  b &= openFileStream(*it, tmpFileName);
55  ++i;
56  }
57  return b;
58 }
59 
61 
66 bool openFileStream(PVecIFStream & fs, const PPath & fileName, size_t nbFile){
67  if(nbFile == 0lu){return true;} //There is no problem in oppening 0 file
68  PPath baseFileName(fileName.eraseExtension()), extention(fileName.getExtension());
69  if(extention != ""){extention = PPath("." + extention);}
70  fs.resize(nbFile);
71  bool b(true);
72  size_t i(0lu);
73  for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
74  PPath tmpFileName(baseFileName + PPath("_") + valueToString(i) + extention);
75  b &= openFileStream(*it, tmpFileName);
76  ++i;
77  }
78  return b;
79 }
80 
82 
85  for(PVecOFStream::iterator it(fs.begin()); it != fs.end(); ++it){
86  it->close();
87  }
88 }
89 
91 
94  for(PVecIFStream::iterator it(fs.begin()); it != fs.end(); ++it){
95  it->close();
96  }
97 }
98 
Path of a directory or a file.
Definition: PPath.h:17
PPath & eraseExtension()
Erase the extension of the PPath.
Definition: PPath.cpp:292
PString getExtension() const
Get file extension.
Definition: PPath.cpp:252
Extends the std::string.
Definition: PString.h:16
std::string valueToString(const T &val)
Convert a type into a string.
bool openFileStream(std::ofstream &fs, const PPath &fileName)
Open a ofstream and says if there is a problem.
void closeFileStream(PVecOFStream &fs)
Close a vector of ofstream.
std::vector< std::ifstream > PVecIFStream
std::vector< std::ofstream > PVecOFStream