FlightGear next
fg_props.cxx File Reference
#include "config.h"
#include <simgear/compiler.h>
#include <simgear/structure/exception.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/misc/strutils.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/particles.hxx>
#include <simgear/sound/soundmgr.hxx>
#include <GUI/gui.h>
#include "globals.hxx"
#include "fg_props.hxx"

Go to the source code of this file.

Functions

static const char * getLoggingClasses ()
 
void setLoggingClasses (const char *c)
 Set the logging classes.
 
static const char * getLoggingPriority ()
 Get the logging priority.
 
void setLoggingPriority (const char *p)
 Set the logging priority.
 
static double getElapsedTime_sec ()
 Return the number of milliseconds elapsed since simulation started.
 
static const char * getDateString ()
 Return the current Zulu time.
 
static void setDateString (const char *date_string)
 Set the current Zulu time.
 
static const char * getGMTString ()
 Return the GMT as a string.
 
static SGPropertyNode_ptr initDoubleNode (const std::string &path, const double v)
 
bool fgSaveFlight (std::ostream &output, bool write_all)
 Save the current state of the simulator to a stream.
 
bool fgLoadFlight (std::istream &input)
 Restore the current state of the simulator from a stream.
 
bool fgLoadProps (const std::string &path, SGPropertyNode *props, bool in_fg_root, int default_mode)
 Load properties from a file.
 
SGPropertyNode * fgGetNode (const char *path, bool create)
 Get a property node.
 
SGPropertyNode * fgGetNode (const char *path, int index, bool create)
 Get a property node with separate index.
 
bool fgHasNode (const char *path)
 Test whether a given node exists.
 
void fgAddChangeListener (SGPropertyChangeListener *listener, const char *path)
 Add a listener to a node.
 
void fgAddChangeListener (SGPropertyChangeListener *listener, const char *path, int index)
 Add a listener to a node.
 
bool fgGetBool (const char *name, bool defaultValue)
 Get a bool value for a property.
 
int fgGetInt (const char *name, int defaultValue)
 Get an int value for a property.
 
long fgGetLong (const char *name, long defaultValue)
 Get a long value for a property.
 
float fgGetFloat (const char *name, float defaultValue)
 Get a float value for a property.
 
double fgGetDouble (const char *name, double defaultValue)
 Get a double value for a property.
 
std::string fgGetString (const char *name, const char *defaultValue)
 Get a string value for a property.
 
bool fgSetBool (const char *name, bool val)
 Set a bool value for a property.
 
bool fgSetInt (const char *name, int val)
 Set an int value for a property.
 
bool fgSetLong (const char *name, long val)
 Set a long value for a property.
 
bool fgSetFloat (const char *name, float val)
 Set a float value for a property.
 
bool fgSetDouble (const char *name, double val)
 Set a double value for a property.
 
bool fgSetString (const char *name, const char *val)
 Set a string value for a property.
 
void fgSetArchivable (const char *name, bool state)
 Set the state of the archive attribute for a property.
 
void fgSetReadable (const char *name, bool state)
 Set the state of the read attribute for a property.
 
void fgSetWritable (const char *name, bool state)
 Set the state of the write attribute for a property.
 
void fgUntie (const char *name)
 Untie a property from an external data source.
 
void fgUntieIfDefined (const std::string &name)
 @brfief variant of the above which doesn't warn if the property does not exist
 

Variables

SGSubsystemMgr::Registrant< FGPropertiesregistrantFGProperties
 

Function Documentation

◆ fgAddChangeListener() [1/2]

void fgAddChangeListener ( SGPropertyChangeListener * listener,
const char * path )

Add a listener to a node.

Parameters
listenerThe listener to add to the node.
pathThe path of the node, relative to root.
indexThe index for the last member of the path (overrides any given in the string).

Definition at line 513 of file fg_props.cxx.

◆ fgAddChangeListener() [2/2]

void fgAddChangeListener ( SGPropertyChangeListener * listener,
const char * path,
int index )

Add a listener to a node.

Parameters
listenerThe listener to add to the node.
pathThe path of the node, relative to root.
indexThe index for the last member of the path (overrides any given in the string).

Definition at line 519 of file fg_props.cxx.

◆ fgGetBool()

bool fgGetBool ( const char * name,
bool defaultValue = false )

Get a bool value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getBoolValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as a bool, or the default value provided.

Definition at line 526 of file fg_props.cxx.

◆ fgGetDouble()

double fgGetDouble ( const char * name,
double defaultValue = 0.0 )

Get a double value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getDoubleValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as a double, or the default value provided.

Definition at line 550 of file fg_props.cxx.

◆ fgGetFloat()

float fgGetFloat ( const char * name,
float defaultValue = 0.0 )

Get a float value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getFloatValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as a float, or the default value provided.

Definition at line 544 of file fg_props.cxx.

◆ fgGetInt()

int fgGetInt ( const char * name,
int defaultValue = 0 )

Get an int value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getIntValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as an int, or the default value provided.

Definition at line 532 of file fg_props.cxx.

◆ fgGetLong()

long fgGetLong ( const char * name,
long defaultValue = 0L )

Get a long value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getLongValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as a long, or the default value provided.

Definition at line 538 of file fg_props.cxx.

◆ fgGetNode() [1/2]

SGPropertyNode * fgGetNode ( const char * path,
bool create = false )

Get a property node.

Parameters
pathThe path of the node, relative to root.
createtrue to create the node if it doesn't exist.
Returns
The node, or 0 if none exists and none was created.

Definition at line 495 of file fg_props.cxx.

◆ fgGetNode() [2/2]

SGPropertyNode * fgGetNode ( const char * path,
int index,
bool create = false )

Get a property node with separate index.

This method separates the index from the path string, to make it easier to iterate through multiple components without using sprintf to add indices. For example, fgGetNode("foo[1]/bar", 3) will return the same result as fgGetNode("foo[1]/bar[3]").

Parameters
pathThe path of the node, relative to root.
indexThe index for the last member of the path (overrides any given in the string).
createtrue to create the node if it doesn't exist.
Returns
The node, or 0 if none exists and none was created.

Definition at line 501 of file fg_props.cxx.

◆ fgGetString()

std::string fgGetString ( const char * name,
const char * defaultValue = "" )

Get a string value for a property.

This method is convenient but inefficient. It should be used infrequently (i.e. for initializing, loading, saving, etc.), not in the main loop. If you need to get a value frequently, it is better to look up the node itself using fgGetNode and then use the node's getStringValue() method, to avoid the lookup overhead.

Parameters
nameThe property name.
defaultValueThe default value to return if the property does not exist.
Returns
The property's value as a string, or the default value provided.

Definition at line 556 of file fg_props.cxx.

◆ fgHasNode()

bool fgHasNode ( const char * path)

Test whether a given node exists.

Parameters
pathThe path of the node, relative to root.
Returns
true if the node exists, false otherwise.

Definition at line 507 of file fg_props.cxx.

◆ fgLoadFlight()

bool fgLoadFlight ( std::istream & input)

Restore the current state of the simulator from a stream.

Load a flight from disk.

Definition at line 448 of file fg_props.cxx.

◆ fgLoadProps()

bool fgLoadProps ( const std::string & path,
SGPropertyNode * props,
bool in_fg_root = true,
int default_mode = 0 )

Load properties from a file.

Parameters
fileThe relative or absolute filename.
propsThe property node to load the properties into.
in_fg_rootIf true, look for the file relative to $FG_ROOT; otherwise, look for the file relative to the current working directory.
Returns
true if the properties loaded successfully, false otherwise.

Definition at line 469 of file fg_props.cxx.

◆ fgSaveFlight()

bool fgSaveFlight ( std::ostream & output,
bool write_all )

Save the current state of the simulator to a stream.

Save a flight to disk.

Definition at line 424 of file fg_props.cxx.

◆ fgSetArchivable()

void fgSetArchivable ( const char * name,
bool state = true )

Set the state of the archive attribute for a property.

If the archive attribute is true, the property will be written when a flight is saved; if it is false, the property will be skipped.

A warning message will be printed if the property does not exist.

Parameters
nameThe property name.
stateThe state of the archive attribute (defaults to true).

Definition at line 598 of file fg_props.cxx.

◆ fgSetBool()

bool fgSetBool ( const char * name,
bool val )

Set a bool value for a property.

Assign a bool value to a property. If the property does not yet exist, it will be created and its type will be set to BOOL; if it has a type of UNKNOWN, the type will also be set to BOOL; otherwise, the bool value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 562 of file fg_props.cxx.

◆ fgSetDouble()

bool fgSetDouble ( const char * name,
double val )

Set a double value for a property.

Assign a double value to a property. If the property does not yet exist, it will be created and its type will be set to DOUBLE; if it has a type of UNKNOWN, the type will also be set to DOUBLE; otherwise, the double value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 586 of file fg_props.cxx.

◆ fgSetFloat()

bool fgSetFloat ( const char * name,
float val )

Set a float value for a property.

Assign a float value to a property. If the property does not yet exist, it will be created and its type will be set to FLOAT; if it has a type of UNKNOWN, the type will also be set to FLOAT; otherwise, the bool value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 580 of file fg_props.cxx.

◆ fgSetInt()

bool fgSetInt ( const char * name,
int val )

Set an int value for a property.

Assign an int value to a property. If the property does not yet exist, it will be created and its type will be set to INT; if it has a type of UNKNOWN, the type will also be set to INT; otherwise, the bool value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 568 of file fg_props.cxx.

◆ fgSetLong()

bool fgSetLong ( const char * name,
long val )

Set a long value for a property.

Assign a long value to a property. If the property does not yet exist, it will be created and its type will be set to LONG; if it has a type of UNKNOWN, the type will also be set to LONG; otherwise, the bool value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 574 of file fg_props.cxx.

◆ fgSetReadable()

void fgSetReadable ( const char * name,
bool state = true )

Set the state of the read attribute for a property.

If the read attribute is true, the property value will be readable; if it is false, the property value will always be the default value for its type.

A warning message will be printed if the property does not exist.

Parameters
nameThe property name.
stateThe state of the read attribute (defaults to true).

Definition at line 610 of file fg_props.cxx.

◆ fgSetString()

bool fgSetString ( const char * name,
const char * val )

Set a string value for a property.

Assign a string value to a property. If the property does not yet exist, it will be created and its type will be set to STRING; if it has a type of UNKNOWN, the type will also be set to STRING; otherwise, the string value will be converted to the property's type.

Parameters
nameThe property name.
valThe new value for the property.
Returns
true if the assignment succeeded, false otherwise.

Definition at line 592 of file fg_props.cxx.

◆ fgSetWritable()

void fgSetWritable ( const char * name,
bool state = true )

Set the state of the write attribute for a property.

If the write attribute is true, the property value may be modified (depending on how it is tied); if the write attribute is false, the property value may not be modified.

A warning message will be printed if the property does not exist.

Parameters
nameThe property name.
stateThe state of the write attribute (defaults to true).

Definition at line 622 of file fg_props.cxx.

◆ fgUntie()

void fgUntie ( const char * name)

Untie a property from an external data source.

Classes should use this function to release control of any properties they are managing.

Definition at line 634 of file fg_props.cxx.

◆ fgUntieIfDefined()

void fgUntieIfDefined ( const std::string & name)

@brfief variant of the above which doesn't warn if the property does not exist

Definition at line 651 of file fg_props.cxx.

◆ getDateString()

static const char * getDateString ( )
static

Return the current Zulu time.

Definition at line 161 of file fg_props.cxx.

◆ getElapsedTime_sec()

static double getElapsedTime_sec ( )
static

Return the number of milliseconds elapsed since simulation started.

Definition at line 151 of file fg_props.cxx.

◆ getGMTString()

static const char * getGMTString ( )
static

Return the GMT as a string.

Definition at line 223 of file fg_props.cxx.

◆ getLoggingClasses()

static const char * getLoggingClasses ( )
static

Definition at line 55 of file fg_props.cxx.

◆ getLoggingPriority()

static const char * getLoggingPriority ( )
static

Get the logging priority.

Definition at line 74 of file fg_props.cxx.

◆ initDoubleNode()

static SGPropertyNode_ptr initDoubleNode ( const std::string & path,
const double v )
static

Definition at line 288 of file fg_props.cxx.

◆ setDateString()

static void setDateString ( const char * date_string)
static

Set the current Zulu time.

Definition at line 183 of file fg_props.cxx.

◆ setLoggingClasses()

void setLoggingClasses ( const char * c)

Set the logging classes.

Definition at line 65 of file fg_props.cxx.

◆ setLoggingPriority()

void setLoggingPriority ( const char * p)

Set the logging priority.

Definition at line 100 of file fg_props.cxx.

Variable Documentation

◆ registrantFGProperties

SGSubsystemMgr::Registrant<FGProperties> registrantFGProperties

Definition at line 413 of file fg_props.cxx.