1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use crate::error::Result;
use crate::feature_processor::FeatureProcessor;
use crate::geometry_processor::GeomProcessor;
use crate::property_processor::{ColumnValue, PropertyProcessor};

pub struct Multiplexer<P1: FeatureProcessor, P2: FeatureProcessor> {
    p1: P1,
    p2: P2,
}

impl<P1: FeatureProcessor, P2: FeatureProcessor> Multiplexer<P1, P2> {
    pub fn new(p1: P1, p2: P2) -> Multiplexer<P1, P2> {
        Multiplexer { p1, p2 }
    }
}

impl<P1: FeatureProcessor, P2: FeatureProcessor> FeatureProcessor for Multiplexer<P1, P2> {
    fn dataset_begin(&mut self, name: Option<&str>) -> Result<()> {
        self.p1.dataset_begin(name)?;
        self.p2.dataset_begin(name)
    }
    fn dataset_end(&mut self) -> Result<()> {
        self.p1.dataset_end()?;
        self.p2.dataset_end()
    }
    fn feature_begin(&mut self, idx: u64) -> Result<()> {
        self.p1.feature_begin(idx)?;
        self.p2.feature_begin(idx)
    }
    fn feature_end(&mut self, idx: u64) -> Result<()> {
        self.p1.feature_end(idx)?;
        self.p2.feature_end(idx)
    }
    fn properties_begin(&mut self) -> Result<()> {
        self.p1.properties_begin()?;
        self.p2.properties_begin()
    }
    fn properties_end(&mut self) -> Result<()> {
        self.p1.properties_end()?;
        self.p2.properties_end()
    }
    fn geometry_begin(&mut self) -> Result<()> {
        self.p1.geometry_begin()?;
        self.p2.geometry_begin()
    }
    fn geometry_end(&mut self) -> Result<()> {
        self.p1.geometry_end()?;
        self.p2.geometry_end()
    }
}

impl<P1: FeatureProcessor, P2: FeatureProcessor> GeomProcessor for Multiplexer<P1, P2> {
    fn xy(&mut self, x: f64, y: f64, idx: usize) -> Result<()> {
        self.p1.xy(x, y, idx)?;
        self.p2.xy(x, y, idx)
    }
    fn coordinate(
        &mut self,
        x: f64,
        y: f64,
        z: Option<f64>,
        m: Option<f64>,
        t: Option<f64>,
        tm: Option<u64>,
        idx: usize,
    ) -> Result<()> {
        self.p1.coordinate(x, y, z, m, t, tm, idx)?;
        self.p2.coordinate(x, y, z, m, t, tm, idx)
    }
    fn point_begin(&mut self, idx: usize) -> Result<()> {
        self.p1.point_begin(idx)?;
        self.p2.point_begin(idx)
    }
    fn point_end(&mut self, idx: usize) -> Result<()> {
        self.p1.point_end(idx)?;
        self.p2.point_end(idx)
    }
    fn multipoint_begin(&mut self, size: usize, idx: usize) -> Result<()> {
        self.p1.multipoint_begin(size, idx)?;
        self.p2.multipoint_begin(size, idx)
    }
    fn multipoint_end(&mut self, idx: usize) -> Result<()> {
        self.p1.multipoint_end(idx)?;
        self.p2.multipoint_end(idx)
    }
    fn linestring_begin(&mut self, tagged: bool, size: usize, idx: usize) -> Result<()> {
        self.p1.linestring_begin(tagged, size, idx)?;
        self.p2.linestring_begin(tagged, size, idx)
    }
    fn linestring_end(&mut self, tagged: bool, idx: usize) -> Result<()> {
        self.p1.linestring_end(tagged, idx)?;
        self.p2.linestring_end(tagged, idx)
    }
    fn multilinestring_begin(&mut self, size: usize, idx: usize) -> Result<()> {
        self.p1.multilinestring_begin(size, idx)?;
        self.p2.multilinestring_begin(size, idx)
    }
    fn multilinestring_end(&mut self, idx: usize) -> Result<()> {
        self.p1.multilinestring_end(idx)?;
        self.p2.multilinestring_end(idx)
    }
    fn polygon_begin(&mut self, tagged: bool, size: usize, idx: usize) -> Result<()> {
        self.p1.polygon_begin(tagged, size, idx)?;
        self.p2.polygon_begin(tagged, size, idx)
    }
    fn polygon_end(&mut self, tagged: bool, idx: usize) -> Result<()> {
        self.p1.polygon_end(tagged, idx)?;
        self.p2.polygon_end(tagged, idx)
    }
    fn multipolygon_begin(&mut self, size: usize, idx: usize) -> Result<()> {
        self.p1.multipolygon_begin(size, idx)?;
        self.p2.multipolygon_begin(size, idx)
    }
    fn multipolygon_end(&mut self, idx: usize) -> Result<()> {
        self.p1.multipolygon_end(idx)?;
        self.p2.multipolygon_end(idx)
    }
}

impl<P1: FeatureProcessor, P2: FeatureProcessor> PropertyProcessor for Multiplexer<P1, P2> {
    fn property(&mut self, i: usize, colname: &str, colval: &ColumnValue) -> Result<bool> {
        self.p1
            .property(i, colname, colval)
            .and(self.p2.property(i, colname, colval))
    }
}