~ubuntu-branches/ubuntu/raring/notecase/raring

« back to all changes in this revision

Viewing changes to src/lib/IOLayerFile64.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Handler
  • Date: 2008-12-21 13:09:58 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221130958-0ri77h0x7j1dclkq
Tags: 1.9.8-0ubuntu1
New upstream release (LP: #307752)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////////////////
2
 
// NoteCase notes manager project <http://notecase.sf.net>
3
 
//
4
 
// This code is licensed under BSD license.See "license.txt" for more details.
5
 
//
6
 
// File: Implements layer for actual reading/writing data into the file
7
 
////////////////////////////////////////////////////////////////////////////
8
 
 
9
 
#include "IOLayerFile64.h"
10
 
#include "debug.h"
11
 
 
12
 
IOLayerFile64::IOLayerFile64()
13
 
{
14
 
        m_nEndOffset = -1;
15
 
}
16
 
 
17
 
IOLayerFile64::~IOLayerFile64()
18
 
{
19
 
}
20
 
 
21
 
int IOLayerFile64::Process(char *szBuffer, int nLen)
22
 
{
23
 
        int nBytes = 0;
24
 
 
25
 
        if(MODE_WRITE == m_nMode)
26
 
        {
27
 
                nBytes = m_file.Write(szBuffer, nLen);
28
 
                //TRACE("IOLayerFile64::Write (%d bytes)\n", nLen);
29
 
        }
30
 
        else
31
 
        {
32
 
                nBytes = m_file.Read(szBuffer, nLen);
33
 
 
34
 
                //when we have read limit defined
35
 
                if(nBytes > 0 && m_nEndOffset > 0){
36
 
                        INT64 nPos = m_file.GetPosition();
37
 
                        if(nPos > m_nEndOffset){
38
 
                                nBytes -= (int)(nPos-m_nEndOffset);
39
 
                                if(nBytes < 0)
40
 
                                        nBytes = 0;
41
 
                        }
42
 
                }
43
 
 
44
 
                //TRACE("IOLayerFile64::Read  (buffer size=%d, read bytes=%d)\n", nLen, nBytes);
45
 
        }
46
 
 
47
 
        m_nProcessedInBytes += nBytes;
48
 
        m_nProcessedOutBytes += nBytes;
49
 
 
50
 
        //store output size for this operation
51
 
        m_nLastOutBytes = nBytes;
52
 
 
53
 
        //call next layer attached?
54
 
        if(NULL != m_pNextLayer && nBytes > 0)
55
 
                return m_pNextLayer->Process(szBuffer, nBytes);
56
 
 
57
 
        return nBytes;
58
 
}
59
 
 
60
 
int IOLayerFile64::Finalize()
61
 
{
62
 
        TRACE("IOLayerFile64::Finalize (pass forward)\n");
63
 
 
64
 
        //call next layer attached?
65
 
        if(NULL != m_pNextLayer)
66
 
                return m_pNextLayer->Finalize();
67
 
        return 0;
68
 
}
 
1
////////////////////////////////////////////////////////////////////////////
 
2
// NoteCase notes manager project <http://notecase.sf.net>
 
3
//
 
4
// This code is licensed under BSD license.See "license.txt" for more details.
 
5
//
 
6
// File: Implements layer for actual reading/writing data into the file
 
7
////////////////////////////////////////////////////////////////////////////
 
8
 
 
9
#include "IOLayerFile64.h"
 
10
#include "debug.h"
 
11
 
 
12
IOLayerFile64::IOLayerFile64()
 
13
{
 
14
        m_nEndOffset = -1;
 
15
}
 
16
 
 
17
IOLayerFile64::~IOLayerFile64()
 
18
{
 
19
}
 
20
 
 
21
int IOLayerFile64::Process(char *szBuffer, int nLen)
 
22
{
 
23
        int nBytes = 0;
 
24
 
 
25
        if(MODE_WRITE == m_nMode)
 
26
        {
 
27
                nBytes = m_file.Write(szBuffer, nLen);
 
28
                //TRACE("IOLayerFile64::Write (%d bytes)\n", nLen);
 
29
        }
 
30
        else
 
31
        {
 
32
                nBytes = m_file.Read(szBuffer, nLen);
 
33
 
 
34
                //when we have read limit defined
 
35
                if(nBytes > 0 && m_nEndOffset > 0){
 
36
                        INT64 nPos = m_file.GetPosition();
 
37
                        if(nPos > m_nEndOffset){
 
38
                                nBytes -= (int)(nPos-m_nEndOffset);
 
39
                                if(nBytes < 0)
 
40
                                        nBytes = 0;
 
41
                        }
 
42
                }
 
43
 
 
44
                //TRACE("IOLayerFile64::Read  (buffer size=%d, read bytes=%d)\n", nLen, nBytes);
 
45
        }
 
46
 
 
47
        m_nProcessedInBytes += nBytes;
 
48
        m_nProcessedOutBytes += nBytes;
 
49
 
 
50
        //store output size for this operation
 
51
        m_nLastOutBytes = nBytes;
 
52
 
 
53
        //call next layer attached?
 
54
        if(NULL != m_pNextLayer && nBytes > 0)
 
55
                return m_pNextLayer->Process(szBuffer, nBytes);
 
56
 
 
57
        return nBytes;
 
58
}
 
59
 
 
60
int IOLayerFile64::Finalize()
 
61
{
 
62
        TRACE("IOLayerFile64::Finalize (pass forward)\n");
 
63
 
 
64
        //call next layer attached?
 
65
        if(NULL != m_pNextLayer)
 
66
                return m_pNextLayer->Finalize();
 
67
        return 0;
 
68
}