Oolite 1.91.0.7645-241119-222d325
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)
 
JSString * OOJSStringFromConstantPRIVATE (JSContext *context, NSInteger value, struct ConstTable *table)
 
NSUInteger OOConstantFromJSStringPRIVATE (JSContext *context, JSString *string, struct ConstTable *table, NSInteger defaultValue)
 
NSUInteger OOConstantFromJSValuePRIVATE (JSContext *context, jsval value, struct ConstTable *table, NSInteger defaultValue)
 
OOINLINE JSString * OOJSStringFromEntityStatus (JSContext *context, OOEntityStatus value)
 
OOINLINE jsval OOJSValueFromEntityStatus (JSContext *context, OOEntityStatus value)
 
OOINLINE OOEntityStatus OOEntityStatusFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOEntityStatus OOEntityStatusFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromScanClass (JSContext *context, OOScanClass value)
 
OOINLINE jsval OOJSValueFromScanClass (JSContext *context, OOScanClass value)
 
OOINLINE OOScanClass OOScanClassFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOScanClass OOScanClassFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromCompassMode (JSContext *context, OOCompassMode value)
 
OOINLINE jsval OOJSValueFromCompassMode (JSContext *context, OOCompassMode value)
 
OOINLINE OOCompassMode OOCompassModeFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOCompassMode OOCompassModeFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromGUIScreenID (JSContext *context, OOGUIScreenID value)
 
OOINLINE jsval OOJSValueFromGUIScreenID (JSContext *context, OOGUIScreenID value)
 
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromGalacticHyperspaceBehaviour (JSContext *context, OOGalacticHyperspaceBehaviour value)
 
OOINLINE jsval OOJSValueFromGalacticHyperspaceBehaviour (JSContext *context, OOGalacticHyperspaceBehaviour value)
 
OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromViewID (JSContext *context, OOViewID value)
 
OOINLINE jsval OOJSValueFromViewID (JSContext *context, OOViewID value)
 
OOINLINE OOViewID OOViewIDFromJSString (JSContext *context, JSString *string)
 
OOINLINE OOViewID OOViewIDFromJSValue (JSContext *context, jsval value)
 
OOINLINE JSString * OOJSStringFromShipDamageType (JSContext *context, OOShipDamageType value)
 
OOINLINE jsval OOJSValueFromShipDamageType (JSContext *context, OOShipDamageType value)
 
OOINLINE JSString * OOJSStringFromLegalStatusReason (JSContext *context, OOLegalStatusReason value)
 
OOINLINE jsval OOJSValueFromLegalStatusReason (JSContext *context, OOLegalStatusReason value)
 

Function Documentation

◆ OOCompassModeFromJSString()

OOINLINE OOCompassMode OOCompassModeFromJSString ( JSContext * context,
JSString * string )

Definition at line 132 of file OOConstToJSString.h.

133{
136}
NSUInteger OOConstantFromJSStringPRIVATE(JSContext *context, JSString *string, struct ConstTable *table, NSInteger defaultValue)
ConstTable gOOCompassModeConstTable
OOCompassMode
Definition OOTypes.h:145
@ kOOCompassModeDefault
Definition OOTypes.h:151

References gOOCompassModeConstTable, kOOCompassModeDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOCompassModeFromJSValue()

OOINLINE OOCompassMode OOCompassModeFromJSValue ( JSContext * context,
jsval value )

Definition at line 139 of file OOConstToJSString.h.

140{
143}
NSUInteger OOConstantFromJSValuePRIVATE(JSContext *context, jsval value, struct ConstTable *table, NSInteger defaultValue)

References gOOCompassModeConstTable, kOOCompassModeDefault, and OOConstantFromJSValuePRIVATE().

Referenced by PlayerShipSetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOConstantFromJSStringPRIVATE()

NSUInteger OOConstantFromJSStringPRIVATE ( JSContext * context,
JSString * string,
struct ConstTable * table,
NSInteger defaultValue )

Definition at line 232 of file OOConstToJSString.m.

233{
234 NSCAssert1(sInited, @"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
235 NSCParameterAssert(context != NULL && JS_IsInRequest(context) && table != NULL);
236
237 // Quick pass: look for pointer-equal string.
238 NSUInteger i, count = table->count;
239 for(i = 0; i < count; i++)
240 {
241 if (table->entries[i].jsString == string)
242 {
243 return table->entries[i].value;
244 }
245 }
246
247
248 // Slow pass: use string comparison. This is expected to fail.
249 if (string != NULL)
250 {
251 for(i = 0; i < count; i++)
252 {
253 int32 result;
254 if (JS_CompareStrings(context, string, table->entries[i].jsString, &result) && result == 0)
255 {
256 return table->entries[i].value;
257 }
258 }
259 }
260
261 // Fail.
262 return defaultValue;
263}
static BOOL sInited
#define JS_IsInRequest(context)
unsigned count
TableEntry * entries
NSUInteger count
NSInteger value
JSString * jsString

References ConstTable::count, count, ConstTable::entries, JS_IsInRequest, TableEntry::jsString, sInited, and TableEntry::value.

Referenced by OOCompassModeFromJSString(), OOConstantFromJSValuePRIVATE(), OOEntityStatusFromJSString(), OOGalacticHyperspaceBehaviourFromJSString(), OOGUIScreenIDFromJSString(), OOScanClassFromJSString(), and OOViewIDFromJSString().

+ Here is the caller graph for this function:

◆ OOConstantFromJSValuePRIVATE()

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

Definition at line 266 of file OOConstToJSString.m.

267{
268 if (EXPECT(JSVAL_IS_STRING(value)))
269 {
270 return OOConstantFromJSStringPRIVATE(context, JSVAL_TO_STRING(value), table, defaultValue);
271 }
272 else
273 {
274 return defaultValue;
275 }
276
277}
NSUInteger OOConstantFromJSStringPRIVATE(JSContext *context, JSString *string, struct ConstTable *table, NSInteger defaultValue)
#define EXPECT(x)

References EXPECT, and OOConstantFromJSStringPRIVATE().

Referenced by OOCompassModeFromJSValue(), OOEntityStatusFromJSValue(), OOGalacticHyperspaceBehaviourFromJSValue(), OOGUIScreenIDFromJSValue(), OOScanClassFromJSValue(), and OOViewIDFromJSValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOConstToJSStringDestroy()

void OOConstToJSStringDestroy ( void )

Definition at line 165 of file OOConstToJSString.m.

166{
167 NSCAssert(sInited, @"OOConstToJSStringDestroy() called while not inited.");
168 sInited = NO;
169 // jsString pointers are now officially junk.
170}

References sInited.

◆ OOConstToJSStringInit()

void OOConstToJSStringInit ( JSContext * context)

Definition at line 144 of file OOConstToJSString.m.

145{
146 NSCAssert(!sInited, @"OOConstToJSStringInit() called while already inited.");
147 NSCParameterAssert(context != NULL && JS_IsInRequest(context));
148
149 sUndefinedString = JS_InternString(context, "UNDEFINED");
150
160
161 sInited = YES;
162}
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

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

+ Here is the call graph for this function:

◆ OOEntityStatusFromJSString()

OOINLINE OOEntityStatus OOEntityStatusFromJSString ( JSContext * context,
JSString * string )

Definition at line 64 of file OOConstToJSString.h.

65{
68}
OOEntityStatus
Definition Entity.h:60
@ kOOEntityStatusDefault
Definition Entity.h:325

References gOOEntityStatusConstTable, kOOEntityStatusDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOEntityStatusFromJSValue()

OOINLINE OOEntityStatus OOEntityStatusFromJSValue ( JSContext * context,
jsval value )

Definition at line 71 of file OOConstToJSString.h.

References gOOEntityStatusConstTable, kOOEntityStatusDefault, and OOConstantFromJSValuePRIVATE().

+ Here is the call graph for this function:

◆ OOGalacticHyperspaceBehaviourFromJSString()

OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSString ( JSContext * context,
JSString * string )

Definition at line 201 of file OOConstToJSString.h.

References gOOGalacticHyperspaceBehaviourConstTable, kOOGalacticHyperspaceBehaviourDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOGalacticHyperspaceBehaviourFromJSValue()

OOINLINE OOGalacticHyperspaceBehaviour OOGalacticHyperspaceBehaviourFromJSValue ( JSContext * context,
jsval value )

Definition at line 208 of file OOConstToJSString.h.

References gOOGalacticHyperspaceBehaviourConstTable, kOOGalacticHyperspaceBehaviourDefault, and OOConstantFromJSValuePRIVATE().

Referenced by PlayerShipSetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOGUIScreenIDFromJSString()

OOINLINE OOGUIScreenID OOGUIScreenIDFromJSString ( JSContext * context,
JSString * string )

Definition at line 166 of file OOConstToJSString.h.

167{
170}
OOGUIScreenID
@ kOOGUIScreenIDDefault

References gOOGUIScreenIDConstTable, kOOGUIScreenIDDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOGUIScreenIDFromJSValue()

OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue ( JSContext * context,
jsval value )

Definition at line 173 of file OOConstToJSString.h.

References gOOGUIScreenIDConstTable, kOOGUIScreenIDDefault, and OOConstantFromJSValuePRIVATE().

Referenced by GlobalClearExtraGuiScreenKeys(), GlobalSetExtraGuiScreenKeys(), and MissionSetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromCompassMode()

OOINLINE JSString * OOJSStringFromCompassMode ( JSContext * context,
OOCompassMode value )

Definition at line 119 of file OOConstToJSString.h.

120{
123}
JSString * OOJSStringFromConstantPRIVATE(JSContext *context, NSInteger value, struct ConstTable *table)

References gOOCompassModeConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromCompassMode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromConstantPRIVATE()

JSString * OOJSStringFromConstantPRIVATE ( JSContext * context,
NSInteger value,
struct ConstTable * table )

Definition at line 200 of file OOConstToJSString.m.

201{
202 NSCAssert1(sInited, @"%s called before OOConstToJSStringInit().", __PRETTY_FUNCTION__);
203 NSCParameterAssert(context != NULL && JS_IsInRequest(context));
204 NSCParameterAssert(table != NULL && table->count > 0);
205
206 // Binary search.
207 NSUInteger min = 0, max = table->count - 1;
208 NSInteger current;
209 do
210 {
211 NSUInteger mid = (min + max) / 2;
212 current = table->entries[mid].value;
213 if (current < value)
214 {
215 min = mid + 1;
216 }
217 else if (current > value)
218 {
219 max = mid - 1;
220 }
221 else
222 {
223 return table->entries[mid].jsString;
224 }
225 }
226 while (min <= max);
227
228 return sUndefinedString;
229}

References ConstTable::count, ConstTable::entries, JS_IsInRequest, TableEntry::jsString, sInited, sUndefinedString, and TableEntry::value.

Referenced by OOJSStringFromCompassMode(), OOJSStringFromEntityStatus(), OOJSStringFromGalacticHyperspaceBehaviour(), OOJSStringFromGUIScreenID(), OOJSStringFromLegalStatusReason(), OOJSStringFromScanClass(), OOJSStringFromShipDamageType(), and OOJSStringFromViewID().

+ Here is the caller graph for this function:

◆ OOJSStringFromEntityStatus()

OOINLINE JSString * OOJSStringFromEntityStatus ( JSContext * context,
OOEntityStatus value )

Definition at line 51 of file OOConstToJSString.h.

52{
55}

References gOOEntityStatusConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromEntityStatus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromGalacticHyperspaceBehaviour()

OOINLINE JSString * OOJSStringFromGalacticHyperspaceBehaviour ( JSContext * context,
OOGalacticHyperspaceBehaviour value )

Definition at line 188 of file OOConstToJSString.h.

References gOOGalacticHyperspaceBehaviourConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromGalacticHyperspaceBehaviour().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromGUIScreenID()

OOINLINE JSString * OOJSStringFromGUIScreenID ( JSContext * context,
OOGUIScreenID value )

Definition at line 153 of file OOConstToJSString.h.

154{
157}

References gOOGUIScreenIDConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromGUIScreenID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromLegalStatusReason()

OOINLINE JSString * OOJSStringFromLegalStatusReason ( JSContext * context,
OOLegalStatusReason value )

Definition at line 270 of file OOConstToJSString.h.

References gOOLegalStatusReasonConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromLegalStatusReason().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromScanClass()

OOINLINE JSString * OOJSStringFromScanClass ( JSContext * context,
OOScanClass value )

Definition at line 85 of file OOConstToJSString.h.

86{
89}

References gOOScanClassConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromScanClass().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromShipDamageType()

OOINLINE JSString * OOJSStringFromShipDamageType ( JSContext * context,
OOShipDamageType value )

Definition at line 256 of file OOConstToJSString.h.

257{
260}

References gOOShipDamageTypeConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromShipDamageType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSStringFromViewID()

OOINLINE JSString * OOJSStringFromViewID ( JSContext * context,
OOViewID value )

Definition at line 223 of file OOConstToJSString.h.

224{
225 extern struct ConstTable gOOViewIDConstTable;
226 return OOJSStringFromConstantPRIVATE(context, value, &gOOViewIDConstTable);
227}

References gOOViewIDConstTable, and OOJSStringFromConstantPRIVATE().

Referenced by OOJSValueFromViewID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromCompassMode()

OOINLINE jsval OOJSValueFromCompassMode ( JSContext * context,
OOCompassMode value )

Definition at line 126 of file OOConstToJSString.h.

127{
128 return STRING_TO_JSVAL(OOJSStringFromCompassMode(context, value));
129}
OOINLINE JSString * OOJSStringFromCompassMode(JSContext *context, OOCompassMode value)

References OOJSStringFromCompassMode().

Referenced by PlayerShipGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromEntityStatus()

OOINLINE jsval OOJSValueFromEntityStatus ( JSContext * context,
OOEntityStatus value )

Definition at line 58 of file OOConstToJSString.h.

59{
60 return STRING_TO_JSVAL(OOJSStringFromEntityStatus(context, value));
61}
OOINLINE JSString * OOJSStringFromEntityStatus(JSContext *context, OOEntityStatus value)

References OOJSStringFromEntityStatus().

Referenced by EntityGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromGalacticHyperspaceBehaviour()

OOINLINE jsval OOJSValueFromGalacticHyperspaceBehaviour ( JSContext * context,
OOGalacticHyperspaceBehaviour value )

Definition at line 195 of file OOConstToJSString.h.

196{
197 return STRING_TO_JSVAL(OOJSStringFromGalacticHyperspaceBehaviour(context, value));
198}
OOINLINE JSString * OOJSStringFromGalacticHyperspaceBehaviour(JSContext *context, OOGalacticHyperspaceBehaviour value)

References OOJSStringFromGalacticHyperspaceBehaviour().

Referenced by PlayerShipGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromGUIScreenID()

OOINLINE jsval OOJSValueFromGUIScreenID ( JSContext * context,
OOGUIScreenID value )

Definition at line 160 of file OOConstToJSString.h.

161{
162 return STRING_TO_JSVAL(OOJSStringFromGUIScreenID(context, value));
163}
OOINLINE JSString * OOJSStringFromGUIScreenID(JSContext *context, OOGUIScreenID value)

References OOJSStringFromGUIScreenID().

Referenced by GlobalGetProperty(), and MissionGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromLegalStatusReason()

OOINLINE jsval OOJSValueFromLegalStatusReason ( JSContext * context,
OOLegalStatusReason value )

Definition at line 277 of file OOConstToJSString.h.

278{
279 return STRING_TO_JSVAL(OOJSStringFromLegalStatusReason(context, value));
280}
OOINLINE JSString * OOJSStringFromLegalStatusReason(JSContext *context, OOLegalStatusReason value)

References OOJSStringFromLegalStatusReason().

+ Here is the call graph for this function:

◆ OOJSValueFromScanClass()

OOINLINE jsval OOJSValueFromScanClass ( JSContext * context,
OOScanClass value )

Definition at line 92 of file OOConstToJSString.h.

93{
94 return STRING_TO_JSVAL(OOJSStringFromScanClass(context, value));
95}
OOINLINE JSString * OOJSStringFromScanClass(JSContext *context, OOScanClass value)

References OOJSStringFromScanClass().

Referenced by EntityGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSValueFromShipDamageType()

OOINLINE jsval OOJSValueFromShipDamageType ( JSContext * context,
OOShipDamageType value )

Definition at line 263 of file OOConstToJSString.h.

264{
265 return STRING_TO_JSVAL(OOJSStringFromShipDamageType(context, value));
266}
OOINLINE JSString * OOJSStringFromShipDamageType(JSContext *context, OOShipDamageType value)

References OOJSStringFromShipDamageType().

+ Here is the call graph for this function:

◆ OOJSValueFromViewID()

OOINLINE jsval OOJSValueFromViewID ( JSContext * context,
OOViewID value )

Definition at line 230 of file OOConstToJSString.h.

231{
232 return STRING_TO_JSVAL(OOJSStringFromViewID(context, value));
233}
OOINLINE JSString * OOJSStringFromViewID(JSContext *context, OOViewID value)

References OOJSStringFromViewID().

Referenced by PlayerShipGetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOScanClassFromJSString()

OOINLINE OOScanClass OOScanClassFromJSString ( JSContext * context,
JSString * string )

Definition at line 98 of file OOConstToJSString.h.

99{
102}
@ kOOScanClassDefault
Definition Entity.h:326
OOScanClass
Definition Entity.h:71

References gOOScanClassConstTable, kOOScanClassDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOScanClassFromJSValue()

OOINLINE OOScanClass OOScanClassFromJSValue ( JSContext * context,
jsval value )

Definition at line 105 of file OOConstToJSString.h.

References gOOScanClassConstTable, kOOScanClassDefault, and OOConstantFromJSValuePRIVATE().

Referenced by EntitySetProperty(), SystemCountEntitiesWithScanClass(), and SystemEntitiesWithScanClass().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOViewIDFromJSString()

OOINLINE OOViewID OOViewIDFromJSString ( JSContext * context,
JSString * string )

Definition at line 236 of file OOConstToJSString.h.

237{
238 extern struct ConstTable gOOViewIDConstTable;
240}
OOViewID
Definition OOTypes.h:43
@ kOOViewIDDefault
Definition OOTypes.h:46

References gOOViewIDConstTable, kOOViewIDDefault, and OOConstantFromJSStringPRIVATE().

+ Here is the call graph for this function:

◆ OOViewIDFromJSValue()

OOINLINE OOViewID OOViewIDFromJSValue ( JSContext * context,
jsval value )

Definition at line 243 of file OOConstToJSString.h.

244{
245 extern struct ConstTable gOOViewIDConstTable;
247}

References gOOViewIDConstTable, kOOViewIDDefault, and OOConstantFromJSValuePRIVATE().

+ Here is the call graph for this function: