예제 #1
0
 public BitfieldData(string name, uint offset, long address, BitfieldType type, uint pluginLine)
     : base(name, offset, address, pluginLine)
 {
     _type             = type;
     CheckAllCommand   = new QuickCheckCommand(this, true);
     UncheckAllCommand = new QuickCheckCommand(this, false);
 }
예제 #2
0
		public BitfieldData(string name, uint offset, uint address, BitfieldType type, uint pluginLine)
			: base(name, offset, address, pluginLine)
		{
			_type = type;
			CheckAllCommand = new QuickCheckCommand(this, true);
			UncheckAllCommand = new QuickCheckCommand(this, false);
		}
 private bool EnterBitfield(BitfieldType type, string name, uint offset, bool visible, uint pluginLine)
 {
     if (visible || _showInvisibles)
     {
         _currentBitfield = new BitfieldData(name, offset, 0, type, pluginLine);
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// Gets the specified integer field of arbitrary size from the bitmap
        /// </summary>
        /// <param name="fieldType">Type of the field.</param>
        /// <param name="offset">The offset (bit or ordinal).</param>
        /// <param name="offsetIsOrdinal">if set to <c>true</c>, offset is ordinal, so offset=N means the N-th counter of the fieldType size.
        /// If set to <c>false</c>, offset is the bit position, so offset=N means the N-th bit</param>
        public T BitfieldGet <T>(BitfieldType fieldType, long offset, bool offsetIsOrdinal = false)
            where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
        {
            var db   = GetRedisDb();
            var args = new List <RedisValue>
            {
                "get",
                fieldType.ToString(),
                (offsetIsOrdinal ? "#" : "") + offset
            };
            var result = db.ScriptEvaluate(LuaScriptResource.Bitfield, new RedisKey[] { RedisKey }, args.ToArray());

            return((T)Convert.ChangeType((double)result, typeof(T)));
        }
        /// <summary>
        /// Increment the specified integer counter.
        /// </summary>
        /// <param name="fieldType">Type of the field.</param>
        /// <param name="offset">The offset (bit or ordinal).</param>
        /// <param name="increment">The value to increment.</param>
        /// <param name="offsetIsOrdinal">if set to <c>true</c>, offset is ordinal, so offset=N means the N-th counter of the fieldType size.
        /// If set to <c>false</c>, offset is the bit position, so offset=N means the N-th bit</param>
        /// <param name="overflowType">Overflow handling.</param>
        /// <returns>The previous value.</returns>
        public T BitfieldIncrementBy <T>(BitfieldType fieldType, long offset, T increment, bool offsetIsOrdinal = false, OverflowType overflowType = OverflowType.Wrap)
            where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable
        {
            var db   = GetRedisDb();
            var args = new List <RedisValue>
            {
                "overflow",
                TextAttribute.GetEnumText(overflowType),
                "incrby",
                fieldType.ToString(),
                (offsetIsOrdinal ? "#" : "") + offset,
                Math.Round((decimal)Convert.ChangeType(increment, typeof(decimal)), 0).ToString(CultureInfo.InvariantCulture)
            };
            var results = (RedisResult[])db.ScriptEvaluate(LuaScriptResource.Bitfield, new RedisKey[] { RedisKey }, args.ToArray());

            if (results[0].IsNull)
            {
                throw new OverflowException("The value would overflow the type " + fieldType);
            }
            return((T)Convert.ChangeType((double)results[0], typeof(T)));
        }
예제 #6
0
 private bool EnterBitfield(BitfieldType type, string name, uint offset, bool visible, uint pluginLine)
 {
     if (visible || _showInvisibles)
     {
         _currentBitfield = new BitfieldData(name, offset, 0, type, pluginLine);
         return true;
     }
     return false;
 }
예제 #7
0
 public BitfieldData(string name, uint offset, BitfieldType type, uint pluginLine)
     : base(name, offset, pluginLine)
 {
     _type = type;
 }
예제 #8
0
 public BitfieldData(string name, uint offset, uint address, BitfieldType type)
     : base(name, offset, address)
 {
     Type = type;
 }