diff --git a/src/bib_manager.rs b/src/bib_manager.rs new file mode 100644 index 0000000..bb0a8c7 --- /dev/null +++ b/src/bib_manager.rs @@ -0,0 +1,31 @@ +use std::sync::{Arc, Mutex}; +use crate::references::anchor::BibListAnchor; +use crate::bibliography::bibliography_dict::BibliographyDictionary; + +/// The root manager for that should be used for further reference operations that +/// go beyond insertion. +#[derive(Clone, Debug)] +pub struct BibManager { + root_ref_anchor: Arc>, + entry_dictionary: Arc>, +} + +impl BibManager { + /// Creates a new BibRefManager with an empty root anchor + pub fn new() -> Self { + Self { + root_ref_anchor: Arc::new(Mutex::new(BibListAnchor::new())), + entry_dictionary: Arc::new(Mutex::new(BibliographyDictionary::new())), + } + } + + /// Returns the BibRefManagers root anchor that. + pub fn root_ref_anchor(&self) -> Arc> { + Arc::clone(&self.root_ref_anchor) + } + + /// Returns the reference to the entry dictionary + pub fn entry_dictionary(&self) -> Arc> { + Arc::clone(&self.entry_dictionary) + } +} \ No newline at end of file diff --git a/src/bibliography/bib_types/mod.rs b/src/bibliography/bib_types/mod.rs new file mode 100644 index 0000000..3c99498 --- /dev/null +++ b/src/bibliography/bib_types/mod.rs @@ -0,0 +1,16 @@ +/// A type of bibliography entry +#[derive(Clone, Debug)] +pub enum BibliographyType { + Article, + Book, + Booklet, + InBook, + InCollection, + Manual, + Thesis, + TechReport, + Unpublished, + Misc, + Url, + Repository, +} \ No newline at end of file diff --git a/src/bibliography/bibliography_dict.rs b/src/bibliography/bibliography_dict.rs new file mode 100644 index 0000000..dca3361 --- /dev/null +++ b/src/bibliography/bibliography_dict.rs @@ -0,0 +1,35 @@ +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; +use crate::bibliography::bibliography_entry::{BibliographyEntryReference, BibliographyEntry}; + +/// A dictionary that contains all bibliography entries +#[derive(Clone, Debug)] +pub struct BibliographyDictionary { + entries: HashMap, +} + + +impl BibliographyDictionary { + /// Creates a new empty BibliographyDictionary + pub fn new() -> Self { + Self { + entries: HashMap::new(), + } + } + + /// Inserts a bibliography entry into the map + pub fn insert(&mut self, entry: BibliographyEntry) { + self.entries.insert(entry.key(), Arc::new(Mutex::new(entry))); + } + + /// Returns the reference to the bibliography entry with the given key + pub fn get(&mut self, key: &str) -> Option { + if let Some(entry) = self.entries.get(&key.to_string()) { + Some(Arc::clone(entry)) + } else { + None + } + } +} + + diff --git a/src/bibliography/bibliography_entry.rs b/src/bibliography/bibliography_entry.rs new file mode 100644 index 0000000..36295a1 --- /dev/null +++ b/src/bibliography/bibliography_entry.rs @@ -0,0 +1,30 @@ +use std::sync::{Arc, Mutex}; +use crate::bibliography::bib_types::BibliographyType; + +/// A single bibliography entry +#[derive(Clone, Debug)] +pub struct BibliographyEntry { + key: String, + note: Option, + bib_type: BibliographyType, +} + +pub type BibliographyEntryReference = Arc>; + + +impl BibliographyEntry { + /// Creates a new bibliography entry with the given key + pub fn new(key: String) -> Self { + Self { + key, + note: None, + bib_type: BibliographyType::Misc, + } + } + + /// Returns the key of the bibliography entry + pub fn key(&self) -> String { + self.key.clone() + } +} + diff --git a/src/bibliography/mod.rs b/src/bibliography/mod.rs new file mode 100644 index 0000000..bcb8a62 --- /dev/null +++ b/src/bibliography/mod.rs @@ -0,0 +1,3 @@ +pub mod bibliography_entry; +pub mod bibliography_dict; +pub mod bib_types; \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f03d154..5700712 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,16 @@ pub mod references; +pub mod bibliography; +pub mod bib_manager; #[cfg(test)] mod tests { - use crate::references::reference_manager::BibRefManager; use crate::references::bib_reference::BibRef; + use crate::bib_manager::BibManager; #[test] fn it_inserts_and_flattens() { - let manager = BibRefManager::new(); - let root_anchor = manager.root_anchor(); + let manager = BibManager::new(); + let root_anchor = manager.root_ref_anchor(); let mut root_anchor = root_anchor.lock().unwrap(); root_anchor.insert(BibRef::new("test".to_string())); let child_anchor = root_anchor.create_anchor(); diff --git a/src/references/bib_reference.rs b/src/references/bib_reference.rs index 854139e..a07d57c 100644 --- a/src/references/bib_reference.rs +++ b/src/references/bib_reference.rs @@ -1,13 +1,31 @@ +use crate::bibliography::bibliography_entry::BibliographyEntryReference; +use std::sync::{Arc, Mutex}; + +/// A reference to a bibliography entry #[derive(Clone, Debug)] pub struct BibRef { key: String, + anchor: Arc>, +} + +/// An anchor of a BibRef that can be used in a DOM to remember the place of a BibRef +/// and to access the corresponding bibliography entry. +#[derive(Clone, Debug)] +pub struct BibRefAnchor { + entry: Option } impl BibRef { /// Creates a new BibRef with a given key pub fn new(key: String) -> Self { Self { - key + key, + anchor: Arc::new(Mutex::new(BibRefAnchor {entry: None})) } } + + /// Returns the anchor of the BibRef + pub fn anchor(&self) -> Arc> { + Arc::clone(&self.anchor) + } } \ No newline at end of file diff --git a/src/references/mod.rs b/src/references/mod.rs index 653240e..3c12e15 100644 --- a/src/references/mod.rs +++ b/src/references/mod.rs @@ -1,3 +1,2 @@ -pub mod reference_manager; pub mod bib_reference; pub mod anchor; \ No newline at end of file diff --git a/src/references/reference_manager.rs b/src/references/reference_manager.rs deleted file mode 100644 index 3b8b133..0000000 --- a/src/references/reference_manager.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::sync::{Arc, Mutex}; -use crate::references::anchor::BibListAnchor; - -/// The root manager for references that should be used for further reference operations that -/// go beyond insertion. -#[derive(Clone, Debug)] -pub struct BibRefManager { - root_anchor: Arc>, -} - -impl BibRefManager { - /// Creates a new BibRefManager with an empty root anchor - pub fn new() -> Self { - Self { - root_anchor: Arc::new(Mutex::new(BibListAnchor::new())) - } - } - - /// Returns the BibRefManagers root anchor that. - pub fn root_anchor(&self) -> Arc> { - Arc::clone(&self.root_anchor) - } -} \ No newline at end of file