Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _CODEMAKER_GLOBAL_HXX_
21 : : #define _CODEMAKER_GLOBAL_HXX_
22 : :
23 : : #include <list>
24 : : #include <vector>
25 : : #include <set>
26 : :
27 : : #include <stdio.h>
28 : : #include <rtl/ustring.hxx>
29 : : #include <rtl/strbuf.hxx>
30 : :
31 : : struct EqualString
32 : : {
33 : 10822 : sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const
34 : : {
35 : 10822 : return (str1 == str2);
36 : : }
37 : : };
38 : :
39 : : struct HashString
40 : : {
41 : 12134 : size_t operator()(const ::rtl::OString& str) const
42 : : {
43 : 12134 : return str.hashCode();
44 : : }
45 : : };
46 : :
47 : : struct LessString
48 : : {
49 : 7454 : sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const
50 : : {
51 : 7454 : return (str1 < str2);
52 : : }
53 : : };
54 : :
55 : : #if defined(_MSC_VER) && _MSC_VER < 1200
56 : : typedef ::std::new_alloc NewAlloc;
57 : : #endif
58 : :
59 : :
60 : : typedef ::std::list< ::rtl::OString > StringList;
61 : : typedef ::std::vector< ::rtl::OString > StringVector;
62 : : typedef ::std::set< ::rtl::OString, LessString > StringSet;
63 : :
64 : : ::rtl::OString makeTempName();
65 : :
66 : : const ::rtl::OString inGlobalSet(const ::rtl::OUString & r);
67 : :
68 : : ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName);
69 : :
70 : : //*************************************************************************
71 : : // FileStream
72 : : //*************************************************************************
73 : : enum FileAccessMode
74 : : {
75 : : FAM_READ, // "r"
76 : : FAM_WRITE, // "w"
77 : : FAM_APPEND, // "a"
78 : : FAM_READWRITE_EXIST, // "r+"
79 : : FAM_READWRITE, // "w+"
80 : : FAM_READAPPEND // "a+"
81 : : };
82 : :
83 : : class FileStream //: public ofstream
84 : : {
85 : : public:
86 : : FileStream();
87 : : virtual ~FileStream();
88 : :
89 : : sal_Bool isValid();
90 : :
91 : : void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE);
92 : : void close();
93 : :
94 : 0 : ::rtl::OString getName() { return m_name; }
95 : :
96 : : // friend functions
97 : : friend FileStream &operator<<(FileStream& o, sal_uInt32 i)
98 : : { fprintf(o.m_pFile, "%lu", sal::static_int_cast< unsigned long >(i));
99 : : return o;
100 : : }
101 : 0 : friend FileStream &operator<<(FileStream& o, char const * s)
102 : 0 : { fprintf(o.m_pFile, "%s", s);
103 : 0 : return o;
104 : : }
105 : : friend FileStream &operator<<(FileStream& o, ::rtl::OString* s)
106 : : { fprintf(o.m_pFile, "%s", s->getStr());
107 : : return o;
108 : : }
109 : : friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s)
110 : : { fprintf(o.m_pFile, "%s", s.getStr());
111 : : return o;
112 : : }
113 : : friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s)
114 : : { fprintf(o.m_pFile, "%s", s->getStr());
115 : : return o;
116 : : }
117 : : friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s)
118 : : { fprintf(o.m_pFile, "%s", s.getStr());
119 : : return o;
120 : : }
121 : :
122 : : protected:
123 : : const sal_Char* checkAccessMode(FileAccessMode mode);
124 : :
125 : : FILE* m_pFile;
126 : : ::rtl::OString m_name;
127 : : };
128 : :
129 : : #endif // _CODEMAKER_GLOBAL_HXX_
130 : :
131 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|