tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting
[LibreOffice.git] / connectivity / source / drivers / hsqldb / accesslog.hxx
blob81db98ae77504591e181df9f219cdb70bac60faf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #ifdef HSQLDB_DBG
24 #include <jni.h>
25 #include <rtl/ustring.hxx>
26 #include <rtl/string.hxx>
28 namespace connectivity::hsqldb
30 class LogFile
32 private:
33 OUString m_sFileName;
35 public:
36 LogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix );
38 public:
39 void writeString( const char* _pString, bool _bEndLine = true );
40 void create() { getLogFile(); }
41 virtual void close();
43 protected:
44 FILE*& getLogFile();
47 class OperationLogFile : public LogFile
49 public:
50 OperationLogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix )
51 :LogFile( env, streamName, ( OString( _pAsciiSuffix ) += ".op" ).getStr() )
55 void logOperation( const char* _pOp )
57 writeString( _pOp, true );
60 void logOperation( const char* _pOp, jlong _nLongArg )
62 OString sLine( _pOp );
63 sLine += "( ";
64 sLine += OString::number( _nLongArg );
65 sLine += " )";
66 writeString( sLine.getStr(), true );
69 void logReturn( jlong _nRetVal )
71 OString sLine( " -> " );
72 sLine += OString::number( _nRetVal );
73 writeString( sLine.getStr(), true );
76 void logReturn( jint _nRetVal )
78 OString sLine( " -> " );
79 sLine += OString::number( _nRetVal );
80 writeString( sLine.getStr(), true );
83 virtual void close()
85 writeString( "-------------------------------", true );
86 writeString( "", true );
87 LogFile::close();
91 class DataLogFile : public LogFile
93 public:
94 DataLogFile( JNIEnv* env, jstring streamName, const char* _pAsciiSuffix )
95 :LogFile( env, streamName, _pAsciiSuffix )
99 void write( jint value )
101 fputc( value, getLogFile() );
102 fflush( getLogFile() );
105 void write( const sal_Int8* buffer, sal_Int32 bytesRead )
107 fwrite( buffer, sizeof(sal_Int8), bytesRead, getLogFile() );
108 fflush( getLogFile() );
111 sal_Int64 seek( sal_Int64 pos )
113 FILE* pFile = getLogFile();
114 fseek( pFile, 0, SEEK_END );
115 if ( ftell( pFile ) < pos )
117 sal_Int8 filler( 0 );
118 while ( ftell( pFile ) < pos )
119 fwrite( &filler, sizeof( sal_Int8 ), 1, pFile );
120 fflush( pFile );
122 fseek( pFile, pos, SEEK_SET );
123 return ftell( pFile );
126 sal_Int64 tell()
128 return ftell( getLogFile() );
133 #endif
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */