/// <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)); }
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)); }
/// <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 });
/// <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)); }
public ValueConfigCommand(ConfigOp op, byte value, bool modeFlag) : base(op, modeFlag) { CheckValueFitsInIndexSpace(value); Value = value; }
public IndexedConfigCommand(ConfigOp op, byte index, bool modeFlag) : base(op, modeFlag) { Index = index; }
protected IndexableConfigCommand(ConfigOp op, bool modeFlag) : base(op, modeFlag) { }
public NonIndexedConfigCommand(ConfigOp op, bool modeFlag) : base(op, modeFlag) { }