Class for storing and passing simple sets of settings.
Inherits :
Inherited By : DzFileIOSettings, DzPaneSettings and DzPropertySettings
DAZ Script | |
---|---|
Type | { StringValue, IntValue, BoolValue, FloatValue, SettingsValue } |
DAZ Script |
---|
DzSettings () |
DzSettings ( DzSettings settings ) |
TODO: Add detailed description.
Enumerated types of the values stored in the DzSettings class.
Default constructor.
DzSettings( DzSettings settings )
Copy constructor.
Parameter(s):
void : clear()
Clears all values from this settings object.
void : copySetting( Number which, DzSettings copyTo )
Copies the setting with the given index to the specified settings object.
Parameter(s):
void : copySetting( String key, DzSettings copyTo )
Copies the setting with the given index to the specified settings object.
Parameter(s):
Boolean : fromString( String settings )
Populates this settings object with the data encoded in a string.
Parameter(s):
Return Value:
true
if the data was read successfully, otherwise false
.XML Syntax
If settings
consists of XML syntax, it is expected to contain an element tagged “Settings” at the root level; all other root level elements are ignored. This “Settings” element is expect to encapsulate child “Setting” tagged elements; all other child elements will be ignored. These “Setting” elements are expected to define “Key” and “Type” attributes. The “Key” attribute defines the named setting, and will depend on what this settings object is used for. The “Type” attribute should define a value of “Bool”, “Int”, “Float”, “String” or “SubSetting”; any non-recognized value will be interpreted as “String”. The text (or child elements in the case of “SubSetting”) of a “Setting” element defines the value of that setting.
Example:
var sSettings = [ '<Settings>', ' <Setting Type="Bool" Key="testBool">yes</Setting>', ' <Setting Type="Int" Key="testInt">123</Setting>', ' <Setting Type="Float" Key="testFloat">123.123</Setting>', ' <Setting Type="String" Key="testString">one two three</Setting>', ' <Setting Type="SubSetting" Key="testSettings">', ' <Setting Type="Bool" Key="testBool">no</Setting>', ' <Setting Type="Int" Key="testInt">456</Setting>', ' <Setting Type="Float" Key="testFloat">456.456</Setting>', ' <Setting Type="String" Key="testString">four five six</Setting>', ' </Setting>', '</Settings>' ].join( "\n" ); var oSettings = new DzSettings(); if( oSettings.fromString( sSettings ) ){ print( "Read of XML encoded data was successful." ); print( oSettings.getIntValue( "testInt" ) ); //123 var oSubSettings = oSettings.getSettingsValue( "testSettings" ); print( oSubSettings.getStringValue( "testString" ) ); //four five six } else { print( "Could not read XML encoded data." ); }
JSON Syntax
(since 4.8.1.23)
If settings
consists of JSON syntax, it is expected to contain an anonymous Object at the root level. This object is expected to define named members that will depend on the purpose of the settings object. These members serve as the keys for the values to be set. The value of a given member determines the type of setting that will be set.
The JSON format supports a single Number type, so a specific structure is used to produce a predictable result. Members that define a numeric value will set a float value on the settings object by default. Setting an integer value on the object is accomplished by defining a member as an Array of 2 values, where the first value is the string “i” and the second value is the integer value to be set. For the sake of continuity, the same structure can be used to indicate a float by substituting “i” with “f”.
Nested settings objects can be specified by defining a member as an Object that follows the structure of the root object.
For reasons of backward compatibility, the value of any member can be an object so long as that object contains a member named “type” whose value is one of “string”, “bool”, “int”, “float” or “setting”, and it also contains a member named “value” with the appropriate value.
Example:
var oData = { "testBool" : true, "testInt" : [ "i", 123 ], "testFloat" : 123.123, "testString" : "one two three", "testSettings" : { "type" : "settings", "value" : { "testBool" : false, "testInt" : [ "i", 456 ], "testFloat" : 456.456, "testString" : "four five six" } } }; //...
var oData = { "testBool" : true, "testInt" : [ "i", 123 ], "testFloat" : 123.123, "testString" : "one two three", "testSettings" : { "testBool" : false, "testInt" : [ "i", 456 ], "testFloat" : 456.456, "testString" : "four five six" } }; //...
var oData = { "testBool" : true, "testInt" : { "type" : "int", "value" : 123 }, "testFloat" : 123.123, "testString" : "one two three", "testSettings" : { "testBool" : false, "testInt" : [ "i", 456 ], "testFloat" : 456.456, "testString" : "four five six" } }; //...
//... var oSettings = new DzSettings(); if( oSettings.fromString( JSON.stringify( oData ) ) ){ print( "Read of JSON encoded data was successful." ); print( oSettings.getIntValue( "testInt" ) ); //123 var oSubSettings = oSettings.getSettingsValue( "testSettings" ); print( oSubSettings.getStringValue( "testString" ) ); //four five six } else { print( "Could not read JSON encoded data." ); }
See Also:
Boolean : getBoolValue( String key, Boolean def=false )
Gets a boolean value from the settings.
Parameter(s):
Return Value:
Number : getFloatValue( String key, Number def=0.0 )
Parameter(s):
Return Value:
Number : getIntValue( String key, Number def=0 )
Gets an integer value from the settings.
Parameter(s):
Return Value:
String : getKey( Number which )
Parameter(s):
Return Value:
Number : getNumValues()
Return Value:
Number : getSettingIndex( String key )
Parameter(s):
Return Value:
Attention:
DzSettings : getSettingsValue( String key )
Parameter(s):
Return Value:
key
is found and is a SettingsValue, otherwise NULL.String : getStringValue( String key, String def=“” )
Gets a string value from the settings.
Parameter(s):
Return Value:
String : getValue( Number which )
Parameter(s):
Return Value:
Type : getValueType( Number which )
Parameter(s):
Return Value:
Parameter(s):
Return Value:
void : removeValue( String key )
Removes a value.
Parameter(s):
void : replaceWithSettings( DzSettings settings )
Replaces the settings of this object with the settings of the specified object.
Parameter(s):
void : setBoolValue( String key, Boolean value )
Adds a boolean value.
Parameter(s):
void : setFloatValue( String key, Number value )
Adds a float value.
Parameter(s):
void : setIntValue( String key, Number value )
Adds an integer value.
Parameter(s):
DzSettings : setSettingsValue( String key, DzSettings settings )
Adds a nested settings value.
Parameter(s):
Return Value:
DzSettings : setSettingsValue( String key )
Adds a nested (empty) settings value.
Parameter(s):
Return Value:
void : setStringValue( String key, String value )
Adds a string value.
Parameter(s):
Return Value:
Example:
var oSettings = new DzSettings(); oSettings.setBoolValue( "testBool", true ); oSettings.setIntValue( "testInt", 123 ); oSettings.setFloatValue( "testFloat", 123.123 ); oSettings.setStringValue( "testString", "one two three" ); var oSubSettings = new DzSettings(); oSubSettings.setBoolValue( "testBool", false ); oSubSettings.setIntValue( "testInt", 456 ); oSubSettings.setFloatValue( "testFloat", 456.456 ); oSubSettings.setStringValue( "testString", "four five six" ); oSettings.setSettingsValue( "testSettings", oSubSettings ); var oJsonSettings = oSettings.toJson(); print( JSON.stringify( oJsonSettings ) ); print( oJsonSettings["testString"] ); //one two three var oJsonSubSettings = oJsonSettings["testSettings"]["value"]; print( oJsonSubSettings["testString"] ); //four five six
See Also:
Since:
String : toJsonString()
Return Value:
Example:
var oSettings = new DzSettings(); oSettings.setBoolValue( "testBool", true ); oSettings.setIntValue( "testInt", 123 ); oSettings.setFloatValue( "testFloat", 123.123 ); oSettings.setStringValue( "testString", "one two three" ); var oSubSettings = new DzSettings(); oSubSettings.setBoolValue( "testBool", false ); oSubSettings.setIntValue( "testInt", 456 ); oSubSettings.setFloatValue( "testFloat", 456.456 ); oSubSettings.setStringValue( "testString", "four five six" ); oSettings.setSettingsValue( "testSettings", oSubSettings ); print( oSettings.toJsonString() );
See Also:
Since:
void : toScript( String varName, DzScript script, Number indent, Boolean define=false )
Appends lines of code to a script object that will reconstruct this DzSettings object.
Parameter(s):
true
, prepends a variable definition statement to the lines generated in script
. If false
, it is the caller's responsibility to ensure that varName
is already defined in script
and holds a valid DzSettings object.Return Value:
Example:
var oSettings = new DzSettings(); oSettings.setBoolValue( "testBool", true ); oSettings.setIntValue( "testInt", 123 ); oSettings.setFloatValue( "testFloat", 123.123 ); oSettings.setStringValue( "testString", "one two three" ); var oSubSettings = new DzSettings(); oSubSettings.setBoolValue( "testBool", false ); oSubSettings.setIntValue( "testInt", 456 ); oSubSettings.setFloatValue( "testFloat", 456.456 ); oSubSettings.setStringValue( "testString", "four five six" ); oSettings.setSettingsValue( "testSettings", oSubSettings ); print( oSettings.toString() );