58#define TABLE(entries) { sizeof entries / sizeof *entries, entries }
72#define ENTRY(label, val) { .value = label, .cString = #label },
73#define GALACTIC_HYPERSPACE_ENTRY(label, val) { .value = GALACTIC_HYPERSPACE_##label, .cString = #label },
74#define DIFF_STRING_ENTRY(label, string) { .value = label, .cString = string },
77#include "OOCompassMode.tbl"
81#include "OOEntityStatus.tbl"
85#include "OOGalacticHyperspaceBehaviour.tbl"
89#include "OOGUIScreenID.tbl"
93#include "OOScanClass.tbl"
97#include "OOViewID.tbl"
101#include "OOShipDamageType.tbl"
105#include "OOLegalStatusReason.tbl"
109#include "OOLongRangeChartMode.tbl"
113#undef GALACTIC_HYPERSPACE_ENTRY
114#undef DIFF_STRING_ENTRY
132 NSCAssert(!
sInited,
@"OOConstToJSStringInit() called while already inited.");
133 NSCParameterAssert(context != NULL);
157 NSCAssert(
sInited,
@"OOConstToJSStringDestroy() called while not inited.");
176 NSCParameterAssert(context != NULL && table != NULL);
179 for (i = 0; i < table->
count; i++) {
190 NSCAssert1(
sInited,
@"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
191 NSCParameterAssert(context != NULL);
192 NSCParameterAssert(table != NULL && table->
count > 0);
195 NSInteger min = 0, max = (NSInteger)table->
count - 1;
198 NSInteger mid = (min + max) / 2;
200 if (current < value) {
202 }
else if (current > value) {
205 return JS_AtomToString(context, table->
entries[mid].
atom);
214 NSCAssert1(
sInited,
@"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
215 NSCParameterAssert(context != NULL && table != NULL);
221 JSAtom atom = JS_ValueToAtom(context, value);
223 JS_FreeValue(context, JS_GetException(context));
227 NSInteger result = defaultValue;
229 for (i = 0; i <
count; i++) {
236 JS_FreeAtom(context, atom);
ConstTable gOOViewIDConstTable
ConstTable gOOEntityStatusConstTable
static TableEntry sOOEntityStatusTableEntries[]
static TableEntry sOOGalacticHyperspaceBehaviourTableEntries[]
void OOConstToJSStringDestroy(void)
static int CompareEntries(const void *a, const void *b)
ConstTable gOOLongRangeChartModeConstTable
ConstTable gOOCompassModeConstTable
static TableEntry sOOViewIDTableEntries[]
ConstTable gOOLegalStatusReasonConstTable
void OOConstToJSStringInit(JSContext *context)
static TableEntry sOOScanClassTableEntries[]
static void InitTable(JSContext *context, ConstTable *table)
ConstTable gOOShipDamageTypeConstTable
ConstTable gOOScanClassConstTable
ConstTable gOOGUIScreenIDConstTable
static TableEntry sOOCompassModeTableEntries[]
ConstTable gOOGalacticHyperspaceBehaviourConstTable
static TableEntry sOOLongRangeChartModeTableEntries[]
static TableEntry sOOShipDamageTypeTableEntries[]
static TableEntry sOOGUIScreenIDTableEntries[]
static TableEntry sOOLegalStatusReasonTableEntries[]
NSUInteger OOConstantFromJSValuePRIVATE(JSContext *context, jsval value, struct ConstTable *table, NSInteger defaultValue)
static BOOL sAtomsInterned
JSValue OOJSValueFromConstantPRIVATE(JSContext *context, NSInteger value, struct ConstTable *table)
static JSAtom sUndefinedAtom