Skip to main content

JMapInfo

Struct JMapInfo 

Source
pub struct JMapInfo<H: HashTable> { /* private fields */ }
Expand description

The main JMap that holds fields and entries. So basically the in-memory representation of a BCSV file

This is a table-like structure where each field represents a column and each entry represents a row of data

Basically implemented what i see on this page

Implementations§

Source§

impl<H: HashTable> JMapInfo<H>

Source

pub fn new(hash_table: H) -> Self

Create a new empty JMapInfo with the given hash table

§Arguments
  • hash_table - The hash table to use for field name lookups
Source

pub fn hash_table(&self) -> &H

Get a reference to the hash table

Source

pub fn hash_table_mut(&mut self) -> &mut H

Get a mutable reference to the hash table

Source

pub fn num_fields(&self) -> usize

Get the number of fields (columns)

Examples found in repository?
examples/write_bcsv.rs (line 15)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let csv_path = Path::new("assets/examples/scenariodata.csv");
11    let jmap = from_csv(hash_table, csv_path, None)?;
12
13    println!("CSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    to_file(&jmap, "test_output.bcsv", &IoOptions::default())?;
19    println!("\nExported to test_output.bcsv");
20
21    Ok(())
22}
More examples
Hide additional examples
examples/read_bcsv.rs (line 15)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let bcsv_path = Path::new("assets/examples/scenariodata.bcsv");
11    let jmap = from_file(hash_table, bcsv_path, &IoOptions::default())?;
12
13    println!("BCSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    println!("Fields");
19    for field in jmap.fields() {
20        let name = jmap.field_name(field.hash);
21        println!("+0x{:X} - {} - {}", field.offset, name, field.field_type);
22    }
23    println!();
24
25    to_csv(&jmap, "test_output.csv", None)?;
26    println!("\nExported to test_output.csv");
27
28    Ok(())
29}
Source

pub fn len(&self) -> usize

Get the number of entries (rows)

Examples found in repository?
examples/write_bcsv.rs (line 14)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let csv_path = Path::new("assets/examples/scenariodata.csv");
11    let jmap = from_csv(hash_table, csv_path, None)?;
12
13    println!("CSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    to_file(&jmap, "test_output.bcsv", &IoOptions::default())?;
19    println!("\nExported to test_output.bcsv");
20
21    Ok(())
22}
More examples
Hide additional examples
examples/read_bcsv.rs (line 14)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let bcsv_path = Path::new("assets/examples/scenariodata.bcsv");
11    let jmap = from_file(hash_table, bcsv_path, &IoOptions::default())?;
12
13    println!("BCSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    println!("Fields");
19    for field in jmap.fields() {
20        let name = jmap.field_name(field.hash);
21        println!("+0x{:X} - {} - {}", field.offset, name, field.field_type);
22    }
23    println!();
24
25    to_csv(&jmap, "test_output.csv", None)?;
26    println!("\nExported to test_output.csv");
27
28    Ok(())
29}
Source

pub fn is_empty(&self) -> bool

Check if entries are empty

Source

pub fn fields(&self) -> impl Iterator<Item = &Field>

Get an iterator over all fields

Examples found in repository?
examples/read_bcsv.rs (line 19)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let bcsv_path = Path::new("assets/examples/scenariodata.bcsv");
11    let jmap = from_file(hash_table, bcsv_path, &IoOptions::default())?;
12
13    println!("BCSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    println!("Fields");
19    for field in jmap.fields() {
20        let name = jmap.field_name(field.hash);
21        println!("+0x{:X} - {} - {}", field.offset, name, field.field_type);
22    }
23    println!();
24
25    to_csv(&jmap, "test_output.csv", None)?;
26    println!("\nExported to test_output.csv");
27
28    Ok(())
29}
Source

pub fn field_hashes(&self) -> impl Iterator<Item = &u32>

Get an iterator over all field hashes

Source

pub fn get_field_by_hash(&self, hash: u32) -> Option<&Field>

Get a field by hash

Source

pub fn get_field(&self, name: &str) -> Option<&Field>

Get a field by name

Source

pub fn contains_field_hash(&self, hash: u32) -> bool

Check if a field exists by hash

Source

pub fn contains_field(&self, name: &str) -> bool

Check if a field exists by name

Source

pub fn field_name(&self, hash: u32) -> String

Get the name of a field by its hash

Examples found in repository?
examples/read_bcsv.rs (line 20)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let lookup_path = Path::new("assets/strings_SMG.txt");
8    let hash_table = smg_hash_table_with_lookup(lookup_path)?;
9
10    let bcsv_path = Path::new("assets/examples/scenariodata.bcsv");
11    let jmap = from_file(hash_table, bcsv_path, &IoOptions::default())?;
12
13    println!("BCSV Info");
14    println!("Entries: {}", jmap.len());
15    println!("Fields: {}", jmap.num_fields());
16    println!();
17
18    println!("Fields");
19    for field in jmap.fields() {
20        let name = jmap.field_name(field.hash);
21        println!("+0x{:X} - {} - {}", field.offset, name, field.field_type);
22    }
23    println!();
24
25    to_csv(&jmap, "test_output.csv", None)?;
26    println!("\nExported to test_output.csv");
27
28    Ok(())
29}
Source

pub fn create_field( &mut self, name: &str, field_type: FieldType, default: FieldValue, ) -> Result<()>

Create a new field with the given name and type

§Arguments
  • name - The name of the field to create
  • field_type - The type of the field to create
  • default - The default value for the field to create
§Errors
  • JMapError::TypeMismatch if the default value is not compatible with the field type
  • JMapError::FieldAlreadyExists if a field with the same name already exists
§Returns

Ok(()) if the field was created successfully, or an error if the field could not be created

Source

pub fn drop_field(&mut self, name: &str) -> Result<()>

Remove a field from the container

§Arguments
  • name - The name of the field to remove
§Errors
  • JMapError::FieldNotFound if the field does not exist
§Returns

Ok(()) if the field was removed successfully, or an error if the field could not be found

Source

pub fn entries(&self) -> &[Entry]

Get a slice of all entries

Source

pub fn entries_mut(&mut self) -> &mut [Entry]

Get a mutable slice of all entries

Source

pub fn get_entry(&self, index: usize) -> Option<&Entry>

Get an entry by index

Source

pub fn get_entry_mut(&mut self, index: usize) -> Option<&mut Entry>

Get a mutable entry by index

Source

pub fn create_entry(&mut self) -> &mut Entry

Create a new entry with default values for all fields

Source

pub fn remove_entry(&mut self, index: usize) -> Result<Entry>

Remove an entry by index

§Arguments
  • index - The index of the entry to remove
§Errors
  • JMapError::EntryIndexOutOfBounds if the index is out of bounds
§Returns

Ok(Entry) if the entry was removed successfully, or an error if the index was out of bounds

Source

pub fn clear_entries(&mut self)

Clear all entries but keep the field definitions

Source

pub fn sort_entries_by<F, K>(&mut self, f: F)
where F: FnMut(&Entry) -> K, K: Ord,

Sort entries by a custom key function

§Arguments
  • f - The key function to sort by
§Types
  • F - The type of the key function, which must be a function that takes a reference to an Entry and returns a key of type K
  • K - The type of the key returned by the key function, which must implement the Ord trait for sorting
Source

pub fn iter(&self) -> impl Iterator<Item = &Entry>

Iterate over entries

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Entry>

Iterate over entries mutably

Trait Implementations§

Source§

impl<H: Debug + HashTable> Debug for JMapInfo<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, H: HashTable> IntoIterator for &'a JMapInfo<H>

Implement IntoIterator for references to JMapInfo to allow iterating over entries by reference

§Types

  • H - The type of the hash table used by the JMapInfo, which must implement the HashTable trait

§Lifetime

  • 'a - The lifetime of the reference to the JMapInfo
Source§

type Item = &'a Entry

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, H: HashTable> IntoIterator for &'a mut JMapInfo<H>

Source§

type Item = &'a mut Entry

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<H: HashTable> IntoIterator for JMapInfo<H>

Implement IntoIterator for JMapInfo to allow iterating over entries directly This allows using for entry in jmap syntax to iterate over entries, as well as iterating over references and mutable references to JMapInfo The item type is Entry for owned iteration, &Entry for reference iteration, and &mut Entry for mutable reference iteration

Source§

type Item = Entry

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<H> Freeze for JMapInfo<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for JMapInfo<H>
where H: RefUnwindSafe,

§

impl<H> Send for JMapInfo<H>
where H: Send,

§

impl<H> Sync for JMapInfo<H>
where H: Sync,

§

impl<H> Unpin for JMapInfo<H>
where H: Unpin,

§

impl<H> UnwindSafe for JMapInfo<H>
where H: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.