Each file must have an owning module
This commit is contained in:
parent
90f08cc1f2
commit
09940f3228
1 changed files with 22 additions and 11 deletions
|
@ -2,7 +2,8 @@ use std::error::Error;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use super::parser::FileHeaderParser;
|
use module::Module;
|
||||||
|
use super::parser::{FileHeaderParser, Parser, ParserError};
|
||||||
use storage::file_id::*;
|
use storage::file_id::*;
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -200,16 +201,18 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData)
|
||||||
* Internal abstract view on a file. Does not exist on the FS and is just kept
|
* Internal abstract view on a file. Does not exist on the FS and is just kept
|
||||||
* internally until it is written to disk.
|
* internally until it is written to disk.
|
||||||
*/
|
*/
|
||||||
pub struct File {
|
pub struct File<'a> {
|
||||||
header : FileHeaderData,
|
owning_module : &'a Module,
|
||||||
data : String,
|
header : FileHeaderData,
|
||||||
id : FileID,
|
data : String,
|
||||||
|
id : FileID,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl<'a> File<'a> {
|
||||||
|
|
||||||
pub fn new() -> File {
|
pub fn new(module: &'a Module) -> File<'a> {
|
||||||
let f = File {
|
let f = File {
|
||||||
|
owning_module: module,
|
||||||
header: FileHeaderData::Null,
|
header: FileHeaderData::Null,
|
||||||
data: String::from(""),
|
data: String::from(""),
|
||||||
id: File::get_new_file_id(),
|
id: File::get_new_file_id(),
|
||||||
|
@ -218,8 +221,9 @@ impl File {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_parser_result(id: FileID, header: FileHeaderData, data: String) -> File {
|
pub fn from_parser_result(module: &Module, id: FileID, header: FileHeaderData, data: String) -> File {
|
||||||
let f = File {
|
let f = File {
|
||||||
|
owning_module: module,
|
||||||
header: header,
|
header: header,
|
||||||
data: data,
|
data: data,
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -228,8 +232,9 @@ impl File {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_header(h: FileHeaderData) -> File {
|
pub fn new_with_header(module: &Module, h: FileHeaderData) -> File {
|
||||||
let f = File {
|
let f = File {
|
||||||
|
owning_module: module,
|
||||||
header: h,
|
header: h,
|
||||||
data: String::from(""),
|
data: String::from(""),
|
||||||
id: File::get_new_file_id(),
|
id: File::get_new_file_id(),
|
||||||
|
@ -238,8 +243,9 @@ impl File {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_data(d: String) -> File {
|
pub fn new_with_data(module: &Module, d: String) -> File {
|
||||||
let f = File {
|
let f = File {
|
||||||
|
owning_module: module,
|
||||||
header: FileHeaderData::Null,
|
header: FileHeaderData::Null,
|
||||||
data: d,
|
data: d,
|
||||||
id: File::get_new_file_id(),
|
id: File::get_new_file_id(),
|
||||||
|
@ -248,8 +254,9 @@ impl File {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_content(h: FileHeaderData, d: String) -> File {
|
pub fn new_with_content(module: &Module, h: FileHeaderData, d: String) -> File {
|
||||||
let f = File {
|
let f = File {
|
||||||
|
owning_module: module,
|
||||||
header: h,
|
header: h,
|
||||||
data: d,
|
data: d,
|
||||||
id: File::get_new_file_id(),
|
id: File::get_new_file_id(),
|
||||||
|
@ -274,6 +281,10 @@ impl File {
|
||||||
self.id.clone()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn owner(&self) -> &Module {
|
||||||
|
self.owning_module
|
||||||
|
}
|
||||||
|
|
||||||
pub fn matches_with(&self, r: &Regex) -> bool {
|
pub fn matches_with(&self, r: &Regex) -> bool {
|
||||||
r.is_match(&self.data[..]) || self.header.matches_with(r)
|
r.is_match(&self.data[..]) || self.header.matches_with(r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue