summaryrefslogtreecommitdiffstats
path: root/src/svnqt/svnfilestream.cpp
blob: b160003779c386812ef9c7c7e6b4e47411984dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/***************************************************************************
 *   Copyright (C) 2006-2007 by Rajko Albrecht                             *
 *   ral@alwins-world.de                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/
#include "svnfilestream.hpp"

#include <tqfile.h>

namespace svn {

namespace stream {

typedef int openmode;
#define READONLY IO_ReadOnly
#define WRITEONLY IO_WriteOnly

class SVNTQT_NOEXPORT SvnFileStream_private
{
public:
    SvnFileStream_private(const TQString&fn,openmode mode);
    virtual ~SvnFileStream_private();

    TQString m_FileName;
    TQFile m_File;
};

SvnFileStream_private::SvnFileStream_private(const TQString&fn,openmode mode)
    : m_FileName(fn),m_File(fn)
{
    m_File.open(mode);
}

SvnFileStream_private::~SvnFileStream_private()
{
}

SvnFileOStream::SvnFileOStream(const TQString&fn,svn_client_ctx_t*ctx)
    :SvnStream(false,true,ctx)
{
    m_FileData = new SvnFileStream_private(fn,WRITEONLY);
    if (!m_FileData->m_File.isOpen()) {
        setError(m_FileData->m_File.errorString());
    }
}


SvnFileOStream::~SvnFileOStream()
{
    delete m_FileData;
}


bool SvnFileOStream::isOk() const
{
    return m_FileData->m_File.isOpen();
}

long SvnFileOStream::write(const char* data, const unsigned long max)
{
    if (!m_FileData->m_File.isOpen()) {
        return -1;
    }
    long res = m_FileData->m_File.writeBlock(data,max);
    if (res<0) {
        setError(m_FileData->m_File.errorString());
    }
    return res;
}

SvnFileIStream::SvnFileIStream(const TQString&fn,svn_client_ctx_t*ctx)
    :SvnStream(true,false,ctx)
{
    m_FileData = new SvnFileStream_private(fn,READONLY);
    if (!m_FileData->m_File.isOpen()) {
        setError(m_FileData->m_File.errorString());
    }
}


SvnFileIStream::~SvnFileIStream()
{
    delete m_FileData;
}


bool SvnFileIStream::isOk() const
{
    return m_FileData->m_File.isOpen();
}

long SvnFileIStream::read(char* data, const unsigned long max)
{
    if (!m_FileData->m_File.isOpen()) {
        return -1;
    }
    long res = m_FileData->m_File.readBlock(data,max);
    if (res<0) {
        setError(m_FileData->m_File.errorString());
    }
    return res;
}

}

}