diff -r c4b1341297e5 -r ba85a47ee414 src/NativeTable.h --- a/src/NativeTable.h Mon Jun 10 00:46:29 2013 +0100 +++ b/src/NativeTable.h Mon Jun 10 01:04:43 2013 +0100 @@ -1,90 +1,90 @@ -/* vim: set ts=4 sw=4 tw=99 et: - * - * Copyright (C) 2012 David Anderson - * - * This file is part of SourcePawn. - * - * SourcePawn is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * SourcePawn. If not, see http://www.gnu.org/licenses/. - */ -#ifndef _include_sp2_native_table_h_ -#define _include_sp2_native_table_h_ - -#include -#include "AllocatorPolicies.h" -#include "Strings.h" -#include "HashTable.h" -#include "Vector.h" -#include "VirtualObjectVisitor.h" - -namespace ke { - -class NativeTable -{ - public: - NativeTable(Zone *zone); - ~NativeTable(); - - private: - struct NativeInfo { - Unbarriered name; - void *address; - size_t index; - - NativeInfo(String *name, void *address, size_t index) - : address(address), - index(index) - { - this->name = name; - } - }; - - struct Policy - { - typedef NativeInfo * Payload; - - static uint32 hash(const CharsAndLength &key) { - return HashCharSequence(key.str(), key.length()); - } - - static bool matches(const CharsAndLength &key, NativeInfo *info) { - if (info->name->length() != key.length()) - return false; - return memcmp(info->name->chars(), key.str(), key.length() * sizeof(char)) == 0; - } - }; - - typedef HashTable NativeMap; - - public: - bool initialize(); - - bool bind(const char *name, void *address); - bool add(Handle name, size_t *indexp); - String *name(size_t index) const { - return natives_[index]->name; - } - void *address(size_t index) const { - return natives_[index]->address; - } - - void accept(VirtualObjectVisitor *visitor); - - private: - Zone *zone_; - NativeMap nativeMap_; - Vector natives_; -}; - -} - -#endif // _include_sp2_native_table_h_ +/* vim: set ts=4 sw=4 tw=99 et: + * + * Copyright (C) 2012 David Anderson + * + * This file is part of SourcePawn. + * + * SourcePawn is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * SourcePawn. If not, see http://www.gnu.org/licenses/. + */ +#ifndef _include_sp2_native_table_h_ +#define _include_sp2_native_table_h_ + +#include +#include "AllocatorPolicies.h" +#include "Strings.h" +#include "HashTable.h" +#include "Vector.h" +#include "VirtualObjectVisitor.h" + +namespace ke { + +class NativeTable +{ + public: + NativeTable(Zone *zone); + ~NativeTable(); + + private: + struct NativeInfo { + Unbarriered name; + void *address; + size_t index; + + NativeInfo(String *name, void *address, size_t index) + : address(address), + index(index) + { + this->name = name; + } + }; + + struct Policy + { + typedef NativeInfo * Payload; + + static uint32 hash(const CharsAndLength &key) { + return HashCharSequence(key.str(), key.length()); + } + + static bool matches(const CharsAndLength &key, NativeInfo *info) { + if (info->name->length() != key.length()) + return false; + return memcmp(info->name->chars(), key.str(), key.length() * sizeof(char)) == 0; + } + }; + + typedef HashTable NativeMap; + + public: + bool initialize(); + + bool bind(const char *name, void *address); + bool add(Handle name, size_t *indexp); + String *name(size_t index) const { + return natives_[index]->name; + } + void *address(size_t index) const { + return natives_[index]->address; + } + + void accept(VirtualObjectVisitor *visitor); + + private: + Zone *zone_; + NativeMap nativeMap_; + Vector natives_; +}; + +} + +#endif // _include_sp2_native_table_h_