1.1 --- a/src/NativeTable.h Mon Jun 10 00:46:29 2013 +0100
1.2 +++ b/src/NativeTable.h Mon Jun 10 01:04:43 2013 +0100
1.3 @@ -1,90 +1,90 @@
1.4 -/* vim: set ts=4 sw=4 tw=99 et:
1.5 - *
1.6 - * Copyright (C) 2012 David Anderson
1.7 - *
1.8 - * This file is part of SourcePawn.
1.9 - *
1.10 - * SourcePawn is free software: you can redistribute it and/or modify it under
1.11 - * the terms of the GNU General Public License as published by the Free
1.12 - * Software Foundation, either version 3 of the License, or (at your option)
1.13 - * any later version.
1.14 - *
1.15 - * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
1.16 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.18 - *
1.19 - * You should have received a copy of the GNU General Public License along with
1.20 - * SourcePawn. If not, see http://www.gnu.org/licenses/.
1.21 - */
1.22 -#ifndef _include_sp2_native_table_h_
1.23 -#define _include_sp2_native_table_h_
1.24 -
1.25 -#include <string.h>
1.26 -#include "AllocatorPolicies.h"
1.27 -#include "Strings.h"
1.28 -#include "HashTable.h"
1.29 -#include "Vector.h"
1.30 -#include "VirtualObjectVisitor.h"
1.31 -
1.32 -namespace ke {
1.33 -
1.34 -class NativeTable
1.35 -{
1.36 - public:
1.37 - NativeTable(Zone *zone);
1.38 - ~NativeTable();
1.39 -
1.40 - private:
1.41 - struct NativeInfo {
1.42 - Unbarriered<String> name;
1.43 - void *address;
1.44 - size_t index;
1.45 -
1.46 - NativeInfo(String *name, void *address, size_t index)
1.47 - : address(address),
1.48 - index(index)
1.49 - {
1.50 - this->name = name;
1.51 - }
1.52 - };
1.53 -
1.54 - struct Policy
1.55 - {
1.56 - typedef NativeInfo * Payload;
1.57 -
1.58 - static uint32 hash(const CharsAndLength &key) {
1.59 - return HashCharSequence(key.str(), key.length());
1.60 - }
1.61 -
1.62 - static bool matches(const CharsAndLength &key, NativeInfo *info) {
1.63 - if (info->name->length() != key.length())
1.64 - return false;
1.65 - return memcmp(info->name->chars(), key.str(), key.length() * sizeof(char)) == 0;
1.66 - }
1.67 - };
1.68 -
1.69 - typedef HashTable<Policy, ZoneAllocatorPolicy> NativeMap;
1.70 -
1.71 - public:
1.72 - bool initialize();
1.73 -
1.74 - bool bind(const char *name, void *address);
1.75 - bool add(Handle<String> name, size_t *indexp);
1.76 - String *name(size_t index) const {
1.77 - return natives_[index]->name;
1.78 - }
1.79 - void *address(size_t index) const {
1.80 - return natives_[index]->address;
1.81 - }
1.82 -
1.83 - void accept(VirtualObjectVisitor *visitor);
1.84 -
1.85 - private:
1.86 - Zone *zone_;
1.87 - NativeMap nativeMap_;
1.88 - Vector<NativeInfo *> natives_;
1.89 -};
1.90 -
1.91 -}
1.92 -
1.93 -#endif // _include_sp2_native_table_h_
1.94 +/* vim: set ts=4 sw=4 tw=99 et:
1.95 + *
1.96 + * Copyright (C) 2012 David Anderson
1.97 + *
1.98 + * This file is part of SourcePawn.
1.99 + *
1.100 + * SourcePawn is free software: you can redistribute it and/or modify it under
1.101 + * the terms of the GNU General Public License as published by the Free
1.102 + * Software Foundation, either version 3 of the License, or (at your option)
1.103 + * any later version.
1.104 + *
1.105 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
1.106 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.107 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.108 + *
1.109 + * You should have received a copy of the GNU General Public License along with
1.110 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
1.111 + */
1.112 +#ifndef _include_sp2_native_table_h_
1.113 +#define _include_sp2_native_table_h_
1.114 +
1.115 +#include <string.h>
1.116 +#include "AllocatorPolicies.h"
1.117 +#include "Strings.h"
1.118 +#include "HashTable.h"
1.119 +#include "Vector.h"
1.120 +#include "VirtualObjectVisitor.h"
1.121 +
1.122 +namespace ke {
1.123 +
1.124 +class NativeTable
1.125 +{
1.126 + public:
1.127 + NativeTable(Zone *zone);
1.128 + ~NativeTable();
1.129 +
1.130 + private:
1.131 + struct NativeInfo {
1.132 + Unbarriered<String> name;
1.133 + void *address;
1.134 + size_t index;
1.135 +
1.136 + NativeInfo(String *name, void *address, size_t index)
1.137 + : address(address),
1.138 + index(index)
1.139 + {
1.140 + this->name = name;
1.141 + }
1.142 + };
1.143 +
1.144 + struct Policy
1.145 + {
1.146 + typedef NativeInfo * Payload;
1.147 +
1.148 + static uint32 hash(const CharsAndLength &key) {
1.149 + return HashCharSequence(key.str(), key.length());
1.150 + }
1.151 +
1.152 + static bool matches(const CharsAndLength &key, NativeInfo *info) {
1.153 + if (info->name->length() != key.length())
1.154 + return false;
1.155 + return memcmp(info->name->chars(), key.str(), key.length() * sizeof(char)) == 0;
1.156 + }
1.157 + };
1.158 +
1.159 + typedef HashTable<Policy, ZoneAllocatorPolicy> NativeMap;
1.160 +
1.161 + public:
1.162 + bool initialize();
1.163 +
1.164 + bool bind(const char *name, void *address);
1.165 + bool add(Handle<String> name, size_t *indexp);
1.166 + String *name(size_t index) const {
1.167 + return natives_[index]->name;
1.168 + }
1.169 + void *address(size_t index) const {
1.170 + return natives_[index]->address;
1.171 + }
1.172 +
1.173 + void accept(VirtualObjectVisitor *visitor);
1.174 +
1.175 + private:
1.176 + Zone *zone_;
1.177 + NativeMap nativeMap_;
1.178 + Vector<NativeInfo *> natives_;
1.179 +};
1.180 +
1.181 +}
1.182 +
1.183 +#endif // _include_sp2_native_table_h_