1 /*
2  * FileBinaryOutputPort.h - <file binary output port>
3  *
4  *   Copyright (c) 2008  Higepon(Taro Minowa)  <higepon@users.sourceforge.jp>
5  *   Copyright (c) 2009  Kokosabu(MIURA Yasuyuki)  <kokosabu@gmail.com>
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *   1. Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *
14  *   2. Redistributions in binary form must reproduce the above copyright
15  *      notice, this list of conditions and the following disclaimer in the
16  *      documentation and/or other materials provided with the distribution.
17  *
18  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *  $Id$
31  */
32 
33 #ifndef SCHEME_FILE_BINARY_OUTPUT_PORT_
34 #define SCHEME_FILE_BINARY_OUTPUT_PORT_
35 
36 #include "BinaryOutputPort.h"
37 #include "OSCompat.h"
38 
39 namespace scheme {
40 
41 class FileBinaryOutputPort : public BinaryOutputPort
42 {
43 public:
44     FileBinaryOutputPort(File* file);
45     FileBinaryOutputPort(ucs4string file);
46     FileBinaryOutputPort(ucs4string file, int openFlags);
47     virtual ~FileBinaryOutputPort();
48 
49     int putU8(uint8_t v);
50     int64_t putU8(uint8_t* v, int64_t size);
51     int64_t putByteVector(ByteVector* bv, int64_t start = 0);
52     int64_t putByteVector(ByteVector* bv, int64_t start, int64_t count);
53     int open();
54     int close();
55     int pseudoClose();
56     bool isClosed() const;
57     void flush();
58     ucs4string toString();
59     bool hasPosition() const;
60     bool hasSetPosition() const;
61     Object position() const;
62     bool setPosition(int64_t position);
63     File* getFile();
getLastErrorMessage()64     ucs4string getLastErrorMessage()
65     {
66         return file_->getLastErrorMessage();
67     }
68 
69 protected:
70     File* file_;
71     ucs4string fileName_;
72     bool isClosed_;
73     bool isPseudoClosed_;
74     int64_t position_;
75 };
76 
77 } // namespace scheme
78 
79 #endif // SCHEME_FILE_BINARY_OUTPUT_PORT_
80