1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_CODEMAKER_GLOBAL_HXX 29 #define INCLUDED_CODEMAKER_GLOBAL_HXX 30 31 #include <list> 32 #include <vector> 33 #include <set> 34 35 #include <stdio.h> 36 37 #include "osl/file.hxx" 38 #include "rtl/ustring.hxx" 39 #include "rtl/strbuf.hxx" 40 41 struct EqualString 42 { 43 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 44 { 45 return (str1 == str2); 46 } 47 }; 48 49 struct HashString 50 { 51 size_t operator()(const ::rtl::OString& str) const 52 { 53 return str.hashCode(); 54 } 55 }; 56 57 struct LessString 58 { 59 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 60 { 61 return (str1 < str2); 62 } 63 }; 64 65 #if defined(_MSC_VER) && _MSC_VER < 1200 66 typedef ::std::new_alloc NewAlloc; 67 #endif 68 69 70 typedef ::std::list< ::rtl::OString > StringList; 71 typedef ::std::vector< ::rtl::OString > StringVector; 72 typedef ::std::set< ::rtl::OString, LessString > StringSet; 73 74 //************************************************************************* 75 // FileStream 76 //************************************************************************* 77 enum FileAccessMode 78 { 79 FAM_READ, // "r" 80 FAM_WRITE, // "w" 81 FAM_READWRITE_EXIST, // "r+" 82 FAM_READWRITE // "w+" 83 }; 84 85 class FileStream 86 { 87 public: 88 FileStream(); 89 FileStream(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 90 virtual ~FileStream(); 91 92 sal_Bool isValid(); 93 94 void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 95 void createTempFile(const ::rtl::OString& sPath); 96 void close(); 97 98 ::rtl::OString getName() { return m_name; } 99 100 bool write(void const * buffer, sal_uInt64 size); 101 102 // friend functions 103 friend FileStream &operator<<(FileStream& o, sal_uInt32 i); 104 friend FileStream &operator<<(FileStream& o, char const * s); 105 friend FileStream &operator<<(FileStream& o, ::rtl::OString* s); 106 friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s); 107 friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s); 108 friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s); 109 110 private: 111 sal_uInt32 checkAccessMode(FileAccessMode mode); 112 113 oslFileHandle m_file; 114 ::rtl::OString m_name; 115 }; 116 117 118 //************************************************************************* 119 // Helper functions 120 //************************************************************************* 121 ::rtl::OString getTempDir(const ::rtl::OString& sFileName); 122 123 ::rtl::OString createFileNameFromType(const ::rtl::OString& destination, 124 const ::rtl::OString type, 125 const ::rtl::OString postfix, 126 sal_Bool bLowerCase=sal_False, 127 const ::rtl::OString prefix=""); 128 129 sal_Bool fileExists(const ::rtl::OString& fileName); 130 sal_Bool makeValidTypeFile(const ::rtl::OString& targetFileName, 131 const ::rtl::OString& tmpFileName, 132 sal_Bool bFileCheck); 133 sal_Bool removeTypeFile(const ::rtl::OString& fileName); 134 135 ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName); 136 137 //************************************************************************* 138 // Global exception to signal problems when a type cannot be dumped 139 //************************************************************************* 140 class CannotDumpException 141 { 142 public: 143 CannotDumpException(const ::rtl::OString& msg) 144 : m_message(msg) {} 145 146 ::rtl::OString m_message; 147 }; 148 149 150 #endif // INCLUDED_CODEMAKER_GLOBAL_HXX 151 152