139 lines
2.6 KiB
Rust
139 lines
2.6 KiB
Rust
//! Map model.
|
|
|
|
use crate::qintr::*;
|
|
//use memmap::Mmap;
|
|
use maraiah::map;
|
|
|
|
pub struct MapModel
|
|
{
|
|
emit: MapModelEmitter,
|
|
model: MapModelTree,
|
|
}
|
|
|
|
impl Drop for MapModel
|
|
{
|
|
fn drop(&mut self)
|
|
{
|
|
if cfg!(debug_assertions) {
|
|
eprintln!("drop MapModel");
|
|
}
|
|
}
|
|
}
|
|
|
|
impl MapModelTrait for MapModel
|
|
{
|
|
/// Returns a new `MapModel` instance.
|
|
fn new(emit: MapModelEmitter, model: MapModelTree) -> MapModel
|
|
{
|
|
if cfg!(debug_assertions) {
|
|
eprintln!("new MapModel");
|
|
}
|
|
|
|
MapModel{emit, model}
|
|
}
|
|
|
|
/// Returns the emitter of `self`.
|
|
fn emit(&mut self) -> &mut MapModelEmitter
|
|
{
|
|
&mut self.emit
|
|
}
|
|
|
|
/// Checks if `row` exists in the leaf `index`.
|
|
fn check_row(&self, index: usize, _row: usize) -> Option<usize>
|
|
{
|
|
None
|
|
}
|
|
|
|
/// Returns the row `index` is in.
|
|
fn row(&self, index: usize) -> usize
|
|
{
|
|
index
|
|
}
|
|
|
|
/// Returns the number of rows in `index`.
|
|
fn row_count(&self, index: Option<usize>) -> usize
|
|
{
|
|
match index {
|
|
Some(_) => 0,
|
|
None => 7,
|
|
}
|
|
}
|
|
|
|
/// Returns the leaf index of `row` in the leaf `index`.
|
|
fn index(&self, index: Option<usize>, row: usize) -> usize
|
|
{
|
|
match index {
|
|
Some(_) => unreachable!(),
|
|
None => row,
|
|
}
|
|
}
|
|
|
|
/// Returns the parent index of the leaf `index`, if any.
|
|
fn parent(&self, _index: usize) -> Option<usize>
|
|
{
|
|
// no parents!
|
|
None
|
|
}
|
|
|
|
fn row_name(&self, row: usize) -> u64
|
|
{
|
|
row as u64 + 1
|
|
}
|
|
|
|
fn some_number(&self, row: usize) -> u64
|
|
{
|
|
69420
|
|
}
|
|
|
|
/// Opens the map file at `path`.
|
|
fn open(&mut self, path: String) -> bool
|
|
{
|
|
if cfg!(debug_assertions) {
|
|
eprintln!("opening project: {}", &path);
|
|
}
|
|
|
|
/*
|
|
let fp = std::fs::File::open(path);
|
|
let fp = if let Ok(fp) = fp {fp} else {return false;};
|
|
|
|
let mm = unsafe {Mmap::map(&fp)};
|
|
let mm = if let Ok(mm) = mm {mm} else {return false;};
|
|
|
|
if let Ok(wad) = map::read(&mm) {
|
|
self.wad.replace(Some(wad));
|
|
return true;
|
|
}
|
|
*/
|
|
|
|
false
|
|
}
|
|
|
|
/// Saves the project into the original file.
|
|
fn save(&self) -> bool
|
|
{
|
|
if cfg!(debug_assertions) {
|
|
eprintln!("saving project");
|
|
}
|
|
|
|
false
|
|
}
|
|
|
|
/// Saves the project into `path`.
|
|
fn save_as(&self, path: String) -> bool
|
|
{
|
|
if cfg!(debug_assertions) {
|
|
eprintln!("saving project as {}", path);
|
|
}
|
|
|
|
false
|
|
}
|
|
|
|
/// Returns `true` if the file has been modified from its original state.
|
|
fn is_dirty(&self) -> bool
|
|
{
|
|
false
|
|
}
|
|
}
|
|
|
|
// EOF
|