Oolite
Loading...
Searching...
No Matches
OOConstToJSString.h File Reference
Include dependency graph for OOConstToJSString.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void OOConstToJSStringInit (JSContext *context)
void OOConstToJSStringDestroy (void)
JSValue OOJSValueFromConstantPRIVATE (JSContext *context, NSInteger value, struct ConstTable *table)
NSUInteger OOConstantFromJSValuePRIVATE (JSContext *context, JSValueConst value, struct ConstTable *table, NSInteger defaultValue)
OOINLINE JSValue OOJSValueFromEntityStatus (JSContext *context, OOEntityStatus value)
OOINLINE OOEntityStatus OOEntityStatusFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromScanClass (JSContext *context, OOScanClass value)
OOINLINE OOScanClass OOScanClassFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromCompassMode (JSContext *context, OOCompassMode value)
OOINLINE OOCompassMode OOCompassModeFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromGUIScreenID (JSContext *context, OOGUIScreenID value)
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromGalacticHyperspaceBehaviour (JSContext *context, OOGalacticHyperspaceBehaviour value)
OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromViewID (JSContext *context, OOViewID value)
OOINLINE OOViewID OOViewIDFromJSValue (JSContext *context, JSValueConst value)
OOINLINE JSValue OOJSValueFromShipDamageType (JSContext *context, OOShipDamageType value)
OOINLINE JSValue OOJSValueFromLegalStatusReason (JSContext *context, OOLegalStatusReason value)

Function Documentation

◆ OOCompassModeFromJSValue()

OOINLINE OOCompassMode OOCompassModeFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 91 of file OOConstToJSString.h.

92{
95}
NSUInteger OOConstantFromJSValuePRIVATE(JSContext *context, jsval value, struct ConstTable *table, NSInteger defaultValue)
ConstTable gOOCompassModeConstTable
OOCompassMode
Definition OOTypes.h:129
@ kOOCompassModeDefault
Definition OOTypes.h:134

References gOOCompassModeConstTable, kOOCompassModeDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function:

◆ OOConstantFromJSValuePRIVATE()

NSUInteger OOConstantFromJSValuePRIVATE ( JSContext * context,
JSValueConst value,
struct ConstTable * table,
NSInteger defaultValue )

Definition at line 212 of file OOConstToJSString.m.

213{
214 NSCAssert1(sInited, @"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
215 NSCParameterAssert(context != NULL && table != NULL);
216
217 if (EXPECT_NOT(!JS_IsString(value)))
218 return defaultValue;
219
220 // Interning a string yields the same atom as the table entry with the same contents.
221 JSAtom atom = JS_ValueToAtom(context, value);
222 if (EXPECT_NOT(atom == JS_ATOM_NULL)) {
223 JS_FreeValue(context, JS_GetException(context));
224 return defaultValue;
225 }
226
227 NSInteger result = defaultValue;
228 NSUInteger i, count = table->count;
229 for (i = 0; i < count; i++) {
230 if (table->entries[i].atom == atom) {
231 result = table->entries[i].value;
232 break;
233 }
234 }
235
236 JS_FreeAtom(context, atom);
237 return result;
238}
static BOOL sInited
Definition OOCPUInfo.m:56
#define EXPECT_NOT(x)
unsigned count
TableEntry * entries
NSUInteger count
NSInteger value

References TableEntry::atom, ConstTable::count, count, ConstTable::entries, EXPECT_NOT, sInited, and TableEntry::value.

◆ OOConstToJSStringDestroy()

void OOConstToJSStringDestroy ( void )

Definition at line 149 of file OOConstToJSString.m.

150{
151 NSCAssert(sInited, @"OOConstToJSStringDestroy() called while not inited.");
152 sInited = NO;
153 // jsString pointers are now officially junk.
154}

References sInited.

◆ OOConstToJSStringInit()

void OOConstToJSStringInit ( JSContext * context)

Definition at line 129 of file OOConstToJSString.m.

130{
131 NSCAssert(!sInited, @"OOConstToJSStringInit() called while already inited.");
132 NSCParameterAssert(context != NULL && JS_IsInRequest(context));
133
134 sUndefinedString = JS_InternString(context, "UNDEFINED");
135
145
146 sInited = YES;
147}
ConstTable gOOViewIDConstTable
ConstTable gOOEntityStatusConstTable
static JSString * sUndefinedString
ConstTable gOOLongRangeChartModeConstTable
ConstTable gOOLegalStatusReasonConstTable
static void InitTable(JSContext *context, ConstTable *table)
ConstTable gOOShipDamageTypeConstTable
ConstTable gOOScanClassConstTable
ConstTable gOOGUIScreenIDConstTable
ConstTable gOOGalacticHyperspaceBehaviourConstTable
#define JS_IsInRequest(context)

References gOOCompassModeConstTable, gOOEntityStatusConstTable, gOOGalacticHyperspaceBehaviourConstTable, gOOGUIScreenIDConstTable, gOOLegalStatusReasonConstTable, gOOLongRangeChartModeConstTable, gOOScanClassConstTable, gOOShipDamageTypeConstTable, gOOViewIDConstTable, InitTable(), sAtomsInterned, sInited, and sUndefinedAtom.

Here is the call graph for this function:

◆ OOEntityStatusFromJSValue()

OOINLINE OOEntityStatus OOEntityStatusFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 57 of file OOConstToJSString.h.

58{
61}
@ kOOEntityStatusDefault
Definition Entity.h:326
OOEntityStatus
Definition Entity.h:60

References gOOEntityStatusConstTable, kOOEntityStatusDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function:

◆ OOGalacticHyperspaceBehaviourFromJSValue()

OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 125 of file OOConstToJSString.h.

References gOOGalacticHyperspaceBehaviourConstTable, kOOGalacticHyperspaceBehaviourDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function:

◆ OOGUIScreenIDFromJSValue()

OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 108 of file OOConstToJSString.h.

109{
112}
@ kOOGUIScreenIDDefault
OOGUIScreenID

References gOOGUIScreenIDConstTable, kOOGUIScreenIDDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function:

◆ OOJSValueFromCompassMode()

OOINLINE JSValue OOJSValueFromCompassMode ( JSContext * context,
OOCompassMode value )

Definition at line 85 of file OOConstToJSString.h.

86{
89}
JSValue OOJSValueFromConstantPRIVATE(JSContext *context, NSInteger value, struct ConstTable *table)

References gOOCompassModeConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromConstantPRIVATE()

JSValue OOJSValueFromConstantPRIVATE ( JSContext * context,
NSInteger value,
struct ConstTable * table )

Definition at line 188 of file OOConstToJSString.m.

189{
190 NSCAssert1(sInited, @"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
191 NSCParameterAssert(context != NULL);
192 NSCParameterAssert(table != NULL && table->count > 0);
193
194 // Binary search. (Signed bounds: the SpiderMonkey version underflowed for values below the first entry.)
195 NSInteger min = 0, max = (NSInteger)table->count - 1;
196 NSInteger current;
197 while (min <= max) {
198 NSInteger mid = (min + max) / 2;
199 current = table->entries[mid].value;
200 if (current < value) {
201 min = mid + 1;
202 } else if (current > value) {
203 max = mid - 1;
204 } else {
205 return JS_AtomToString(context, table->entries[mid].atom);
206 }
207 }
208
209 return JS_AtomToString(context, sUndefinedAtom);
210}
static JSAtom sUndefinedAtom

References TableEntry::atom, ConstTable::count, ConstTable::entries, sInited, sUndefinedAtom, and TableEntry::value.

Referenced by OOJSValueFromCompassMode(), OOJSValueFromEntityStatus(), OOJSValueFromGalacticHyperspaceBehaviour(), OOJSValueFromGUIScreenID(), OOJSValueFromLegalStatusReason(), OOJSValueFromScanClass(), OOJSValueFromShipDamageType(), and OOJSValueFromViewID().

Here is the caller graph for this function:

◆ OOJSValueFromEntityStatus()

OOINLINE JSValue OOJSValueFromEntityStatus ( JSContext * context,
OOEntityStatus value )

Definition at line 51 of file OOConstToJSString.h.

52{
55}

References gOOEntityStatusConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromGalacticHyperspaceBehaviour()

OOINLINE JSValue OOJSValueFromGalacticHyperspaceBehaviour ( JSContext * context,
OOGalacticHyperspaceBehaviour value )

Definition at line 119 of file OOConstToJSString.h.

References gOOGalacticHyperspaceBehaviourConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromGUIScreenID()

OOINLINE JSValue OOJSValueFromGUIScreenID ( JSContext * context,
OOGUIScreenID value )

Definition at line 102 of file OOConstToJSString.h.

103{
106}

References gOOGUIScreenIDConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromLegalStatusReason()

OOINLINE JSValue OOJSValueFromLegalStatusReason ( JSContext * context,
OOLegalStatusReason value )

Definition at line 162 of file OOConstToJSString.h.

References gOOLegalStatusReasonConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromScanClass()

OOINLINE JSValue OOJSValueFromScanClass ( JSContext * context,
OOScanClass value )

Definition at line 68 of file OOConstToJSString.h.

69{
72}

References gOOScanClassConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromShipDamageType()

OOINLINE JSValue OOJSValueFromShipDamageType ( JSContext * context,
OOShipDamageType value )

Definition at line 152 of file OOConstToJSString.h.

153{
156}

References gOOShipDamageTypeConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOJSValueFromViewID()

OOINLINE JSValue OOJSValueFromViewID ( JSContext * context,
OOViewID value )

Definition at line 136 of file OOConstToJSString.h.

137{
138 extern struct ConstTable gOOViewIDConstTable;
139 return OOJSValueFromConstantPRIVATE(context, value, &gOOViewIDConstTable);
140}

References gOOViewIDConstTable, OOINLINE, and OOJSValueFromConstantPRIVATE().

Here is the call graph for this function:

◆ OOScanClassFromJSValue()

OOINLINE OOScanClass OOScanClassFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 74 of file OOConstToJSString.h.

75{
78}
@ kOOScanClassDefault
Definition Entity.h:327
OOScanClass
Definition Entity.h:69

References gOOScanClassConstTable, kOOScanClassDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function:

◆ OOViewIDFromJSValue()

OOINLINE OOViewID OOViewIDFromJSValue ( JSContext * context,
JSValueConst value )

Definition at line 142 of file OOConstToJSString.h.

143{
144 extern struct ConstTable gOOViewIDConstTable;
146}
OOViewID
Definition OOTypes.h:39
@ kOOViewIDDefault
Definition OOTypes.h:42

References gOOViewIDConstTable, kOOViewIDDefault, OOConstantFromJSValuePRIVATE(), and OOINLINE.

Here is the call graph for this function: