예제 #1
0
 /// <summary>
 ///     Constructs the appropriate command object for a config operation that may contain an index.
 /// </summary>
 /// <param name="op">The config operation to lift to a command object.</param>
 /// <param name="index">An index, or absence thereof (<see cref="ConfigCache.NoIndex" />).</param>
 /// <param name="modeFlag">The mode flag.</param>
 /// <returns>The appropriate command for <paramref name="op" /> and <paramref name="index" />.</returns>
 private ICommand PossiblyIndexedConfigCommand(ConfigOp op, int index = ConfigCache.NoIndex,
                                               bool modeFlag          = false)
 {
     return(index == ConfigCache.NoIndex
         ? (ICommand) new NonIndexedConfigCommand(op, modeFlag)
         : new IndexedConfigCommand(op, (byte)index, modeFlag));
 }
예제 #2
0
        private static ICommand UnpackIndexableConfig(ConfigOp op, bool modeFlag, ushort word)
        {
            var indexedFlag = HasConfigIndexedFlag(word);

            return(indexedFlag
                ? (ICommand) new IndexedConfigCommand(op, ConfigIndex(word), modeFlag)
                : new NonIndexedConfigCommand(op, modeFlag));
        }
예제 #3
0
 /// <summary>
 ///     Gets whether a particular config operation can take an index.
 /// </summary>
 /// <param name="op">The operation to check.</param>
 /// <returns>
 ///     True if <paramref name="op" /> can take an index (that is, its
 ///     packed representation's lowest 7 bits are a has-index flag followed by
 ///     6 index bits); false if not (and the packed representation's lowest
 ///     7 bits are one don't-care bit followed by 6 value bits).
 /// </returns>
 public static bool CanTakeIndex(this ConfigOp op)
 {
     return(op switch {
         ConfigOp.SetConfigValue => true,
         ConfigOp.Option => true,
         ConfigOp.ConfigSetting => true,
         ConfigOp.ConfigResult => true,
         // Technically, IPRestriction doesn't take an index.
         // However, it puts the 'alter/deny' bit in the same place as
         // the 'has/doesn't have index' bit, and it's easier to model
         // this as an indexed command.
         ConfigOp.IpRestriction => true,
         _ => false
     });
예제 #4
0
 /// <summary>
 ///     Packs this <see cref="ConfigOp"/> into its BapsNet representation
 /// </summary>
 /// <param name="op">The opcode to pack.</param>
 /// <returns>
 ///     The bit-pattern of <see cref="op"/> in a packed BapsNet command word,
 ///     less its group code.
 /// </returns>
 public static ushort ToWordBits(this ConfigOp op)
 {
     return(Op((byte)op));
 }
예제 #5
0
 public ValueConfigCommand(ConfigOp op, byte value, bool modeFlag) : base(op, modeFlag)
 {
     CheckValueFitsInIndexSpace(value);
     Value = value;
 }
예제 #6
0
 public IndexedConfigCommand(ConfigOp op, byte index, bool modeFlag) : base(op, modeFlag)
 {
     Index = index;
 }
예제 #7
0
 protected IndexableConfigCommand(ConfigOp op, bool modeFlag) : base(op, modeFlag)
 {
 }
 public NonIndexedConfigCommand(ConfigOp op, bool modeFlag) : base(op, modeFlag)
 {
 }