Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
File.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLUtils/src/ICLUtils/File.h                           **
00010 ** Module : ICLUtils                                               **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/ShallowCopyable.h>
00035 #include <ICLUtils/BasicTypes.h>
00036 #include <string>
00037 #include <vector>
00038 
00039 
00040 namespace icl{
00041   namespace utils{
00042     
00044     class FileImpl;
00045     struct ICLUtils_API FileImplDelOp { static void delete_func(FileImpl *i); };
00048 
00049 
00061     class ICLUtils_API File : public utils::ShallowCopyable<FileImpl, FileImplDelOp>{
00062       public:
00063       
00065       enum OpenMode{
00066         readBinary = 0,  
00067         readText = 1,    
00068         writeBinary = 2, 
00069         writeText = 3,   
00070         notOpen = 4      
00071       };
00072 
00074       static std::string read_file(const std::string &filename, bool textMode=true);
00075 
00077       static std::vector<std::string> read_lines(const std::string &filename);
00078 
00080       static void write_file(const std::string &filename, const std::string &text, 
00081                              bool textMode=true);
00082 
00084       static void write_lines(const std::string &filename, const std::vector<std::string> &lines);
00085 
00086 
00088       File();
00089       
00091       File(const std::string &name);
00092       
00094       File(const std::string &name, OpenMode om);
00095   
00097       ~File();
00098       
00100       bool exists() const;
00101   
00103       bool isDirectory() const;
00104       
00106       bool isOpen() const;
00107       
00109       bool isBinary() const;
00110       
00112       std::string getDir() const;
00113       
00115       std::string getBaseName() const;
00116   
00118       std::string getSuffix() const;
00119   
00121       std::string getName() const;
00122       
00124       void write(const void *data, int len);
00125       
00127 
00128       void writeLine(const void *data, int len);
00129       
00131       void write(const std::string &text);
00132       
00134       void setPrecision(const std::string &p="%8f");
00135   
00137       File &operator<<(char c);
00138   
00140       File &operator<<(unsigned char uc); 
00141   
00143       File &operator<<(int i);
00144   
00146       File &operator<<(unsigned int ui);
00147       
00149       File &operator<<(float f);
00150   
00152       File &operator<<(double d);
00153   
00155       File &operator<<(const std::string &s);
00156       
00158 
00160       std::string readLine() const;
00161       
00163 
00166       std::string &readLine(std::string &dst) const;
00167   
00169       const std::vector<icl8u> &readAll() const;
00170   
00172       const icl8u* getCurrentDataPointer() const;
00173       
00175       const icl8u* getFileDataPointer() const;
00176   
00178 
00181       std::vector<icl8u> read(int len) const;
00182       
00184 
00185       int read(int len, void *dst) const;
00186   
00188       bool hasMoreLines() const;
00189   
00191       int bytesAvailable() const;
00192       
00194       int getFileSize() const;
00195       
00197 
00198       void open(OpenMode om);
00199   
00201 
00202       void reopen(OpenMode om);
00203   
00205       void close();
00206       
00208       void erase();
00209       
00211       void reset();
00212   
00214       void *getHandle() const;
00215   
00217       bool canRead() const;
00218       
00220       bool canWrite() const;
00221       
00223       OpenMode getOpenMode() const;
00224     
00225     };
00226   } // namespace utils
00227 }
00228 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines