/* Blunk - Multi User Server Framework Copyright 2009 - 2010 Nils W [nillus.net] Michael Graham [script-o-matic.net] This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . * PORTED TO C# BY awa500! */ using System; /** * Represents a Property List that can be read + written to. * * @author Nils * */ namespace Holo.Source.Socket_servers.MUS { public class MusPropList { private String[] m_symbols; private short[] m_data_types; private byte[][] m_data; public MusPropList(int length) { m_symbols = new String[length]; m_data_types = new short[length]; m_data = new byte[length][]; } public bool setPropAsBytes(string symbol, short type, byte[] data) { for (int i = 0; i < m_symbols.Length; i++) { if (m_symbols[i] == null) { m_symbols[i] = symbol; m_data_types[i] = type; m_data[i] = data; return true; } } // No space return false; } public bool setPropAsInt(string symbol, int i) { byte[] data = BitUtil.intToBytes(i); return this.setPropAsBytes(symbol, MusTypes.Integer, data); } public bool setPropAsString(string symbol, string str) { byte[] data = System.Text.Encoding.Default.GetBytes(str); return this.setPropAsBytes(symbol, MusTypes.String, data); } public short getPropType(string symbol) { for (int i = 0; i < m_symbols.Length; i++) { if (m_symbols[i] != null) { if (m_symbols[i].Equals(symbol)) { return m_data_types[i]; } } } return MusTypes.Void; } public byte[] getPropAsBytes(string symbol) { for (int i = 0; i < m_symbols.Length; i++) { if (m_symbols[i] != null) { if (m_symbols[i].Equals(symbol)) { return m_data[i]; } } } return new byte[0]; } public int getPropAsInt(string symbol) { byte[] bytes = this.getPropAsBytes(symbol); if (bytes.Length == 0) { return -1; } else { return BitUtil.bytesToInt(bytes); } } public String getPropAsString(String symbol) { byte[] bytes = this.getPropAsBytes(symbol); return System.Text.Encoding.Default.GetString(bytes); } public String getSymbolAt(int slot) { return m_symbols[slot]; } public short getDataTypeAt(int slot) { return m_data_types[slot]; } public byte[] getDataAt(int slot) { return m_data[slot]; } public int length() { return m_symbols.Length; } } }