Image Component Library (ICL)
File.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/File.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
35 #include <ICLUtils/BasicTypes.h>
36 #include <string>
37 #include <vector>
38 
39 
40 namespace icl{
41  namespace utils{
42 
44  class FileImpl;
45  struct ICLUtils_API FileImplDelOp { static void delete_func(FileImpl *i); };
48 
61  class ICLUtils_API File : public utils::ShallowCopyable<FileImpl, FileImplDelOp>{
62  public:
63 
65  enum OpenMode{
66  readBinary = 0,
67  readText = 1,
68  writeBinary = 2,
69  writeText = 3,
70  notOpen = 4
71  };
72 
74  static std::string read_file(const std::string &filename, bool textMode=true);
75 
77  static std::vector<std::string> read_lines(const std::string &filename);
78 
80  static void write_file(const std::string &filename, const std::string &text,
81  bool textMode=true);
82 
84  static void write_lines(const std::string &filename, const std::vector<std::string> &lines);
85 
86 
88  File();
89 
91  File(const std::string &name);
92 
94  File(const std::string &name, OpenMode om);
95 
97  ~File();
98 
100  bool exists() const;
101 
103  bool isDirectory() const;
104 
106  bool isOpen() const;
107 
109  bool isBinary() const;
110 
112  std::string getDir() const;
113 
115  std::string getBaseName() const;
116 
118  std::string getSuffix() const;
119 
121  std::string getName() const;
122 
124  void write(const void *data, int len);
125 
127 
128  void writeLine(const void *data, int len);
129 
131  void write(const std::string &text);
132 
134  void setPrecision(const std::string &p="%8f");
135 
137  File &operator<<(char c);
138 
140  File &operator<<(unsigned char uc);
141 
143  File &operator<<(int i);
144 
146  File &operator<<(unsigned int ui);
147 
149  File &operator<<(float f);
150 
152  File &operator<<(double d);
153 
155  File &operator<<(const std::string &s);
156 
158 
160  std::string readLine() const;
161 
163 
166  std::string &readLine(std::string &dst) const;
167 
169  const std::vector<icl8u> &readAll() const;
170 
172  const icl8u* getCurrentDataPointer() const;
173 
175  const icl8u* getFileDataPointer() const;
176 
178 
181  std::vector<icl8u> read(int len) const;
182 
184 
185  int read(int len, void *dst) const;
186 
188  bool hasMoreLines() const;
189 
191  int bytesAvailable() const;
192 
194  int getFileSize() const;
195 
197 
198  void open(OpenMode om);
199 
201 
202  void reopen(OpenMode om);
203 
205  void close();
206 
208  void erase();
209 
211  void reset();
212 
214  void *getHandle() const;
215 
217  bool canRead() const;
218 
220  bool canWrite() const;
221 
223  OpenMode getOpenMode() const;
224 
225  };
226  } // namespace utils
227 }
228 
undocument this line if you encounter any issues!
Definition: Any.h:37
OpenMode
mode to open files
Definition: File.h:65
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
Interface class for cheap copyable classes using a smart ptr.
Definition: ShallowCopyable.h:131
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
Utility class for file handling (reading files is buffered)
Definition: File.h:61
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.