Structs |
Top Previous Next |
FreeFlyer script allows users to define Structs, which are collections of related FreeFlyer objects. Unlike Lists, Structs can contain many objects of different types. Structs can be passed as arguments into Procedures, effectively passing several related objects into the Procedure as a single argument. FreeFlyer Structs are also designed to allow users to easily import and export JSON data.
Defining a StructWhen working with Structs, the first step is to specify the Struct definition. This sets the type name for the Struct and the types and names of the member data held by the Struct. The general syntax for defining a Struct is:
A more specific syntax example is shown below. This example shows how to define a Struct called "SpacecraftWithMetaData" that contains an instance of a Spacecraft object, several Variable objects, and a String object. Structs can contain instances of any type of FreeFlyer object. Structs can also contain Lists of FreeFlyer objects.
You can define a Struct that will contain other types of Structs. The example below shows the definition for a "ConjunctionDataStruct" that will contain two instances of the "SpacecraftWithMetaData" Struct.
You can also define a Struct that derives off of another type of Struct, using the "extends" keyword. The example below shows how to define a "HighInterestConjunction" Struct that extends the "ConjunctionDataStruct" type.
You can also define Structs in a separate file, and include the file in your Mission Plan using the Include command or the "Externals" tab, similar to defining FreeFlyer Procedures in an external file.
Creating an Instance of a StructOnce you've defined a Struct type, you can create one or more instances of it. This is similar to creating any other type of object in FreeFlyer script. The example below shows how to create two instances of the "SpacecraftWithMetaData" Struct defined above:
You can also create a List of instances of a Struct. After creating the List, simply set the List.Count as usual:
Working with Struct InstancesAfter creating one or more instances of your Struct type, you can access the various objects contained within the Struct, just like working with other types of objects that are built-in to FreeFlyer. Some syntax examples are shown below:
You can use the assignment operator (=) to assign two instances of the same type of Struct, so long as all the object types contained within the Struct are assignable.
You can also use reference assignment (the := operator) to configure an object contained within a Struct to refer to another object that you created separately. This will cause any references to that Struct element to refer to the specified object. The example below demonstrates using reference assignment with a Spacecraft contained in a Struct:
Working with JSON DataFreeFlyer Structs are designed to allow users to easily import and export JSON data. JSON, or JavaScript Object Notation, is a data file format that contains attribute-value pairs. You can specify annotations (using the @ symbol) for individual objects contained in a Struct to indicate how that object's data should be handled when serializing to JSON format, or deserializing from JSON format. For more information on working with JSON data in FreeFlyer, see the JSON-Formatted Data page.
For an example of using Structs to import JSON Data, see the Close Approach Maneuver Sample Mission Plan.
See Also•JSON-Formatted Data page in the Interfacing with External Resources Guide •Using Procedures Guide •Struct script element •Include Command •Script Operators Guide •Lists page
|