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 INCLUDED_CODEMAKER_GLOBAL_HXX
21 : : #define INCLUDED_CODEMAKER_GLOBAL_HXX
22 : :
23 : : #include <list>
24 : : #include <vector>
25 : : #include <set>
26 : :
27 : : #include <stdio.h>
28 : :
29 : : #include "osl/file.hxx"
30 : : #include "rtl/ustring.hxx"
31 : : #include "rtl/strbuf.hxx"
32 : :
33 : : struct EqualString
34 : : {
35 : 0 : sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const
36 : : {
37 : 0 : return (str1 == str2);
38 : : }
39 : : };
40 : :
41 : : struct HashString
42 : : {
43 : 0 : size_t operator()(const ::rtl::OString& str) const
44 : : {
45 : 0 : return str.hashCode();
46 : : }
47 : : };
48 : :
49 : : struct LessString
50 : : {
51 : : sal_Bool operator()(const ::rtl::OString& str1, const ::rtl::OString& str2) const
52 : : {
53 : : return (str1 < str2);
54 : : }
55 : : };
56 : :
57 : : #if defined(_MSC_VER) && _MSC_VER < 1200
58 : : typedef ::std::new_alloc NewAlloc;
59 : : #endif
60 : :
61 : :
62 : : typedef ::std::list< ::rtl::OString > StringList;
63 : : typedef ::std::vector< ::rtl::OString > StringVector;
64 : : typedef ::std::set< ::rtl::OString, LessString > StringSet;
65 : :
66 : : //*************************************************************************
67 : : // FileStream
68 : : //*************************************************************************
69 : : enum FileAccessMode
70 : : {
71 : : FAM_READ, // "r"
72 : : FAM_WRITE, // "w"
73 : : FAM_READWRITE_EXIST, // "r+"
74 : : FAM_READWRITE // "w+"
75 : : };
76 : :
77 : : class FileStream
78 : : {
79 : : public:
80 : : FileStream();
81 : : virtual ~FileStream();
82 : :
83 : : sal_Bool isValid();
84 : :
85 : : void open(const ::rtl::OString& name, FileAccessMode nMode = FAM_READWRITE);
86 : : void createTempFile(const ::rtl::OString& sPath);
87 : : void close();
88 : :
89 : 0 : ::rtl::OString getName() { return m_name; }
90 : :
91 : : bool write(void const * buffer, sal_uInt64 size);
92 : :
93 : : // friend functions
94 : : friend FileStream &operator<<(FileStream& o, sal_uInt32 i);
95 : : friend FileStream &operator<<(FileStream& o, char const * s);
96 : : friend FileStream &operator<<(FileStream& o, ::rtl::OString* s);
97 : : friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s);
98 : : friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer* s);
99 : : friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s);
100 : :
101 : : private:
102 : : sal_uInt32 checkAccessMode(FileAccessMode mode);
103 : :
104 : : oslFileHandle m_file;
105 : : ::rtl::OString m_name;
106 : : };
107 : :
108 : :
109 : : //*************************************************************************
110 : : // Helper functions
111 : : //*************************************************************************
112 : : ::rtl::OString getTempDir(const ::rtl::OString& sFileName);
113 : :
114 : : ::rtl::OString createFileNameFromType(const ::rtl::OString& destination,
115 : : const ::rtl::OString type,
116 : : const ::rtl::OString postfix,
117 : : sal_Bool bLowerCase=sal_False,
118 : : const ::rtl::OString prefix="");
119 : :
120 : : sal_Bool fileExists(const ::rtl::OString& fileName);
121 : : sal_Bool makeValidTypeFile(const ::rtl::OString& targetFileName,
122 : : const ::rtl::OString& tmpFileName,
123 : : sal_Bool bFileCheck);
124 : : sal_Bool removeTypeFile(const ::rtl::OString& fileName);
125 : :
126 : : ::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName);
127 : :
128 : : //*************************************************************************
129 : : // Global exception to signal problems when a type cannot be dumped
130 : : //*************************************************************************
131 : 0 : class CannotDumpException
132 : : {
133 : : public:
134 : 0 : CannotDumpException(const ::rtl::OString& msg)
135 : 0 : : m_message(msg) {}
136 : :
137 : : ::rtl::OString m_message;
138 : : };
139 : :
140 : :
141 : : #endif // INCLUDED_CODEMAKER_GLOBAL_HXX
142 : :
143 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|