| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | |
| 14 | #ifndef PX_PHYSICS_EXTENSIONS_DEFAULT_STREAMS_H |
| 15 | #define PX_PHYSICS_EXTENSIONS_DEFAULT_STREAMS_H |
| 16 | /** \addtogroup extensions |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include "common/PxPhysXCommonConfig.h" |
| 22 | #include "foundation/PxIO.h" |
| 23 | #include "foundation/PxFoundation.h" |
| 24 | |
| 25 | #ifndef PX_WIIU |
| 26 | typedef FILE* PxFileHandle; |
| 27 | #else |
| 28 | #include "extensions/wiiu/PxWiiUFileHandle.h" |
| 29 | #endif |
| 30 | |
| 31 | #ifndef PX_DOXYGEN |
| 32 | namespace physx |
| 33 | { |
| 34 | #endif |
| 35 | |
| 36 | /** |
| 37 | \brief default implementation of a memory write stream |
| 38 | |
| 39 | @see PxOutputStream |
| 40 | */ |
| 41 | |
| 42 | class PxDefaultMemoryOutputStream: public PxOutputStream |
| 43 | { |
| 44 | public: |
| 45 | PxDefaultMemoryOutputStream(PxAllocatorCallback &allocator = PxGetFoundation().getAllocatorCallback()); |
| 46 | virtual ~PxDefaultMemoryOutputStream(); |
| 47 | |
| 48 | virtual PxU32 write(const void* src, PxU32 count); |
| 49 | |
| 50 | virtual PxU32 getSize() const { return mSize; } |
| 51 | virtual PxU8* getData() const { return mData; } |
| 52 | |
| 53 | private: |
| 54 | PxDefaultMemoryOutputStream(const PxDefaultMemoryOutputStream&); |
| 55 | PxDefaultMemoryOutputStream& operator=(const PxDefaultMemoryOutputStream&); |
| 56 | |
| 57 | PxAllocatorCallback& mAllocator; |
| 58 | PxU8* mData; |
| 59 | PxU32 mSize; |
| 60 | PxU32 mCapacity; |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | \brief default implementation of a memory read stream |
| 65 | |
| 66 | @see PxInputData |
| 67 | */ |
| 68 | |
| 69 | class PxDefaultMemoryInputData: public PxInputData |
| 70 | { |
| 71 | public: |
| 72 | PxDefaultMemoryInputData(PxU8* data, PxU32 length); |
| 73 | |
| 74 | virtual PxU32 read(void* dest, PxU32 count); |
| 75 | virtual PxU32 getLength() const; |
| 76 | virtual void seek(PxU32 pos); |
| 77 | virtual PxU32 tell() const; |
| 78 | |
| 79 | private: |
| 80 | PxU32 mSize; |
| 81 | const PxU8* mData; |
| 82 | PxU32 mPos; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | \brief default implementation of a file write stream |
| 89 | |
| 90 | @see PxOutputStream |
| 91 | */ |
| 92 | |
| 93 | class PxDefaultFileOutputStream: public PxOutputStream |
| 94 | { |
| 95 | public: |
| 96 | PxDefaultFileOutputStream(const char* name); |
| 97 | virtual ~PxDefaultFileOutputStream(); |
| 98 | |
| 99 | virtual PxU32 write(const void* src, PxU32 count); |
| 100 | virtual bool isValid(); |
| 101 | private: |
| 102 | PxFileHandle mFile; |
| 103 | }; |
| 104 | |
| 105 | |
| 106 | /** |
| 107 | \brief default implementation of a file read stream |
| 108 | |
| 109 | @see PxInputData |
| 110 | */ |
| 111 | |
| 112 | class PxDefaultFileInputData: public PxInputData |
| 113 | { |
| 114 | public: |
| 115 | PxDefaultFileInputData(const char* name); |
| 116 | virtual ~PxDefaultFileInputData(); |
| 117 | |
| 118 | virtual PxU32 read(void* dest, PxU32 count); |
| 119 | virtual void seek(PxU32 pos); |
| 120 | virtual PxU32 tell() const; |
| 121 | virtual PxU32 getLength() const; |
| 122 | |
| 123 | bool isValid() const; |
| 124 | private: |
| 125 | PxFileHandle mFile; |
| 126 | PxU32 mLength; |
| 127 | }; |
| 128 | |
| 129 | #ifndef PX_DOXYGEN |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | /** @} */ |
| 134 | |
| 135 | #endif |
| 136 | |
| 137 | |