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