Skip to content

Commit

Permalink
wip buckets 2
Browse files Browse the repository at this point in the history
  • Loading branch information
misson20000 committed Nov 25, 2023
1 parent 1a6004a commit 07ba5b7
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 99 deletions.
70 changes: 67 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,59 @@ impl Default for Notifier {
}
}

pub enum PhiIterator<Item, I1: Iterator<Item = Item>, I2: Iterator<Item = Item>, I3: Iterator<Item = Item>, I4: Iterator<Item = Item>> {
pub enum Never {
}

pub struct NeverIterator<T>(Never, std::marker::PhantomData<T>);

impl<T> Iterator for NeverIterator<T> {
type Item = T;

fn next(&mut self) -> Option<T> {
match self.0 {
}
}
}

impl<T> DoubleEndedIterator for NeverIterator<T> {
fn next_back(&mut self) -> Option<T> {
match self.0 {
}
}
}
pub enum PhiIterator
<Item,
I1: Iterator<Item = Item> = NeverIterator<Item>,
I2: Iterator<Item = Item> = NeverIterator<Item>,
I3: Iterator<Item = Item> = NeverIterator<Item>,
I4: Iterator<Item = Item> = NeverIterator<Item>,
I5: Iterator<Item = Item> = NeverIterator<Item>,
I6: Iterator<Item = Item> = NeverIterator<Item>
> {
I1(I1),
I2(I2),
I3(I3),
I4(I4),
I5(I5),
I6(I6),
}

impl<Item, I1: Iterator<Item = Item>, I2: Iterator<Item = Item>, I3: Iterator<Item = Item>, I4: Iterator<Item = Item>> Iterator for PhiIterator<Item, I1, I2, I3, I4> {
impl<Item,
I1: Iterator<Item = Item>,
I2: Iterator<Item = Item>,
I3: Iterator<Item = Item>,
I4: Iterator<Item = Item>,
I5: Iterator<Item = Item>,
I6: Iterator<Item = Item>
> Iterator for PhiIterator
<Item,
I1,
I2,
I3,
I4,
I5,
I6
> {
type Item = Item;

fn next(&mut self) -> Option<Item> {
Expand All @@ -79,17 +124,36 @@ impl<Item, I1: Iterator<Item = Item>, I2: Iterator<Item = Item>, I3: Iterator<It
Self::I2(i) => i.next(),
Self::I3(i) => i.next(),
Self::I4(i) => i.next(),
Self::I5(i) => i.next(),
Self::I6(i) => i.next(),
}
}
}

impl<Item, I1: DoubleEndedIterator<Item = Item>, I2: DoubleEndedIterator<Item = Item>, I3: DoubleEndedIterator<Item = Item>, I4: DoubleEndedIterator<Item = Item>> DoubleEndedIterator for PhiIterator<Item, I1, I2, I3, I4> {
impl<Item,
I1: DoubleEndedIterator<Item = Item>,
I2: DoubleEndedIterator<Item = Item>,
I3: DoubleEndedIterator<Item = Item>,
I4: DoubleEndedIterator<Item = Item>,
I5: DoubleEndedIterator<Item = Item>,
I6: DoubleEndedIterator<Item = Item>
> DoubleEndedIterator for PhiIterator
<Item,
I1,
I2,
I3,
I4,
I5,
I6
> {
fn next_back(&mut self) -> Option<Item> {
match self {
Self::I1(i) => i.next_back(),
Self::I2(i) => i.next_back(),
Self::I3(i) => i.next_back(),
Self::I4(i) => i.next_back(),
Self::I5(i) => i.next_back(),
Self::I6(i) => i.next_back(),
}
}
}
1 change: 1 addition & 0 deletions src/view/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use gtk::pango;
use gtk::subclass::prelude::*;
use gtk::prelude::*;

mod bucket;
pub mod facet;
mod token_view;
mod line;
Expand Down
175 changes: 175 additions & 0 deletions src/view/listing/bucket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
use std::iter;
use std::sync;
use std::vec;

use crate::model::addr;
use crate::model::document::structure;
use crate::model::listing::token;
use crate::model::selection;
use crate::view::listing;
use crate::view::listing::facet::cursor;
use crate::view::listing::token_view;

use gtk::graphene;

#[derive(Clone, Copy)]
pub struct RenderArgs<'a> {
snapshot: &'a gtk::Snapshot,
cursor: &'a cursor::CursorView,
selection: &'a selection::listing::Mode,
render: &'a listing::RenderDetail
}

pub trait Bucket {
type TokenIterator;
type BorrowingTokenIterator<'a> where Self: 'a;

//fn render(&mut self, ctx: RenderArgs<'_>);
fn iter_tokens(&self) -> Self::BorrowingTokenIterator<'_>;
fn to_tokens(self) -> Self::TokenIterator;
}

pub struct BlankMarker;
pub struct TitleMarker;
pub struct HexstringMarker;
pub struct SummaryMarker;

pub struct SingleTokenBucket<Marker> {
begin: graphene::Point,
end: graphene::Point,
tv: token_view::TokenView,
marker: std::marker::PhantomData<Marker>,
}

pub struct MaybeTokenBucket<Marker> {
begin: graphene::Point,
end: graphene::Point,
tv: Option<token_view::TokenView>,
marker: std::marker::PhantomData<Marker>,
}

pub struct MultiTokenBucket<Marker> {
begin: graphene::Point,
end: graphene::Point,
tvs: Vec<token_view::TokenView>,
marker: std::marker::PhantomData<Marker>,
}

pub struct HexdumpBucket {
begin: graphene::Point,
end: graphene::Point,
node: sync::Arc<structure::Node>,
line_extent: addr::Extent,
tvs: Vec<token_view::TokenView>
}

impl<Marker> SingleTokenBucket<Marker> {
}

impl<Marker> From<token::Token> for SingleTokenBucket<Marker> {
fn from(token: token::Token) -> Self {
SingleTokenBucket {
begin: graphene::Point::zero(),
end: graphene::Point::zero(),
tv: token_view::TokenView::from(token),
marker: std::marker::PhantomData
}
}
}

impl<Marker> Bucket for SingleTokenBucket<Marker> {
type TokenIterator = iter::Once<token::Token>;
type BorrowingTokenIterator<'a> = iter::Once<&'a token::Token> where Marker: 'a;

fn iter_tokens(&self) -> Self::BorrowingTokenIterator<'_> {
iter::once(self.tv.token())
}

fn to_tokens(self) -> Self::TokenIterator {
iter::once(self.tv.into_token())
}
}

impl<Marker> MaybeTokenBucket<Marker> {
fn from_token(token: Option<token::Token>) -> Self {
MaybeTokenBucket {
begin: graphene::Point::zero(),
end: graphene::Point::zero(),
tv: token.map(token_view::TokenView::from),
marker: std::marker::PhantomData
}
}
}

impl<Marker> From<Option<token::Token>> for MaybeTokenBucket<Marker> {
fn from(token: Option<token::Token>) -> Self {
MaybeTokenBucket {
begin: graphene::Point::zero(),
end: graphene::Point::zero(),
tv: token.map(token_view::TokenView::from),
marker: std::marker::PhantomData
}
}
}

impl<Marker> Bucket for MaybeTokenBucket<Marker> {
type TokenIterator = std::option::IntoIter<token::Token>;
type BorrowingTokenIterator<'a> = std::option::IntoIter<&'a token::Token> where Marker: 'a;

fn iter_tokens(&self) -> Self::BorrowingTokenIterator<'_> {
self.tv.as_ref().map(token_view::TokenView::token).into_iter()
}

fn to_tokens(self) -> Self::TokenIterator {
self.tv.map(token_view::TokenView::into_token).into_iter()
}
}

impl<Marker> MultiTokenBucket<Marker> {
pub fn from_tokens(tokens: impl Iterator<Item = token::Token>) -> Self {
MultiTokenBucket {
begin: graphene::Point::zero(),
end: graphene::Point::zero(),
tvs: tokens.map(token_view::TokenView::from).collect(),
marker: std::marker::PhantomData
}
}
}

impl<Marker> Bucket for MultiTokenBucket<Marker> {
type TokenIterator = iter::Map<vec::IntoIter<token_view::TokenView>, fn(token_view::TokenView) -> token::Token>;
type BorrowingTokenIterator<'a> = iter::Map<std::slice::Iter<'a, token_view::TokenView>, fn(&'a token_view::TokenView) -> &'a token::Token> where Marker: 'a;

fn iter_tokens(&self) -> Self::BorrowingTokenIterator<'_> {
self.tvs.iter().map(token_view::TokenView::token)
}

fn to_tokens(self) -> Self::TokenIterator {
self.tvs.into_iter().map(token_view::TokenView::into_token)
}
}

impl HexdumpBucket {
pub fn new(node: sync::Arc<structure::Node>, line_extent: addr::Extent, tokens: impl Iterator<Item = token::Token>) -> Self {
HexdumpBucket {
begin: graphene::Point::zero(),
end: graphene::Point::zero(),
node,
line_extent,
tvs: tokens.map(token_view::TokenView::from).collect(),
}
}
}

impl Bucket for HexdumpBucket {
type TokenIterator = iter::Map<vec::IntoIter<token_view::TokenView>, fn(token_view::TokenView) -> token::Token>;
type BorrowingTokenIterator<'a> = iter::Map<std::slice::Iter<'a, token_view::TokenView>, fn(&'a token_view::TokenView) -> &'a token::Token>;

fn iter_tokens(&self) -> Self::BorrowingTokenIterator<'_> {
self.tvs.iter().map(token_view::TokenView::token)
}

fn to_tokens(self) -> Self::TokenIterator {
self.tvs.into_iter().map(token_view::TokenView::into_token)
}
}
Loading

0 comments on commit 07ba5b7

Please sign in to comment.