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 _CODEMAKER_GLOBAL_HXX_ 25 #define _CODEMAKER_GLOBAL_HXX_ 26 27 #include <list> 28 #include <vector> 29 #include <set> 30 31 #include <stdio.h> 32 #include <rtl/ustring.hxx> 33 #include <rtl/strbuf.hxx> 34 35 struct EqualString 36 { operator ()EqualString37 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 38 { 39 return (str1 == str2); 40 } 41 }; 42 43 struct HashString 44 { operator ()HashString45 size_t operator()(const ::rtl::OString& str) const 46 { 47 return str.hashCode(); 48 } 49 }; 50 51 struct LessString 52 { operator ()LessString53 sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 54 { 55 return (str1 < str2); 56 } 57 }; 58 59 #if defined(_MSC_VER) && _MSC_VER < 1200 60 typedef ::std::new_alloc NewAlloc; 61 #endif 62 63 64 typedef ::std::list< ::rtl::OString > StringList; 65 typedef ::std::vector< ::rtl::OString > StringVector; 66 typedef ::std::set< ::rtl::OString, LessString > StringSet; 67 68 ::rtl::OString makeTempName(); 69 70 const ::rtl::OString inGlobalSet(const ::rtl::OUString & r); 71 72 ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName); 73 74 //************************************************************************* 75 // FileStream 76 //************************************************************************* 77 enum FileAccessMode 78 { 79 FAM_READ, // "r" 80 FAM_WRITE, // "w" 81 FAM_APPEND, // "a" 82 FAM_READWRITE_EXIST, // "r+" 83 FAM_READWRITE, // "w+" 84 FAM_READAPPEND // "a+" 85 }; 86 87 class FileStream //: public ofstream 88 { 89 public: 90 FileStream(); 91 virtual ~FileStream(); 92 93 sal_Bool isValid(); 94 95 void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 96 void close(); 97 getName()98 ::rtl::OString getName() { return m_name; } 99 100 // friend functions operator <<(FileStream & o,sal_uInt32 i)101 friend FileStream &operator<<(FileStream& o, sal_uInt32 i) 102 { fprintf(o.m_pFile, "%lu", sal::static_int_cast< unsigned long >(i)); 103 return o; 104 } operator <<(FileStream & o,char const * s)105 friend FileStream &operator<<(FileStream& o, char const * s) 106 { fprintf(o.m_pFile, "%s", s); 107 return o; 108 } operator <<(FileStream & o,::rtl::OString * s)109 friend FileStream &operator<<(FileStream& o, ::rtl::OString* s) 110 { fprintf(o.m_pFile, "%s", s->getStr()); 111 return o; 112 } operator <<(FileStream & o,const::rtl::OString & s)113 friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s) 114 { fprintf(o.m_pFile, "%s", s.getStr()); 115 return o; 116 } operator <<(FileStream & o,::rtl::OStringBuffer * s)117 friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s) 118 { fprintf(o.m_pFile, "%s", s->getStr()); 119 return o; 120 } operator <<(FileStream & o,const::rtl::OStringBuffer & s)121 friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s) 122 { fprintf(o.m_pFile, "%s", s.getStr()); 123 return o; 124 } 125 126 protected: 127 const sal_Char* checkAccessMode(FileAccessMode mode); 128 129 FILE* m_pFile; 130 ::rtl::OString m_name; 131 }; 132 133 #endif // _CODEMAKER_GLOBAL_HXX_ 134 135