121 lines
3.0 KiB
C#
121 lines
3.0 KiB
C#
using Sarand.Net.Standard.Base.Core;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Sarand.Net.Standard.Base.Bus
|
|
{
|
|
//=======================================================================
|
|
public class DataItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly NamedValue.Map values = new NamedValue.Map();
|
|
private readonly List<DataItem> childItems = new List<DataItem>();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public DataItem (int itemType = 0)
|
|
{
|
|
this.ItemType = itemType;
|
|
}
|
|
public DataItem (NamedValue.Map values, int itemType = 0)
|
|
{
|
|
this.ItemType = itemType;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public int ItemType { get; }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Values.
|
|
public bool HasValue (String name)
|
|
{
|
|
return values.HasValue(name);
|
|
}
|
|
public DataValue.DataType GetValueType (String name)
|
|
{
|
|
return GetValue(name)?.GetDataType() ?? DataValue.DataType.Unknown;
|
|
}
|
|
public DataValue GetValue (String name)
|
|
{
|
|
return values.GetValue(name);
|
|
}
|
|
public NamedValue.Map GetValues ()
|
|
{
|
|
return new NamedValue.Map(values);
|
|
}
|
|
public bool SetValue (String name, DataValue value)
|
|
{
|
|
values.AddValue(name, value);
|
|
return HasValue(name);
|
|
}
|
|
public bool SetValue (NamedValue value)
|
|
{
|
|
return SetValue(value.Name, value.Value);
|
|
}
|
|
public bool SetValues (NamedValue.Map values)
|
|
{
|
|
return this.values.AddValues(values);
|
|
}
|
|
public bool SetValues (ICollection<NamedValue> values)
|
|
{
|
|
return this.values.AddValues(values);
|
|
}
|
|
public bool RenameValue (String nameOld, String nameNew)
|
|
{
|
|
return values.RenameValue(nameOld, nameNew);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Child items.
|
|
public long GetChildItemCount ()
|
|
{
|
|
return childItems.Count;
|
|
}
|
|
public DataItem GetChildItemByPos (int itemIdx)
|
|
{
|
|
if (itemIdx <= childItems.Count)
|
|
return childItems[itemIdx];
|
|
return null;
|
|
}
|
|
public DataItem GetChildItemByType (int itemType)
|
|
{
|
|
return childItems.Find(item => item.ItemType == itemType);
|
|
}
|
|
public List<DataItem> GetChildItemsByType (int itemType)
|
|
{
|
|
List<DataItem> items = new List<DataItem>();
|
|
foreach (DataItem item in childItems)
|
|
{
|
|
if (item != null && item.ItemType == itemType)
|
|
items.Add(item);
|
|
}
|
|
return items;
|
|
}
|
|
|
|
// Update child items.
|
|
public bool ClearChildItems ()
|
|
{
|
|
childItems.Clear();
|
|
return true;
|
|
}
|
|
public bool AddChildItem (DataItem item)
|
|
{
|
|
if (item != null)
|
|
childItems.Add(item);
|
|
return item != null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
public static class SacsDataItemList
|
|
{
|
|
|
|
}
|
|
//=======================================================================
|
|
}
|