add move fn to dsl, rename SPCommand to GenericCommand, remove DisplayBitVec command
This commit is contained in:
		
							parent
							
								
									e434130784
								
							
						
					
					
						commit
						323ba6128e
					
				
					 13 changed files with 335 additions and 356 deletions
				
			
		| 
						 | 
				
			
			@ -12,7 +12,6 @@ use std::ptr::NonNull;
 | 
			
		|||
wrap_grid!(Bitmap, bool);
 | 
			
		||||
 | 
			
		||||
wrap_functions!(bitmap;
 | 
			
		||||
 | 
			
		||||
    /// Creates a new [Bitmap] with the specified dimensions.
 | 
			
		||||
    ///
 | 
			
		||||
    /// # Arguments
 | 
			
		||||
| 
						 | 
				
			
			@ -76,35 +75,26 @@ wrap_functions!(bitmap;
 | 
			
		|||
        let bitvec = unsafe { heap_remove(bitvec) };
 | 
			
		||||
        heap_move_ok(Bitmap::from_bitvec(width, bitvec))
 | 
			
		||||
    }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(Bitmap;
 | 
			
		||||
    /// Consumes the Bitmap and returns the contained BitVec.
 | 
			
		||||
    fn into_bitvec(
 | 
			
		||||
        bitmap: NonNull<Bitmap>
 | 
			
		||||
    ) -> NonNull<DisplayBitVec> {
 | 
			
		||||
        let bitmap = unsafe { heap_remove(bitmap) };
 | 
			
		||||
    move fn into_bitvec(bitmap) -> NonNull<DisplayBitVec> {
 | 
			
		||||
        heap_move_nonnull(bitmap.into())
 | 
			
		||||
    }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Creates a [BitmapCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [Bitmap] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    fn try_into_packet(
 | 
			
		||||
        bitmap: NonNull<Bitmap>,
 | 
			
		||||
        x: usize,
 | 
			
		||||
        y: usize,
 | 
			
		||||
        compression: CompressionCode,
 | 
			
		||||
    ) -> *mut Packet {
 | 
			
		||||
        let bitmap = unsafe { heap_remove(bitmap) };
 | 
			
		||||
    move fn try_into_packet(bitmap, x: usize, y: usize, compression: CompressionCode) -> *mut Packet {
 | 
			
		||||
        heap_move_ok(Packet::try_from(BitmapCommand {
 | 
			
		||||
            bitmap,
 | 
			
		||||
            origin: Origin::new(x, y),
 | 
			
		||||
            compression,
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(Bitmap;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Gets an unsafe reference to the data of the [Bitmap] instance.
 | 
			
		||||
    ///
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use crate::{
 | 
			
		||||
    containers::{wrap_container, ByteSlice},
 | 
			
		||||
    macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_remove},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok},
 | 
			
		||||
};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
 | 
			
		||||
| 
						 | 
				
			
			@ -35,29 +35,27 @@ wrap_functions!(associate DisplayBitVec;
 | 
			
		|||
        heap_move_nonnull(DisplayBitVec::from_slice(data))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(DisplayBitVec;
 | 
			
		||||
    /// Creates a [BitVecCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [DisplayBitVec] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    fn try_into_packet(
 | 
			
		||||
        bitvec: NonNull<DisplayBitVec>,
 | 
			
		||||
    move fn try_into_packet(
 | 
			
		||||
        bitvec,
 | 
			
		||||
        offset: usize,
 | 
			
		||||
        operation: BinaryOperation,
 | 
			
		||||
        compression: CompressionCode,
 | 
			
		||||
        compression: CompressionCode
 | 
			
		||||
    ) -> *mut Packet {
 | 
			
		||||
        let bitvec = unsafe { heap_remove(bitvec) };
 | 
			
		||||
        heap_move_ok(Packet::try_from(BitVecCommand {
 | 
			
		||||
            bitvec,
 | 
			
		||||
            offset,
 | 
			
		||||
            operation,
 | 
			
		||||
            compression,
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(DisplayBitVec;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Gets the value of a bit.
 | 
			
		||||
    ///
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use crate::{
 | 
			
		||||
    containers::{wrap_grid, ByteSlice},
 | 
			
		||||
    macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_move_some},
 | 
			
		||||
};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
 | 
			
		||||
| 
						 | 
				
			
			@ -54,26 +54,21 @@ wrap_functions!(associate BrightnessGrid;
 | 
			
		|||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(BrightnessGrid;
 | 
			
		||||
    /// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [BrightnessGrid] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    fn try_into_packet(
 | 
			
		||||
        grid: NonNull<BrightnessGrid>,
 | 
			
		||||
        x: usize,
 | 
			
		||||
        y: usize,
 | 
			
		||||
    ) -> *mut Packet {
 | 
			
		||||
        let grid = unsafe { heap_remove(grid) };
 | 
			
		||||
    move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
 | 
			
		||||
        heap_move_ok(Packet::try_from(BrightnessGridCommand {
 | 
			
		||||
            grid,
 | 
			
		||||
            origin: Origin::new(x, y),
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(BrightnessGrid;
 | 
			
		||||
    /// Gets an unsafe reference to the data of the instance.
 | 
			
		||||
    ///
 | 
			
		||||
    /// The returned memory is valid for the lifetime of the grid.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use crate::{
 | 
			
		||||
    containers::{derive_get_width_height, wrap_container, ByteSlice},
 | 
			
		||||
    macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_remove},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok},
 | 
			
		||||
};
 | 
			
		||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
| 
						 | 
				
			
			@ -23,41 +23,18 @@ wrap_functions!(associate CharGrid;
 | 
			
		|||
    /// sp_char_grid_set(grid, 0, 0, '!');
 | 
			
		||||
    /// sp_char_grid_free(grid);
 | 
			
		||||
    /// ```
 | 
			
		||||
    fn new(
 | 
			
		||||
        width: usize,
 | 
			
		||||
        height: usize,
 | 
			
		||||
    ) -> NonNull<CharGrid> {
 | 
			
		||||
    fn new(width: usize, height: usize) -> NonNull<CharGrid> {
 | 
			
		||||
        heap_move_nonnull(CharGrid::new(width, height))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Loads a [CharGrid] with the specified dimensions from the provided data.
 | 
			
		||||
    ///
 | 
			
		||||
    /// returns: new CharGrid or NULL in case of an error
 | 
			
		||||
    fn load(
 | 
			
		||||
        width: usize,
 | 
			
		||||
        height: usize,
 | 
			
		||||
        data: ByteSlice,
 | 
			
		||||
    ) -> *mut CharGrid {
 | 
			
		||||
    fn load(width: usize, height: usize, data: ByteSlice) -> *mut CharGrid {
 | 
			
		||||
        let data = unsafe { data.as_slice() };
 | 
			
		||||
        heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Creates a [CharGridCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [CharGrid] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    fn try_into_packet(
 | 
			
		||||
        grid: NonNull<CharGrid>,
 | 
			
		||||
        x: usize,
 | 
			
		||||
        y: usize,
 | 
			
		||||
    ) -> *mut Packet {
 | 
			
		||||
        let grid = unsafe { heap_remove(grid) };
 | 
			
		||||
        heap_move_ok(Packet::try_from(CharGridCommand {
 | 
			
		||||
            grid,
 | 
			
		||||
            origin: Origin::new(x, y),
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -102,4 +79,16 @@ wrap_methods!(CharGrid;
 | 
			
		|||
    mut fn fill(instance, value: u32) {
 | 
			
		||||
        instance.fill(char::from_u32(value).unwrap())
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /// Creates a [CharGridCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [CharGrid] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
 | 
			
		||||
        heap_move_ok(Packet::try_from(CharGridCommand {
 | 
			
		||||
            grid,
 | 
			
		||||
            origin: Origin::new(x, y),
 | 
			
		||||
        }))
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use crate::{
 | 
			
		||||
    containers::{wrap_grid, ByteSlice},
 | 
			
		||||
    macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
 | 
			
		||||
    mem::{heap_move_nonnull, heap_move_ok, heap_move_some},
 | 
			
		||||
};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
 | 
			
		||||
| 
						 | 
				
			
			@ -32,26 +32,21 @@ wrap_functions!(cp437grid;
 | 
			
		|||
        heap_move_some(Cp437Grid::load(width, height, data))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(Cp437Grid;
 | 
			
		||||
    /// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
 | 
			
		||||
    ///
 | 
			
		||||
    /// The provided [Cp437Grid] gets consumed.
 | 
			
		||||
    ///
 | 
			
		||||
    /// Returns NULL in case of an error.
 | 
			
		||||
    fn try_into_packet(
 | 
			
		||||
        grid: NonNull<Cp437Grid>,
 | 
			
		||||
        x: usize,
 | 
			
		||||
        y: usize,
 | 
			
		||||
    ) -> *mut Packet {
 | 
			
		||||
        let grid = unsafe { heap_remove(grid) };
 | 
			
		||||
    move fn try_into_packet(grid, x: usize, y: usize) -> *mut Packet {
 | 
			
		||||
        heap_move_ok(Packet::try_from(Cp437GridCommand {
 | 
			
		||||
            grid,
 | 
			
		||||
            origin: Origin::new(x, y),
 | 
			
		||||
        }))
 | 
			
		||||
    }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
wrap_methods!(Cp437Grid;
 | 
			
		||||
    /// Gets an unsafe reference to the data of the grid.
 | 
			
		||||
    ///
 | 
			
		||||
    /// The returned memory is valid for the lifetime of the instance.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue