Bug 591908: Remove Math.floor from microbenchmark iterations/sec calculation (r=fklockii)
[tamarin-stm.git] / shell / File.h
blobf190fbae004b3373fd41d151f032c172f7bae968
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmshell_File__
41 #define __avmshell_File__
43 #include "avmshell.h"
45 namespace avmshell
47 /**
48 * Abstract base class for performing platform-specific file operations
49 * This class needs to be derived and its methods implemented by platform to enable the shell to perform file I/O
51 class File
53 public:
54 /**
55 * An enum defining the open modes for a file
57 typedef enum
59 OPEN_READ = 0,
60 OPEN_WRITE,
61 OPEN_APPEND,
62 OPEN_READ_BINARY,
63 OPEN_WRITE_BINARY,
64 OPEN_APPEND_BINARY
65 }OpenAttribute;
67 /**
68 * Virtual Destructor
70 virtual ~File() {}
72 /**
73 * Method to open a file on platform's file system
74 * The implementation should open the file with the given name and attributes for open mode
75 * @param filename represents the path and name of the file to be opened. filename is UTF-8
76 * @param flags one of the values from OpenAttribute enumeration indicating the mode of file
77 * @return true if file was opened successfully, false otherwise
78 * @see enum OpenAttribute
80 virtual bool open(const char* filename, OpenAttribute flags) = 0;
82 /**
83 * Method to close an opened file.
84 * If the file was not opened this method should do nothing
85 * @return none
87 virtual void close() = 0;
89 /**
90 * Method to read a chunk of data from the file
91 * This method can return 0 in event of a read error or if the file marker was at end-of-file.
92 * So a return value of zero should not be treated as an error condition by default.
93 * Instead method isEOF() should be used to detect a end-of-file .
94 * @param buffer buffer to read the data into
95 * @param bytesToRead number of bytes to read
96 * @return number of bytes actually read. 0 or less than bytesToRead in case of error or end-of-file was reached
98 virtual size_t read(void* buffer, size_t bytesToRead) = 0;
101 * Method to write a chunk of data to the file
102 * @param buffer buffer containing the data to write to file
103 * @param bytesToWrite number of bytes to write from the buffer
104 * @return number of bytes actually written. If this value is less than bytesToWrite then that indicates an error
106 virtual size_t write(const void* buffer, size_t bytesToWrite) = 0;
109 * Method to get the current position of the file head
110 * @return returns the current byte position of the file head, -1 if an error occurred
112 virtual int64_t getPosition() const = 0;
115 * Method to move the file head to a certain position
116 * @param pos number indicating the byte position in file to move the file head to
117 * @return returns true if the operation was successful, false if an error occurred
119 virtual bool setPosition(int64_t pos) = 0;
122 * Method to get the size of file
123 * @return size of the file, -1 if an error occurred
125 virtual int64_t size() const = 0;
128 * Method to check if the end-of-file has reached
129 * @return true if end if reached, false otherwise
131 virtual bool isEOF() const = 0;
135 #endif /* __avmshell_File__ */