File: buffer.h

package info (click to toggle)
tardy 1.12-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,620 kB
  • ctags: 1,014
  • sloc: cpp: 9,530; sh: 4,426; makefile: 723; awk: 44
file content (105 lines) | stat: -rw-r--r-- 3,042 bytes parent folder | download | duplicates (3)
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
//
//	srecord - manipulate eprom load files
//	Copyright (C) 2003, 2004 Peter Miller;
//	All rights reserved.
//
//	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., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
//
// MANIFEST: interface definition for common/file/output/buffer.cc
//

#ifndef COMMON_FILE_OUTPUT_BUFFER_H
#define COMMON_FILE_OUTPUT_BUFFER_H

#pragma interface "file_output_buffer"

#include <file/output.h>

/**
  * The file_output_buffer class is used to represent a buffered output
  * stream.  The data is passed through unchanged, however it is
  * buffered before delivery to the deeper output stream.
  */
class file_output_buffer:
    public file_output
{
public:
    /**
      * The destructor.
      */
    virtual ~file_output_buffer();

    /**
      * The constructor.
      *
      * \param deeper
      *     This argument is used to specify the output stream to write
      *     the data to once it has been buffered.
      * \param blocksize
      *     This argument my be used to specify the block size, in bytes.
      *     It defaults to 512 bytes if zero or negative.
      */
    file_output_buffer(file_output *deeper, int blocksize = 0);

    // See base class for documentation.
    const char *filename() const;

    // See base class for documentation.
    void write(const void *data, int nbytes);

private:
    /**
      * The deeper instance variable is used to remember the output file
      * to write the output to, once it has been buffered.
      */
    file_output *deeper;

    /**
      * The blocksize instance variable is used to remember the size of
      * blocks to be wrutten to the deeper output.
      */
    int blocksize;

    /**
      * The buffer instance variable is used to remember whe the buffer
      * of blocksize byte has been allocated in the heap.
      */
    char *buffer;

    /**
      * The pos instance variable is used to remember how many bytes
      * have been buffered into `buffer'.
      *
      * Invariant: assert(pos >= 0 && pos < blocksize);
      */
    int pos;

    /**
      * The default constructor.  Do not use.
      */
    file_output_buffer();

    /**
      * The copy constructor.  Do not use.
      */
    file_output_buffer(const file_output_buffer &);

    /**
      * The assignment operator.  Do not use.
      */
    file_output_buffer &operator=(const file_output_buffer &);
};

#endif // COMMON_FILE_OUTPUT_BUFFER_H