Main Page | Modules | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

FileStream.h

Go to the documentation of this file.
00001 /********************************************************************
00002 
00003 Copyright 2006, ACCESS Systems Americas, Inc. All rights reserved.
00004 
00005 The contents of this file are subject to the Mozilla Public License Version
00006 1.1 (the "License"); you may not use this file except in compliance with
00007 the License. You may obtain a copy of the License at
00008 http://www.mozilla.org/MPL/
00009 
00010 Software distributed under the License is distributed on an "AS IS" basis,
00011 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012 for the specific language governing rights and limitations under the
00013 License.
00014 
00015 The Original Code is the entire contents of this file.
00016 
00017 The Initial Developer of the Original Code is ACCESS Systems Americas, Inc.
00018 
00019 Portions created by ACCESS Systems Americas, Inc. are Copyright © 2006. All
00020 Rights Reserved.
00021 
00022 Contributor(s): none.
00023 
00024 ********************************************************************/
00034 #ifndef ALP_FILESTREAM_H
00035 #define ALP_FILESTREAM_H
00036 
00037 // Includes ------------------------------------------------------------------
00038 #include <stdio.h>
00039 #include <string>
00040 
00041 
00042 namespace alp {
00043 
00044 // Typedefs ------------------------------------------------------------------
00045 class FileStream
00046 {
00047         public:
00048                 enum openmode
00049                 {
00050                         app = 0x01,
00051                         ate = 0x02,
00052                         binary = 0x04,
00053                         in = 0x08,
00054                         out = 0x10,
00055                         trunc = 0x20
00056                 };
00057                 enum iostate
00058                 {
00059                         goodbit = 0x00,
00060                         badbit  = 0x01,
00061                         eofbit  = 0x02,
00062                         failbit = 0x04
00063                 };
00064 
00065                 FileStream();
00066                 FileStream(const char* path, int mode);
00067                 FileStream(const std::string& path, int mode);
00068                 ~FileStream();
00069 
00070                 void            open(const char* path, int mode);
00071                 void            open(const std::string& path, int mode);
00072                 void            close();
00073 
00074                 FileStream& getline(char* s, size_t size);
00075                 FileStream& getline(char* s, size_t size, char delim);
00076                 FileStream& getline(std::string& s);
00077                 FileStream& getline(std::string& s, char delim);
00078 
00079                 FileStream& read(char* s, size_t size);
00080                 FileStream&     write(const char* s, size_t size);
00081 
00082                 bool            eof();
00083                 bool            good();
00084                 int                     openmode();
00085                 int                     rdstate();
00086                 void            clear(int state = goodbit);
00087 
00088         private:
00089                 bool            getlinechar(int& c, char delim);
00090                 void            getlinecheck(int& c, char delim);
00091 
00092                 FILE*           fHandle;
00093                 uint8_t         fOpenMode;
00094                 uint8_t         fState;
00095 };
00096 
00097 
00098 // Prototypes ----------------------------------------------------------------
00099 inline FileStream& getline(FileStream& fs, std::string& s) { return fs.getline(s); }
00100 inline FileStream& getline(FileStream& fs, std::string& s, char delim) { return fs.getline(s, delim); }
00101 
00102 FileStream& operator<<(FileStream& fs, const char* s);
00103 FileStream& operator<<(FileStream& fs, const std::string& s);
00104 FileStream& operator<<(FileStream& fs, int i);
00105 
00106 }       // namespace alp
00107 
00108 
00109 #endif  // ALP_FILESTREAM_H

Generated on Sat Dec 16 20:29:47 2006 for hiker-0.9 by  doxygen 1.4.4