2002-03-23 00:29:21 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
Header: FGPropertyManager.h
|
|
|
|
Author: Tony Peden
|
|
|
|
Based on work originally by David Megginson
|
|
|
|
Date: 2/2002
|
|
|
|
|
|
|
|
------------- Copyright (C) 2002 -------------
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
Further information about the GNU General Public License can also be found on
|
|
|
|
the world wide web at http://www.gnu.org.
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
SENTRY
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
#ifndef FGPROPERTYMANAGER_H
|
|
|
|
#define FGPROPERTYMANAGER_H
|
|
|
|
|
2002-03-23 00:29:21 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
INCLUDES
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
2002-09-22 15:31:09 +00:00
|
|
|
#include <string>
|
2002-03-20 14:06:14 +00:00
|
|
|
#include <simgear/misc/props.hxx>
|
|
|
|
|
2002-03-23 00:29:21 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
DEFINITIONS
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
|
|
|
#define ID_PROPERTYMANAGER "$Id$"
|
|
|
|
|
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
FORWARD DECLARATIONS
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
2002-03-20 14:06:14 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2002-03-23 00:29:21 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
CLASS DOCUMENTATION
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
|
|
|
/** Class wrapper for property handling.
|
|
|
|
@author David Megginson, Tony Peden
|
|
|
|
@see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGPropertyManager.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
|
|
|
|
Header File </a>
|
2002-04-06 16:03:16 +00:00
|
|
|
@see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGPropertyManager.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
|
|
|
|
Source File </a>
|
2002-03-23 00:29:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
CLASS DECLARATION
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
|
|
|
|
2002-09-22 15:31:09 +00:00
|
|
|
class FGPropertyManager : public SGPropertyNode {
|
2002-03-20 14:06:14 +00:00
|
|
|
public:
|
2002-03-23 00:29:21 +00:00
|
|
|
/// Constructor
|
2002-09-22 15:31:09 +00:00
|
|
|
FGPropertyManager(void) {}
|
2002-03-23 00:29:21 +00:00
|
|
|
/// Destructor
|
2002-09-22 15:31:09 +00:00
|
|
|
~FGPropertyManager(void) {}
|
|
|
|
|
|
|
|
/** Property-ify a name
|
|
|
|
* replaces spaces with '-' and, optionally, makes name all lower case
|
|
|
|
* @param name string to change
|
|
|
|
* @param lowercase true to change all upper case chars to lower
|
|
|
|
* NOTE: this function changes its argument and thus relies
|
|
|
|
* on pass by value
|
|
|
|
*/
|
|
|
|
string mkPropertyName(string name, bool lowercase);
|
|
|
|
|
2002-03-20 14:06:14 +00:00
|
|
|
/**
|
|
|
|
* Get a property node.
|
|
|
|
*
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
|
|
|
* @return The node, or 0 if none exists and none was created.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
FGPropertyManager*
|
|
|
|
GetNode (const string &path, bool create = false);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
2002-09-22 15:31:09 +00:00
|
|
|
FGPropertyManager*
|
|
|
|
GetNode (const string &relpath, int index, bool create = false);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether a given node exists.
|
|
|
|
*
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
* @return true if the node exists, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool HasNode (const string &path);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
2002-04-06 16:03:16 +00:00
|
|
|
/**
|
|
|
|
* Get the name of a node
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
string GetName( void );
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getBoolValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as a bool, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool GetBool (const string &name, bool defaultValue = false);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getIntValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as an int, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
int GetInt (const string &name, int defaultValue = 0);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getLongValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as a long, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
int GetLong (const string &name, long defaultValue = 0L);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getFloatValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as a float, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
float GetFloat (const string &name, float defaultValue = 0.0);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getDoubleValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as a double, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
double GetDouble (const string &name, double defaultValue = 0.0);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 GetNode and then
|
|
|
|
* use the node's getStringValue() method, to avoid the lookup overhead.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
* does not exist.
|
|
|
|
* @return The property's value as a string, or the default value provided.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
string GetString (const string &name, string defaultValue = "");
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetBool (const string &name, bool val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetInt (const string &name, int val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetLong (const string &name, long val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetFloat (const string &name, float val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetDouble (const string &name, double val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param val The new value for the property.
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
bool SetString (const string &name, const string &val);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convenience functions for setting property attributes.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param state The state of the archive attribute (defaults to true).
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void SetArchivable (const string &name, bool state = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param state The state of the read attribute (defaults to true).
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void SetReadable (const string &name, bool state = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param name The property name.
|
|
|
|
* @param state The state of the write attribute (defaults to true).
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void SetWritable (const string &name, bool state = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convenience functions for tying properties, with logging.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Untie a property from an external data source.
|
|
|
|
*
|
|
|
|
* Classes should use this function to release control of any
|
|
|
|
* properties they are managing.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void Untie (const string &name);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Templates cause ambiguity here
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to an external bool variable.
|
|
|
|
*
|
|
|
|
* The property's value will automatically mirror the variable's
|
|
|
|
* value, and vice-versa, until the property is untied.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param pointer A pointer to the variable.
|
|
|
|
* @param useDefault true if any existing property value should be
|
|
|
|
* copied to the variable; false if the variable should not
|
|
|
|
* be modified; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void
|
|
|
|
Tie (const string &name, bool *pointer, bool useDefault = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to an external int variable.
|
|
|
|
*
|
|
|
|
* The property's value will automatically mirror the variable's
|
|
|
|
* value, and vice-versa, until the property is untied.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param pointer A pointer to the variable.
|
|
|
|
* @param useDefault true if any existing property value should be
|
|
|
|
* copied to the variable; false if the variable should not
|
|
|
|
* be modified; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void
|
|
|
|
Tie (const string &name, int *pointer, bool useDefault = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to an external long variable.
|
|
|
|
*
|
|
|
|
* The property's value will automatically mirror the variable's
|
|
|
|
* value, and vice-versa, until the property is untied.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param pointer A pointer to the variable.
|
|
|
|
* @param useDefault true if any existing property value should be
|
|
|
|
* copied to the variable; false if the variable should not
|
|
|
|
* be modified; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void
|
|
|
|
Tie (const string &name, long *pointer, bool useDefault = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to an external float variable.
|
|
|
|
*
|
|
|
|
* The property's value will automatically mirror the variable's
|
|
|
|
* value, and vice-versa, until the property is untied.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param pointer A pointer to the variable.
|
|
|
|
* @param useDefault true if any existing property value should be
|
|
|
|
* copied to the variable; false if the variable should not
|
|
|
|
* be modified; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void
|
|
|
|
Tie (const string &name, float *pointer, bool useDefault = true);
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to an external double variable.
|
|
|
|
*
|
|
|
|
* The property's value will automatically mirror the variable's
|
|
|
|
* value, and vice-versa, until the property is untied.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param pointer A pointer to the variable.
|
|
|
|
* @param useDefault true if any existing property value should be
|
|
|
|
* copied to the variable; false if the variable should not
|
|
|
|
* be modified; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
void
|
|
|
|
Tie (const string &name, double *pointer, bool useDefault = true);
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// All of the following functions *must* be inlined, otherwise linker
|
|
|
|
// errors will result
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2002-03-20 14:06:14 +00:00
|
|
|
/* template <class V> void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, V (*getter)(), void (*setter)(V) = 0,
|
2002-03-20 14:06:14 +00:00
|
|
|
bool useDefault = true);
|
|
|
|
|
|
|
|
template <class V> void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, int index, V (*getter)(int),
|
2002-03-20 14:06:14 +00:00
|
|
|
void (*setter)(int, V) = 0, bool useDefault = true);
|
|
|
|
|
|
|
|
template <class T, class V> void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, T * obj, V (T::*getter)() const,
|
2002-03-20 14:06:14 +00:00
|
|
|
void (T::*setter)(V) = 0, bool useDefault = true);
|
|
|
|
|
|
|
|
template <class T, class V> void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, T * obj, int index,
|
2002-03-20 14:06:14 +00:00
|
|
|
V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
|
|
|
|
bool useDefault = true); */
|
|
|
|
|
2002-09-22 15:31:09 +00:00
|
|
|
/**
|
2002-03-20 14:06:14 +00:00
|
|
|
* Tie a property to a pair of simple functions.
|
|
|
|
*
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
* be invoked; every time the property value is modified, the setter
|
|
|
|
* (if any) will be invoked. The getter can be 0 to make the property
|
|
|
|
* unreadable, and the setter can be 0 to make the property
|
|
|
|
* unmodifiable.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param getter The getter function, or 0 if the value is unreadable.
|
|
|
|
* @param setter The setter function, or 0 if the value is unmodifiable.
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
* discarded; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
|
|
|
|
template <class V> inline void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, V (*getter)(), void (*setter)(V) = 0,
|
2002-09-22 15:31:09 +00:00
|
|
|
bool useDefault = true)
|
2002-03-20 14:06:14 +00:00
|
|
|
{
|
|
|
|
if (!tie(name.c_str(), SGRawValueFunctions<V>(getter, setter),
|
|
|
|
useDefault))
|
|
|
|
cout <<
|
2002-04-30 13:42:26 +00:00
|
|
|
"Failed to tie property " << name << " to functions" << endl;
|
2002-03-20 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to a pair of indexed functions.
|
|
|
|
*
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
* be invoked with the index provided; every time the property value
|
|
|
|
* is modified, the setter (if any) will be invoked with the index
|
|
|
|
* provided. The getter can be 0 to make the property unreadable, and
|
|
|
|
* the setter can be 0 to make the property unmodifiable.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param index The integer argument to pass to the getter and
|
|
|
|
* setter functions.
|
|
|
|
* @param getter The getter function, or 0 if the value is unreadable.
|
|
|
|
* @param setter The setter function, or 0 if the value is unmodifiable.
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
* discarded; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
template <class V> inline void Tie (const string &name,
|
|
|
|
int index, V (*getter)(int),
|
2002-03-20 14:06:14 +00:00
|
|
|
void (*setter)(int, V) = 0, bool useDefault = true)
|
|
|
|
{
|
|
|
|
if (!tie(name.c_str(),
|
|
|
|
SGRawValueFunctionsIndexed<V>(index,
|
|
|
|
getter,
|
|
|
|
setter),
|
|
|
|
useDefault))
|
|
|
|
cout <<
|
2002-04-30 13:42:26 +00:00
|
|
|
"Failed to tie property " << name << " to indexed functions" << endl;
|
2002-03-20 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a property to a pair of object methods.
|
|
|
|
*
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
* be invoked; every time the property value is modified, the setter
|
|
|
|
* (if any) will be invoked. The getter can be 0 to make the property
|
|
|
|
* unreadable, and the setter can be 0 to make the property
|
|
|
|
* unmodifiable.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param obj The object whose methods should be invoked.
|
|
|
|
* @param getter The object's getter method, or 0 if the value is
|
|
|
|
* unreadable.
|
|
|
|
* @param setter The object's setter method, or 0 if the value is
|
|
|
|
* unmodifiable.
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
* discarded; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
template <class T, class V> inline void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, T * obj, V (T::*getter)() const,
|
2002-03-20 14:06:14 +00:00
|
|
|
void (T::*setter)(V) = 0, bool useDefault = true)
|
|
|
|
{
|
|
|
|
if (!tie(name.c_str(),
|
2002-09-22 15:31:09 +00:00
|
|
|
SGRawValueMethods<T,V>(*obj, getter, setter),
|
|
|
|
useDefault))
|
2002-03-20 14:06:14 +00:00
|
|
|
cout <<
|
2002-09-22 15:31:09 +00:00
|
|
|
"Failed to tie property " << name << " to object methods" << endl;
|
2002-03-20 14:06:14 +00:00
|
|
|
}
|
2002-09-22 15:31:09 +00:00
|
|
|
|
2002-03-20 14:06:14 +00:00
|
|
|
/**
|
|
|
|
* Tie a property to a pair of indexed object methods.
|
|
|
|
*
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
* be invoked with the index provided; every time the property value
|
|
|
|
* is modified, the setter (if any) will be invoked with the index
|
|
|
|
* provided. The getter can be 0 to make the property unreadable, and
|
|
|
|
* the setter can be 0 to make the property unmodifiable.
|
|
|
|
*
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
* @param obj The object whose methods should be invoked.
|
|
|
|
* @param index The integer argument to pass to the getter and
|
|
|
|
* setter methods.
|
|
|
|
* @param getter The getter method, or 0 if the value is unreadable.
|
|
|
|
* @param setter The setter method, or 0 if the value is unmodifiable.
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
* discarded; defaults to true.
|
|
|
|
*/
|
2002-09-22 15:31:09 +00:00
|
|
|
template <class T, class V> inline void
|
2002-03-23 00:29:21 +00:00
|
|
|
Tie (const string &name, T * obj, int index,
|
2002-03-20 14:06:14 +00:00
|
|
|
V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
|
2002-09-22 15:31:09 +00:00
|
|
|
bool useDefault = true)
|
2002-03-20 14:06:14 +00:00
|
|
|
{
|
|
|
|
if (!tie(name.c_str(),
|
2002-09-22 15:31:09 +00:00
|
|
|
SGRawValueMethodsIndexed<T,V>(*obj,
|
|
|
|
index,
|
|
|
|
getter,
|
|
|
|
setter),
|
|
|
|
useDefault))
|
2002-03-20 14:06:14 +00:00
|
|
|
cout <<
|
2002-09-22 15:31:09 +00:00
|
|
|
"Failed to tie property " << name << " to indexed object methods" << endl;
|
|
|
|
}
|
|
|
|
};
|
2002-03-20 14:06:14 +00:00
|
|
|
|
|
|
|
#endif // FGPROPERTYMANAGER_H
|
|
|
|
|