- .NET API: Added properties to MmsVariableSpecification class (LIB61850-460)

pull/535/head
Michael Zillgith 11 months ago
parent 830059fca2
commit ae02944918

@ -1,7 +1,7 @@
/* /*
* MmsVariableSpecification.cs * MmsVariableSpecification.cs
* *
* Copyright 2014 Michael Zillgith * Copyright 2014-2024 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *
@ -70,14 +70,14 @@ namespace IEC61850
/* only to prevent garbage collector to destroy parent element */ /* only to prevent garbage collector to destroy parent element */
internal MmsVariableSpecification parent = null; internal MmsVariableSpecification parent = null;
internal MmsVariableSpecification (IntPtr self, MmsVariableSpecification parent) internal MmsVariableSpecification(IntPtr self, MmsVariableSpecification parent)
{ {
this.self = self; this.self = self;
this.responsableForDeletion = false; this.responsableForDeletion = false;
this.parent = parent; this.parent = parent;
} }
internal MmsVariableSpecification (IntPtr self, bool responsableForDeletion) internal MmsVariableSpecification(IntPtr self, bool responsableForDeletion)
{ {
this.self = self; this.self = self;
this.responsableForDeletion = responsableForDeletion; this.responsableForDeletion = responsableForDeletion;
@ -104,7 +104,7 @@ namespace IEC61850
return null; return null;
} }
~MmsVariableSpecification () ~MmsVariableSpecification()
{ {
if (responsableForDeletion) if (responsableForDeletion)
MmsVariableSpecification_destroy(self); MmsVariableSpecification_destroy(self);
@ -116,9 +116,17 @@ namespace IEC61850
/// <returns> /// <returns>
/// The MmsType of the variable /// The MmsType of the variable
/// </returns> /// </returns>
public new MmsType GetType () public new MmsType GetType()
{ {
return (MmsType) MmsVariableSpecification_getType(self); return (MmsType)MmsVariableSpecification_getType(self);
}
/// <summary>
/// The MmsValue type of the variable
/// </summary>
public MmsType MmsType
{
get { return (MmsType)MmsVariableSpecification_getType(self); }
} }
/// <summary> /// <summary>
@ -128,14 +136,32 @@ namespace IEC61850
/// The array element type. /// The array element type.
/// </returns> /// </returns>
/// <exception cref="MmsValueException">This exception is thrown if the value is not of type MMS_ARRAY</exception> /// <exception cref="MmsValueException">This exception is thrown if the value is not of type MMS_ARRAY</exception>
public MmsVariableSpecification getArrayElementType () public MmsVariableSpecification getArrayElementType()
{
if (GetType() == MmsType.MMS_ARRAY)
{ {
if (GetType() == MmsType.MMS_ARRAY) {
IntPtr varSpecPtr = MmsVariableSpecification.MmsVariableSpecification_getArrayElementSpecification(self); IntPtr varSpecPtr = MmsVariableSpecification.MmsVariableSpecification_getArrayElementSpecification(self);
return new MmsVariableSpecification(varSpecPtr, this); return new MmsVariableSpecification(varSpecPtr, this);
} }
else else
throw new MmsValueException ("specification is of wrong type"); throw new MmsValueException("specification is of wrong type");
}
/// <summary>
/// The type of array elements (when the variable is of type MMS_ARRAY)
/// </summary>
public MmsVariableSpecification ArrayElementType
{
get
{
if (GetType() == MmsType.MMS_ARRAY)
{
IntPtr varSpecPtr = MmsVariableSpecification.MmsVariableSpecification_getArrayElementSpecification(self);
return new MmsVariableSpecification(varSpecPtr, this);
}
else
return null;
}
} }
/// <summary> /// <summary>
@ -147,41 +173,86 @@ namespace IEC61850
/// <param name='index'> /// <param name='index'>
/// Index. /// Index.
/// </param> /// </param>
public MmsVariableSpecification GetElement (int index) public MmsVariableSpecification GetElement(int index)
{
if (GetType() == MmsType.MMS_STRUCTURE)
{ {
if (GetType () == MmsType.MMS_STRUCTURE) {
if ((index >= 0) && (index < Size ())) { if ((index >= 0) && (index < Size()))
{
IntPtr varSpecPtr = MmsVariableSpecification_getChildSpecificationByIndex(self, index); IntPtr varSpecPtr = MmsVariableSpecification_getChildSpecificationByIndex(self, index);
return new MmsVariableSpecification(varSpecPtr, this); return new MmsVariableSpecification(varSpecPtr, this);
} }
else else
throw new MmsValueException ("Index out of bounds"); throw new MmsValueException("Index out of bounds");
} }
else else
throw new MmsValueException ("specification is of wrong type"); throw new MmsValueException("specification is of wrong type");
}
/// <summary>
/// The element types for complex variables (MMS_STRUCTURE)
/// </summary>
public MmsVariableSpecification[] Elements
{
get
{
if (GetType() != MmsType.MMS_STRUCTURE)
return null;
List<MmsVariableSpecification> elements = new List<MmsVariableSpecification>();
for (int i = 0; i < Size(); i++)
{
elements.Add(GetElement(i));
}
return elements.ToArray();
}
} }
/// <summary> /// <summary>
/// Gets the name of the variable /// Gets the name of the variable (relative to the parent)
/// </summary> /// </summary>
/// <returns> /// <returns>
/// The name. /// The name.
/// </returns> /// </returns>
public string GetName () public string GetName()
{ {
IntPtr namePtr = MmsVariableSpecification_getName(self); IntPtr namePtr = MmsVariableSpecification_getName(self);
return Marshal.PtrToStringAnsi (namePtr); return Marshal.PtrToStringAnsi(namePtr);
}
/// <summary>
/// The name of the variable (relative to the parent)
/// </summary>
public string Name
{
get
{
return GetName();
}
} }
/// <summary> /// <summary>
/// Get the "size" of the variable (array size, number of structure elements ...) /// Get the "size" of the variable (array size, number of structure elements ...)
/// </summary> /// </summary>
public int Size () public int Size()
{
return MmsVariableSpecification_getSize(self);
}
/// <summary>
/// The "size" of the variable (array size, number of structure elements ...)
/// </summary>
public int size
{
get
{ {
return MmsVariableSpecification_getSize(self); return MmsVariableSpecification_getSize(self);
} }
}
/// <summary> /// <summary>
/// Determines whether the given value object matches this type /// Determines whether the given value object matches this type
@ -193,9 +264,9 @@ namespace IEC61850
return MmsVariableSpecification_isValueOfType(self, value.valueReference); return MmsVariableSpecification_isValueOfType(self, value.valueReference);
} }
IEnumerator IEnumerable.GetEnumerator () IEnumerator IEnumerable.GetEnumerator()
{ {
return new MmsVariableSpecificationEnumerator (this); return new MmsVariableSpecificationEnumerator(this);
} }
private class MmsVariableSpecificationEnumerator : IEnumerator private class MmsVariableSpecificationEnumerator : IEnumerator
@ -203,27 +274,28 @@ namespace IEC61850
private MmsVariableSpecification value; private MmsVariableSpecification value;
private int index = -1; private int index = -1;
public MmsVariableSpecificationEnumerator (MmsVariableSpecification value) public MmsVariableSpecificationEnumerator(MmsVariableSpecification value)
{ {
this.value = value; this.value = value;
} }
#region IEnumerator Members #region IEnumerator Members
public void Reset () public void Reset()
{ {
index = -1; index = -1;
} }
public object Current { public object Current
{
get { return value.GetElement (index);} get { return value.GetElement(index); }
} }
public bool MoveNext () public bool MoveNext()
{ {
index++; index++;
if (index >= value.Size ()) if (index >= value.Size())
return false; return false;
else else
return true; return true;

Loading…
Cancel
Save