1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_CODEMAKER_GLOBAL_HXX 25 #define INCLUDED_CODEMAKER_GLOBAL_HXX 26 27 #include <list> 28 #include <vector> 29 #include <set> 30 31 #include <stdio.h> 32 33 #include "osl/file.hxx" 34 #include "rtl/ustring.hxx" 35 #include "rtl/strbuf.hxx" 36 37 struct EqualString 38 { operator ()EqualString39 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 40 { 41 return (str1 == str2); 42 } 43 }; 44 45 struct HashString 46 { operator ()HashString47 size_t operator()(const ::rtl::OString& str) const 48 { 49 return str.hashCode(); 50 } 51 }; 52 53 struct LessString 54 { operator ()LessString55 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 56 { 57 return (str1 < str2); 58 } 59 }; 60 61 #if defined(_MSC_VER) && _MSC_VER < 1200 62 typedef ::std::new_alloc NewAlloc; 63 #endif 64 65 66 typedef ::std::list< ::rtl::OString > StringList; 67 typedef ::std::vector< ::rtl::OString > StringVector; 68 typedef ::std::set< ::rtl::OString, LessString > StringSet; 69 70 //************************************************************************* 71 // FileStream 72 //************************************************************************* 73 enum FileAccessMode 74 { 75 FAM_READ, // "r" 76 FAM_WRITE, // "w" 77 FAM_READWRITE_EXIST, // "r+" 78 FAM_READWRITE // "w+" 79 }; 80 81 class FileStream 82 { 83 public: 84 FileStream(); 85 FileStream(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 86 virtual ~FileStream(); 87 88 sal_Bool isValid(); 89 90 void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 91 void createTempFile(const ::rtl::OString& sPath); 92 void close(); 93 getName()94 ::rtl::OString getName() { return m_name; } 95 96 bool write(void const * buffer, sal_uInt64 size); 97 98 // friend functions 99 friend FileStream &operator<<(FileStream& o, sal_uInt32 i); 100 friend FileStream &operator<<(FileStream& o, char const * s); 101 friend FileStream &operator<<(FileStream& o, ::rtl::OString* s); 102 friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s); 103 friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s); 104 friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s); 105 106 private: 107 sal_uInt32 checkAccessMode(FileAccessMode mode); 108 109 oslFileHandle m_file; 110 ::rtl::OString m_name; 111 }; 112 113 114 //************************************************************************* 115 // Helper functions 116 //************************************************************************* 117 ::rtl::OString getTempDir(const ::rtl::OString& sFileName); 118 119 ::rtl::OString createFileNameFromType(const ::rtl::OString& destination, 120 const ::rtl::OString type, 121 const ::rtl::OString postfix, 122 sal_Bool bLowerCase=sal_False, 123 const ::rtl::OString prefix=""); 124 125 sal_Bool fileExists(const ::rtl::OString& fileName); 126 sal_Bool makeValidTypeFile(const ::rtl::OString& targetFileName, 127 const ::rtl::OString& tmpFileName, 128 sal_Bool bFileCheck); 129 sal_Bool removeTypeFile(const ::rtl::OString& fileName); 130 131 ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName); 132 133 //************************************************************************* 134 // Global exception to signal problems when a type cannot be dumped 135 //************************************************************************* 136 class CannotDumpException 137 { 138 public: CannotDumpException(const::rtl::OString & msg)139 CannotDumpException(const ::rtl::OString& msg) 140 : m_message(msg) {} 141 142 ::rtl::OString m_message; 143 }; 144 145 146 #endif // INCLUDED_CODEMAKER_GLOBAL_HXX 147 148