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