KSP API
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
ConfigNode Class Reference

A ConfigNode represents a collection of data that can be serialized to or deserialized from a file. A ConfigNode contains a set of values, and optionally one or more ConfigNodes, so they can be used recursively. More...

Classes

class  ConfigNodeList
 
class  Value
 
class  ValueList
 

Public Member Functions

 ConfigNode ()
 
 ConfigNode (string name)
 
ConfigNode AddNode (string name)
 Add a sub-ConfigNode with a given name to this node. More...
 
void AddValue (string name, object value)
 Add a new piece of data to this ConfigNode. Values show up in serialized ConfigNodes as lines of the form More...
 
void AddValue (string name, string value)
 Add a new piece of data to this ConfigNode. Values show up in serialized ConfigNodes as lines of the form More...
 
void ClearData ()
 Remove all nodes and values? More...
 
void ClearNodes ()
 Remove all sub-ConfigNodes from this ConfigNode? More...
 
void ClearValues ()
 Remove all values from this ConfigNode? More...
 
void CopyTo (ConfigNode node)
 Copies the contents of this node into a different ConfigNode More...
 
ConfigNode GetNode (string name)
 
ConfigNode[] GetNodes (string name)
 
string GetValue (string name)
 
string[] GetValues (string name)
 
bool HasNode ()
 
bool HasNode (string name)
 
bool HasValue ()
 
bool HasValue (string name)
 
bool Save (string fileFullName)
 Seralize this ConfigNode to a file. More...
 
bool Save (string fileFullName, string header)
 
bool SetNode (string name, ConfigNode newNode)
 
bool SetNode (string name, ConfigNode newNode, int index)
 
bool SetValue (string name, string newValue)
 
bool SetValue (string name, string newValue, int index)
 
override string ToString ()
 Seralizes this ConfigNode to a string. More...
 

Static Public Member Functions

static ConfigNode CreateConfigFromObject (object obj)
 Create a ConfigNode from a given object. This function will use reflection to scan the given object looking for fields with the [Persistent] attribute. When it finds such a field it adds it as a name-value pair to the returned ConfigNode. The name wil be the name of the field, and the value will the the serialized version of the field's data. More...
 
static ConfigNode CreateConfigFromObject (object obj, int pass)
 Like CreateConfigFromObject, but only pays attention to fields with the "pass" field of the [Persistent] attribute set to pass. More...
 
static object CreateObjectFromConfig (ConfigNode node)
 
static T CreateObjectFromConfig< T > (ConfigNode node)
 
static object CreateObjectFromConfig (string typeName, ConfigNode node)
 
static ConfigNode Load (string fileFullName)
 
static bool LoadObjectFromConfig (object obj, ConfigNode node)
 Initialize an existing object using data from the ConfigNode. This method will scan the object looking for fields with the [Persistent] attribute. When it finds such a field, it looks in the ConfigNode for a matching name-value pair, and then parses the value and sets the field to the result. More...
 
static bool LoadObjectFromConfig (object obj, ConfigNode node, int pass)
 Like LoadObjectFromConfig, but only pays attention to fields for which the "pass" field of the [Persistent] attribute is equal to pass. More...
 
static Color ParseColor (string vectorString)
 
static Color32 ParseColor32 (string vectorString)
 
static Enum ParseEnum (Type enumType, string vectorString)
 
static Matrix4x4 ParseMatrix4x4 (string quaternionString)
 
static Quaternion ParseQuaternion (string quaternionString)
 
static QuaternionD ParseQuaternionD (string quaternionString)
 
static Vector3 ParseVector2 (string vectorString)
 
static Vector3 ParseVector3 (string vectorString)
 
static Vector3d ParseVector3D (string vectorString)
 
static Vector4 ParseVector4 (string vectorString)
 
static string WriteColor (Color color)
 
static string WriteColor (Color32 color)
 
static string WriteEnum (Enum en)
 
static string WriteMatrix4x4 (Matrix4x4 matrix)
 
static string WriteQuaternion (Quaternion quaternion)
 
static string WriteQuaternion (QuaternionD quaternion)
 
static string WriteVector (Vector2 vector)
 
static string WriteVector (Vector3 vector)
 
static string WriteVector (Vector3d vector)
 
static string WriteVector (Vector4 vector)
 

Public Attributes

const string configTabIndent = @" "
 
string name
 

Properties

int CountNodes [get]
 
int CountValues [get]
 
bool HasData [get]
 
ConfigNode.ConfigNodeList nodes [get]
 
ConfigNode.ValueList values [get]
 

Detailed Description

A ConfigNode represents a collection of data that can be serialized to or deserialized from a file. A ConfigNode contains a set of values, and optionally one or more ConfigNodes, so they can be used recursively.

Constructor & Destructor Documentation

ConfigNode.ConfigNode ( )
ConfigNode.ConfigNode ( string  name)

Member Function Documentation

ConfigNode ConfigNode.AddNode ( string  name)

Add a sub-ConfigNode with a given name to this node.

Parameters
nameThe name of the new node
Returns
The newly created sub-ConfigNode
void ConfigNode.AddValue ( string  name,
object  value 
)

Add a new piece of data to this ConfigNode. Values show up in serialized ConfigNodes as lines of the form

name = value

Parameters
nameThe name of the new value.
valueThe data to store.
void ConfigNode.AddValue ( string  name,
string  value 
)

Add a new piece of data to this ConfigNode. Values show up in serialized ConfigNodes as lines of the form

name = value

Parameters
nameThe name of the new value.
valueThe data to store.
void ConfigNode.ClearData ( )

Remove all nodes and values?

void ConfigNode.ClearNodes ( )

Remove all sub-ConfigNodes from this ConfigNode?

void ConfigNode.ClearValues ( )

Remove all values from this ConfigNode?

void ConfigNode.CopyTo ( ConfigNode  node)

Copies the contents of this node into a different ConfigNode

Parameters
nodeThe ConfigNode to copy this one into.
static ConfigNode ConfigNode.CreateConfigFromObject ( object  obj)
static

Create a ConfigNode from a given object. This function will use reflection to scan the given object looking for fields with the [Persistent] attribute. When it finds such a field it adds it as a name-value pair to the returned ConfigNode. The name wil be the name of the field, and the value will the the serialized version of the field's data.

Parameters
objThe object to scan to create a ConfigNode
Returns
A ConfigNode containing the persistent fields of the object.
static ConfigNode ConfigNode.CreateConfigFromObject ( object  obj,
int  pass 
)
static

Like CreateConfigFromObject, but only pays attention to fields with the "pass" field of the [Persistent] attribute set to pass.

Parameters
objThe object to scan to create a ConfigNode.
passA flag indicate which fields to serialize.
Returns
A ConfigNode containing the desired persistent fields of the object.
static object ConfigNode.CreateObjectFromConfig ( ConfigNode  node)
static
static object ConfigNode.CreateObjectFromConfig ( string  typeName,
ConfigNode  node 
)
static
static T ConfigNode.CreateObjectFromConfig< T > ( ConfigNode  node)
static
ConfigNode ConfigNode.GetNode ( string  name)
ConfigNode [] ConfigNode.GetNodes ( string  name)
string ConfigNode.GetValue ( string  name)
string [] ConfigNode.GetValues ( string  name)
bool ConfigNode.HasNode ( )
bool ConfigNode.HasNode ( string  name)
bool ConfigNode.HasValue ( )
bool ConfigNode.HasValue ( string  name)
static ConfigNode ConfigNode.Load ( string  fileFullName)
static
static bool ConfigNode.LoadObjectFromConfig ( object  obj,
ConfigNode  node 
)
static

Initialize an existing object using data from the ConfigNode. This method will scan the object looking for fields with the [Persistent] attribute. When it finds such a field, it looks in the ConfigNode for a matching name-value pair, and then parses the value and sets the field to the result.

Parameters
objThe object to initialize
nodeThe ConfigNode used to initialize the object.
Returns
static bool ConfigNode.LoadObjectFromConfig ( object  obj,
ConfigNode  node,
int  pass 
)
static

Like LoadObjectFromConfig, but only pays attention to fields for which the "pass" field of the [Persistent] attribute is equal to pass.

Parameters
objThe object to initialize
nodeThe ConfigNode used to initialize the object.
passA flag indicating which fields to initialize.
Returns
static Color ConfigNode.ParseColor ( string  vectorString)
static
static Color32 ConfigNode.ParseColor32 ( string  vectorString)
static
static Enum ConfigNode.ParseEnum ( Type  enumType,
string  vectorString 
)
static
static Matrix4x4 ConfigNode.ParseMatrix4x4 ( string  quaternionString)
static
static Quaternion ConfigNode.ParseQuaternion ( string  quaternionString)
static
static QuaternionD ConfigNode.ParseQuaternionD ( string  quaternionString)
static
static Vector3 ConfigNode.ParseVector2 ( string  vectorString)
static
static Vector3 ConfigNode.ParseVector3 ( string  vectorString)
static
static Vector3d ConfigNode.ParseVector3D ( string  vectorString)
static
static Vector4 ConfigNode.ParseVector4 ( string  vectorString)
static
bool ConfigNode.Save ( string  fileFullName)

Seralize this ConfigNode to a file.

Parameters
fileFullNameA filename (absolute path?)
Returns
?
bool ConfigNode.Save ( string  fileFullName,
string  header 
)
bool ConfigNode.SetNode ( string  name,
ConfigNode  newNode 
)
bool ConfigNode.SetNode ( string  name,
ConfigNode  newNode,
int  index 
)
bool ConfigNode.SetValue ( string  name,
string  newValue 
)
bool ConfigNode.SetValue ( string  name,
string  newValue,
int  index 
)
override string ConfigNode.ToString ( )

Seralizes this ConfigNode to a string.

Returns
A serialized version of this ConfigNode
static string ConfigNode.WriteColor ( Color  color)
static
static string ConfigNode.WriteColor ( Color32  color)
static
static string ConfigNode.WriteEnum ( Enum  en)
static
static string ConfigNode.WriteMatrix4x4 ( Matrix4x4  matrix)
static
static string ConfigNode.WriteQuaternion ( Quaternion  quaternion)
static
static string ConfigNode.WriteQuaternion ( QuaternionD  quaternion)
static
static string ConfigNode.WriteVector ( Vector2  vector)
static
static string ConfigNode.WriteVector ( Vector3  vector)
static
static string ConfigNode.WriteVector ( Vector3d  vector)
static
static string ConfigNode.WriteVector ( Vector4  vector)
static

Member Data Documentation

const string ConfigNode.configTabIndent = @" "
string ConfigNode.name

Property Documentation

int ConfigNode.CountNodes
get
int ConfigNode.CountValues
get
bool ConfigNode.HasData
get
ConfigNode.ConfigNodeList ConfigNode.nodes
get
ConfigNode.ValueList ConfigNode.values
get

The documentation for this class was generated from the following file: