dvander@0: /* dvander@0: * Copyright (C) 2012 David Anderson dvander@0: * dvander@0: * This file is part of JITCraft. dvander@0: * dvander@0: * JITCraft is free software: you can redistribute it and/or modify it under dvander@0: * the terms of the GNU General Public License as published by the Free dvander@0: * Software Foundation, either version 3 of the License, or (at your option) dvander@0: * any later version. dvander@0: * dvander@0: * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY dvander@0: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS dvander@0: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. dvander@0: * dvander@0: * You should have received a copy of the GNU General Public License along with dvander@0: * JITCraft. If not, see http://www.gnu.org/licenses/. dvander@0: */ dvander@0: #ifndef _include_jc_unsafe_array_ dvander@0: #define _include_jc_unsafe_array_ dvander@0: dvander@0: #include dvander@0: dvander@0: namespace jc { dvander@0: dvander@0: class UnsafeArray dvander@0: { dvander@0: public: dvander@0: unsigned length() { dvander@0: return *(reinterpret_cast(this) - 1); dvander@0: } dvander@0: dvander@0: unsigned *uint32Vector() { dvander@0: return reinterpret_cast(this); dvander@0: } dvander@0: int *int32Vector() { dvander@0: return reinterpret_cast(this); dvander@0: } dvander@0: int readInt32(size_t index) { dvander@0: assert(index < length()); dvander@0: return int32Vector()[index]; dvander@0: } dvander@0: void writeInt32(size_t index, int value) { dvander@0: assert(index < length()); dvander@0: int32Vector()[index] = value; dvander@0: } dvander@0: UnsafeArray *indirect(size_t index) { dvander@0: assert(index < length()); dvander@0: unsigned *address = uint32Vector() + index; dvander@0: return reinterpret_cast(reinterpret_cast(address) + *address); dvander@0: } dvander@0: void *allocationBase() { dvander@0: return reinterpret_cast(this) - 1; dvander@0: } dvander@0: }; dvander@0: dvander@0: } dvander@0: dvander@0: #endif // _include_jc_unsafe_array_