Mantis#2126. Thank you kindly, Ralphos for a patch that addresses:

Types extracted from a LSL_Types.list have to be down-cast initially 
to the exact type of value type object that the Object actually is.
This would make for very cumbersome, ugly code when extracting list 
parameter items in ll functions where a few implicit conversions 
should be applied such as key -> LSLString and LSLInteger -> LSLFloat 
(but not LSLFloat -> LSLInteger). This patch adds a set of GetXXXItem 
member functions to the LLS_Type.list class, where XXX is the name 
of the LSL_Type to be extracted: LSLFLoat, LSLInteger etc. All take 
a single, int parameter that is the item number to be extracted.
0.6.0-stable
Charles Krinke 2008-09-05 23:26:35 +00:00
parent 271bbb2557
commit 947242f476
3 changed files with 169 additions and 8 deletions

View File

@ -5726,13 +5726,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (remain < 7)
return;
bool flexi = (LSL_Types.LSLInteger)rules.Data[idx++];
int softness = (LSL_Types.LSLInteger)rules.Data[idx++];
float gravity = (float)(LSL_Types.LSLFloat)rules.Data[idx++];
float friction = (float)(LSL_Types.LSLFloat)rules.Data[idx++];
float wind = (float)(LSL_Types.LSLFloat)rules.Data[idx++];
float tension = (float)(LSL_Types.LSLFloat)rules.Data[idx++];
LSL_Types.Vector3 force = (LSL_Types.Vector3)rules.Data[idx++];
bool flexi = rules.GetLSLIntegerItem(idx++);
int softness = rules.GetLSLIntegerItem(idx++);
float gravity = (float)rules.GetLSLFloatItem(idx++);
float friction = (float)rules.GetLSLFloatItem(idx++);
float wind = (float)rules.GetLSLFloatItem(idx++);
float tension = (float)rules.GetLSLFloatItem(idx++);
LSL_Types.Vector3 force = rules.GetVector3Item(idx++);
SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);

View File

@ -421,6 +421,58 @@ namespace OpenSim.Region.ScriptEngine.Shared
}
}
// Member functions to obtain item as specific types.
// For cases where implicit conversions would apply if items
// were not in a list (e.g. integer to float, but not float
// to integer) functions check for alternate types so as to
// down-cast from Object to the correct type.
// Note: no checks for item index being valid are performed
public LSL_Types.LSLFloat GetLSLFloatItem( int itemIndex )
{
if (m_data[itemIndex] is LSL_Types.LSLInteger)
{
return (LSL_Types.LSLInteger)m_data[itemIndex];
}
else
{
return (LSL_Types.LSLFloat)m_data[itemIndex];
}
}
public LSL_Types.LSLString GetLSLStringItem(int itemIndex)
{
if (m_data[itemIndex] is LSL_Types.key)
{
return (LSL_Types.key)m_data[itemIndex];
}
else
{
return (LSL_Types.LSLString)m_data[itemIndex];
}
}
public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex)
{
return (LSL_Types.LSLInteger)m_data[itemIndex];
}
public LSL_Types.Vector3 GetVector3Item(int itemIndex)
{
return (LSL_Types.Vector3)m_data[itemIndex];
}
public LSL_Types.Quaternion GetQuaternionItem(int itemIndex)
{
return (LSL_Types.Quaternion)m_data[itemIndex];
}
public LSL_Types.key GetKeyItem(int itemIndex)
{
return (LSL_Types.key)m_data[itemIndex];
}
public static list operator +(list a, list b)
{
object[] tmp;
@ -1167,6 +1219,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
return k.value;
}
static public implicit operator LSLString(key k)
{
return k.value;
}
public static bool operator ==(key k1, key k2)
{
return k1.value == k2.value;
@ -1190,6 +1247,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
return value.GetHashCode();
}
public override string ToString()
{
return value;
}
#endregion
}

View File

@ -157,6 +157,105 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]);
}
//====================================================================================
/// <summary>
/// Tests GetLSLIntegerItem for LSLInteger item.
/// </summary>
[Test]
public void TestGetLSLIntegerItemForLSLIntegerItem()
{
LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetLSLIntegerItem(0));
}
/// <summary>
/// Tests GetLSLFloatItem for LSLFloat item.
/// </summary>
[Test]
public void TestGetLSLFloatItemForLSLFloatItem()
{
LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetLSLFloatItem(0));
}
/// <summary>
/// Tests GetLSLFloatItem for LSLInteger item.
/// </summary>
[Test]
public void TestGetLSLFloatItemForLSLIntegerItem()
{
LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987);
LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0));
}
/// <summary>
/// Tests GetLSLStringItem for LSLString item.
/// </summary>
[Test]
public void TestGetLSLStringItemForLSLStringItem()
{
LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all");
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetLSLStringItem(0));
}
/// <summary>
/// Tests GetLSLStringItem for key item.
/// </summary>
[Test]
public void TestGetLSLStringItemForKeyItem()
{
LSL_Types.key testValue
= new LSL_Types.key("98000000-0000-2222-3333-100000001000");
LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testStringValue, testList.GetLSLStringItem(0));
}
/// <summary>
/// Tests GetVector3Item for Vector3 item.
/// </summary>
[Test]
public void TestGetVector3ItemForVector3Item()
{
LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetVector3Item(0));
}
/// <summary>
/// Tests GetQuaternionItem for Quaternion item.
/// </summary>
[Test]
public void TestGetQuaternionItemForQuaternionItem()
{
LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987);
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetQuaternionItem(0));
}
/// <summary>
/// Tests GetKeyItem for key item.
/// </summary>
[Test]
public void TestGetKeyItemForKeyItem()
{
LSL_Types.key testValue
= new LSL_Types.key("00000000-0000-2222-3333-100000001012");
LSL_Types.list testList = new LSL_Types.list(testValue);
Assert.AreEqual(testValue, testList.GetKeyItem(0));
}
}
}