1 #ifndef _ANTLR3_FILESTREAM_HPP 2 #define _ANTLR3_FILESTREAM_HPP 3 4 // [The "BSD licence"] 5 // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 7 // 8 // All rights reserved. 9 // 10 // Redistribution and use in source and binary forms, with or without 11 // modification, are permitted provided that the following conditions 12 // are met: 13 // 1. Redistributions of source code must retain the above copyright 14 // notice, this list of conditions and the following disclaimer. 15 // 2. Redistributions in binary form must reproduce the above copyright 16 // notice, this list of conditions and the following disclaimer in the 17 // documentation and/or other materials provided with the distribution. 18 // 3. The name of the author may not be used to endorse or promote products 19 // derived from this software without specific prior written permission. 20 // 21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32 #include <exception> 33 #include <string> 34 35 #include "antlr3defs.hpp" 36 37 ANTLR_BEGIN_NAMESPACE() 38 39 template<class ImplTraits> 40 class FileUtils 41 { 42 public: 43 /** \brief Open an operating system file and return the descriptor 44 * We just use the common open() and related functions here. 45 * Later we might find better ways on systems 46 * such as Windows and OpenVMS for instance. But the idea is to read the 47 * while file at once anyway, so it may be irrelevant. 48 */ 49 static ANTLR_FDSC AntlrFopen(const ANTLR_UINT8* filename, const char * mode); 50 51 /** \brief Close an operating system file and free any handles 52 * etc. 53 */ 54 static void AntlrFclose (ANTLR_FDSC fd); 55 56 static ANTLR_UINT32 AntlrFsize(const ANTLR_UINT8* filename); 57 template<typename InputStreamType> 58 static ANTLR_UINT32 AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName); 59 static ANTLR_UINT32 AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data); 60 61 }; 62 63 class ParseFileAbsentException : public std::exception 64 { what() const65 virtual const char* what() const throw() 66 { 67 return " Parse File not Present"; 68 } 69 }; 70 71 ANTLR_END_NAMESPACE() 72 73 #include "antlr3filestream.inl" 74 75 #endif 76