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.GPL  **
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/ShallowCopyable.h>
00034 #include <ICLUtils/BasicTypes.h>
00035 #include <string>
00036 #include <vector>
00037 
00038 
00039 namespace icl{
00040   namespace utils{
00041     
00043     class FileImpl;
00044     struct FileImplDelOp { static void delete_func(FileImpl *i); };
00047 
00048 
00060     class File  : public utils::ShallowCopyable<FileImpl,FileImplDelOp>{
00061       public:
00062       
00064       enum OpenMode{
00065         readBinary = 0,  
00066         readText = 1,    
00067         writeBinary = 2, 
00068         writeText = 3,   
00069         notOpen = 4      
00070       };
00071 
00073       static std::string read_file(const std::string &filename, bool textMode=true);
00074 
00076       static std::vector<std::string> read_lines(const std::string &filename);
00077 
00079       static void write_file(const std::string &filename, const std::string &text, 
00080                              bool textMode=true);
00081 
00083       static void write_lines(const std::string &filename, const std::vector<std::string> &lines);
00084 
00085 
00087       File();
00088       
00090       File(const std::string &name);
00091       
00093       File(const std::string &name, OpenMode om);
00094   
00096       ~File();
00097       
00099       bool exists() const;
00100   
00102       bool isOpen() const;
00103       
00105       bool isBinary() const;
00106       
00108       std::string getDir() const;
00109       
00111       std::string getBaseName() const;
00112   
00114       std::string getSuffix() const;
00115   
00117       std::string getName() const;
00118       
00120       void write(const void *data, int len);
00121       
00123 
00124       void writeLine(const void *data, int len);
00125       
00127       void write(const std::string &text);
00128       
00130       void setPrecision(const std::string &p="%8f");
00131   
00133       File &operator<<(char c);
00134   
00136       File &operator<<(unsigned char uc); 
00137   
00139       File &operator<<(int i);
00140   
00142       File &operator<<(unsigned int ui);
00143       
00145       File &operator<<(float f);
00146   
00148       File &operator<<(double d);
00149   
00151       File &operator<<(const std::string &s);
00152       
00154 
00156       std::string readLine() const;
00157       
00159 
00162       std::string &readLine(std::string &dst) const;
00163   
00165       const std::vector<icl8u> &readAll() const;
00166   
00168       const icl8u* getCurrentDataPointer() const;
00169       
00171       const icl8u* getFileDataPointer() const;
00172   
00174 
00177       std::vector<icl8u> read(int len) const;
00178       
00180 
00181       int read(int len, void *dst) const;
00182   
00184       bool hasMoreLines() const;
00185   
00187       int bytesAvailable() const;
00188       
00190       int getFileSize() const;
00191       
00193 
00194       void open(OpenMode om);
00195   
00197 
00198       void reopen(OpenMode om);
00199   
00201       void close();
00202       
00204       void erase();
00205       
00207       void reset();
00208   
00210       void *getHandle() const;
00211   
00213       bool canRead() const;
00214       
00216       bool canWrite() const;
00217       
00219       OpenMode getOpenMode() const;
00220     
00221     };
00222   } // namespace utils
00223 }
00224 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines