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>
impl<H: HashTable> JMapInfo<H>
Sourcepub fn new(hash_table: H) -> Self
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
Sourcepub fn hash_table(&self) -> &H
pub fn hash_table(&self) -> &H
Get a reference to the hash table
Sourcepub fn hash_table_mut(&mut self) -> &mut H
pub fn hash_table_mut(&mut self) -> &mut H
Get a mutable reference to the hash table
Sourcepub fn num_fields(&self) -> usize
pub fn num_fields(&self) -> usize
Get the number of fields (columns)
Examples found in repository?
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
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}Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the number of entries (rows)
Examples found in repository?
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
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}Sourcepub fn fields(&self) -> impl Iterator<Item = &Field>
pub fn fields(&self) -> impl Iterator<Item = &Field>
Get an iterator over all fields
Examples found in repository?
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}Sourcepub fn field_hashes(&self) -> impl Iterator<Item = &u32>
pub fn field_hashes(&self) -> impl Iterator<Item = &u32>
Get an iterator over all field hashes
Sourcepub fn get_field_by_hash(&self, hash: u32) -> Option<&Field>
pub fn get_field_by_hash(&self, hash: u32) -> Option<&Field>
Get a field by hash
Sourcepub fn contains_field_hash(&self, hash: u32) -> bool
pub fn contains_field_hash(&self, hash: u32) -> bool
Check if a field exists by hash
Sourcepub fn contains_field(&self, name: &str) -> bool
pub fn contains_field(&self, name: &str) -> bool
Check if a field exists by name
Sourcepub fn field_name(&self, hash: u32) -> String
pub fn field_name(&self, hash: u32) -> String
Get the name of a field by its hash
Examples found in repository?
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}Sourcepub fn create_field(
&mut self,
name: &str,
field_type: FieldType,
default: FieldValue,
) -> Result<()>
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 createfield_type- The type of the field to createdefault- The default value for the field to create
§Errors
JMapError::TypeMismatchif the default value is not compatible with the field typeJMapError::FieldAlreadyExistsif 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
Sourcepub fn drop_field(&mut self, name: &str) -> Result<()>
pub fn drop_field(&mut self, name: &str) -> Result<()>
Sourcepub fn entries_mut(&mut self) -> &mut [Entry]
pub fn entries_mut(&mut self) -> &mut [Entry]
Get a mutable slice of all entries
Sourcepub fn get_entry_mut(&mut self, index: usize) -> Option<&mut Entry>
pub fn get_entry_mut(&mut self, index: usize) -> Option<&mut Entry>
Get a mutable entry by index
Sourcepub fn create_entry(&mut self) -> &mut Entry
pub fn create_entry(&mut self) -> &mut Entry
Create a new entry with default values for all fields
Sourcepub fn remove_entry(&mut self, index: usize) -> Result<Entry>
pub fn remove_entry(&mut self, index: usize) -> Result<Entry>
Sourcepub fn clear_entries(&mut self)
pub fn clear_entries(&mut self)
Clear all entries but keep the field definitions
Sourcepub fn sort_entries_by<F, K>(&mut self, f: F)
pub fn sort_entries_by<F, K>(&mut self, f: F)
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 anEntryand returns a key of typeKK- The type of the key returned by the key function, which must implement theOrdtrait for sorting
Trait Implementations§
Source§impl<'a, H: HashTable> IntoIterator for &'a JMapInfo<H>
Implement IntoIterator for references to JMapInfo to allow iterating over entries by reference
impl<'a, H: HashTable> IntoIterator for &'a JMapInfo<H>
Implement IntoIterator for references to JMapInfo to allow iterating over entries by reference
Source§impl<'a, H: HashTable> IntoIterator for &'a mut JMapInfo<H>
impl<'a, H: HashTable> IntoIterator for &'a mut JMapInfo<H>
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
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