track total size of static array and Unit/Class/Func
[hiphop-php.git] / hphp / runtime / base / mem-file.h
blob7716023b62e0c7eba9c78c7be41536d7022475d4
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_MEM_FILE_H_
18 #define incl_HPHP_MEM_FILE_H_
20 #include "hphp/runtime/base/file.h"
21 #include "hphp/runtime/base/type-array.h"
22 #include "hphp/runtime/base/type-string.h"
24 namespace HPHP {
25 ///////////////////////////////////////////////////////////////////////////////
27 /**
28 * memory based files.
30 struct MemFile : File {
31 DECLARE_RESOURCE_ALLOCATION(MemFile);
33 explicit MemFile(const String& wrapper_type = null_string,
34 const String& stream_type = empty_string_ref);
35 MemFile(const char *data, int64_t len,
36 const String& wrapper_type = null_string,
37 const String& stream_type = empty_string_ref);
38 ~MemFile() override;
40 CLASSNAME_IS("MemFile");
41 // overriding ResourceData
42 const String& o_getClassNameHook() const override { return classnameof(); }
44 bool open(const String& filename, const String& mode) override;
45 bool close() override;
46 int64_t readImpl(char *buffer, int64_t length) override;
47 int getc() override;
48 int64_t writeImpl(const char *buffer, int64_t length) override;
49 bool seekable() override { return true;}
50 bool seek(int64_t offset, int whence = SEEK_SET) override;
51 int64_t tell() override;
52 bool eof() override;
53 bool rewind() override;
54 bool flush() override;
56 Array getMetaData() override;
58 void unzip();
60 protected:
61 char *m_data; // data of the memory file
62 int64_t m_len; // length of the memory file
63 int64_t m_cursor; // m_data's read position
64 bool m_malloced; // whether to free m_data on delete
66 bool closeImpl();
69 ///////////////////////////////////////////////////////////////////////////////
72 #endif // incl_HPHP_MEM_FILE_H_