1*976fe0bfSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*976fe0bfSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*976fe0bfSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*976fe0bfSAndrew Rist * distributed with this work for additional information 6*976fe0bfSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*976fe0bfSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*976fe0bfSAndrew Rist * "License"); you may not use this file except in compliance 9*976fe0bfSAndrew Rist * with the License. You may obtain a copy of the License at 10*976fe0bfSAndrew Rist * 11*976fe0bfSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*976fe0bfSAndrew Rist * 13*976fe0bfSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*976fe0bfSAndrew Rist * software distributed under the License is distributed on an 15*976fe0bfSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*976fe0bfSAndrew Rist * KIND, either express or implied. See the License for the 17*976fe0bfSAndrew Rist * specific language governing permissions and limitations 18*976fe0bfSAndrew Rist * under the License. 19*976fe0bfSAndrew Rist * 20*976fe0bfSAndrew Rist *************************************************************/ 21*976fe0bfSAndrew Rist 22*976fe0bfSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _CODEMAKER_GLOBAL_HXX_ 25cdf0e10cSrcweir #define _CODEMAKER_GLOBAL_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <list> 28cdf0e10cSrcweir #include <vector> 29cdf0e10cSrcweir #include <set> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <stdio.h> 32cdf0e10cSrcweir #include <rtl/ustring.hxx> 33cdf0e10cSrcweir #include <rtl/strbuf.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir struct EqualString 36cdf0e10cSrcweir { operator ()EqualString37cdf0e10cSrcweir sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 38cdf0e10cSrcweir { 39cdf0e10cSrcweir return (str1 == str2); 40cdf0e10cSrcweir } 41cdf0e10cSrcweir }; 42cdf0e10cSrcweir 43cdf0e10cSrcweir struct HashString 44cdf0e10cSrcweir { operator ()HashString45cdf0e10cSrcweir size_t operator()(const ::rtl::OString& str) const 46cdf0e10cSrcweir { 47cdf0e10cSrcweir return str.hashCode(); 48cdf0e10cSrcweir } 49cdf0e10cSrcweir }; 50cdf0e10cSrcweir 51cdf0e10cSrcweir struct LessString 52cdf0e10cSrcweir { operator ()LessString53cdf0e10cSrcweir sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const 54cdf0e10cSrcweir { 55cdf0e10cSrcweir return (str1 < str2); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir }; 58cdf0e10cSrcweir 59cdf0e10cSrcweir #if defined(_MSC_VER) && _MSC_VER < 1200 60cdf0e10cSrcweir typedef ::std::new_alloc NewAlloc; 61cdf0e10cSrcweir #endif 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir typedef ::std::list< ::rtl::OString > StringList; 65cdf0e10cSrcweir typedef ::std::vector< ::rtl::OString > StringVector; 66cdf0e10cSrcweir typedef ::std::set< ::rtl::OString, LessString > StringSet; 67cdf0e10cSrcweir 68cdf0e10cSrcweir ::rtl::OString makeTempName(); 69cdf0e10cSrcweir 70cdf0e10cSrcweir const ::rtl::OString inGlobalSet(const ::rtl::OUString & r); 71cdf0e10cSrcweir 72cdf0e10cSrcweir ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName); 73cdf0e10cSrcweir 74cdf0e10cSrcweir //************************************************************************* 75cdf0e10cSrcweir // FileStream 76cdf0e10cSrcweir //************************************************************************* 77cdf0e10cSrcweir enum FileAccessMode 78cdf0e10cSrcweir { 79cdf0e10cSrcweir FAM_READ, // "r" 80cdf0e10cSrcweir FAM_WRITE, // "w" 81cdf0e10cSrcweir FAM_APPEND, // "a" 82cdf0e10cSrcweir FAM_READWRITE_EXIST, // "r+" 83cdf0e10cSrcweir FAM_READWRITE, // "w+" 84cdf0e10cSrcweir FAM_READAPPEND // "a+" 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir class FileStream //: public ofstream 88cdf0e10cSrcweir { 89cdf0e10cSrcweir public: 90cdf0e10cSrcweir FileStream(); 91cdf0e10cSrcweir virtual ~FileStream(); 92cdf0e10cSrcweir 93cdf0e10cSrcweir sal_Bool isValid(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE); 96cdf0e10cSrcweir void close(); 97cdf0e10cSrcweir getName()98cdf0e10cSrcweir ::rtl::OString getName() { return m_name; } 99cdf0e10cSrcweir 100cdf0e10cSrcweir // friend functions operator <<(FileStream & o,sal_uInt32 i)101cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, sal_uInt32 i) 102cdf0e10cSrcweir { fprintf(o.m_pFile, "%lu", sal::static_int_cast< unsigned long >(i)); 103cdf0e10cSrcweir return o; 104cdf0e10cSrcweir } operator <<(FileStream & o,char const * s)105cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, char const * s) 106cdf0e10cSrcweir { fprintf(o.m_pFile, "%s", s); 107cdf0e10cSrcweir return o; 108cdf0e10cSrcweir } operator <<(FileStream & o,::rtl::OString * s)109cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, ::rtl::OString* s) 110cdf0e10cSrcweir { fprintf(o.m_pFile, "%s", s->getStr()); 111cdf0e10cSrcweir return o; 112cdf0e10cSrcweir } operator <<(FileStream & o,const::rtl::OString & s)113cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s) 114cdf0e10cSrcweir { fprintf(o.m_pFile, "%s", s.getStr()); 115cdf0e10cSrcweir return o; 116cdf0e10cSrcweir } operator <<(FileStream & o,::rtl::OStringBuffer * s)117cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s) 118cdf0e10cSrcweir { fprintf(o.m_pFile, "%s", s->getStr()); 119cdf0e10cSrcweir return o; 120cdf0e10cSrcweir } operator <<(FileStream & o,const::rtl::OStringBuffer & s)121cdf0e10cSrcweir friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s) 122cdf0e10cSrcweir { fprintf(o.m_pFile, "%s", s.getStr()); 123cdf0e10cSrcweir return o; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir protected: 127cdf0e10cSrcweir const sal_Char* checkAccessMode(FileAccessMode mode); 128cdf0e10cSrcweir 129cdf0e10cSrcweir FILE* m_pFile; 130cdf0e10cSrcweir ::rtl::OString m_name; 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir 133cdf0e10cSrcweir #endif // _CODEMAKER_GLOBAL_HXX_ 134cdf0e10cSrcweir 135