Struct methods to &self, related changed to parse.

Cleaned up struct derives, comments, and variables in main.
This commit is contained in:
Kyle Kiteveles 2023-08-07 15:44:57 -04:00
parent 7baa168d8c
commit c15d1613b8
2 changed files with 46 additions and 30 deletions

View file

@ -9,7 +9,6 @@ fn main() {
let mut objects_filenames: Vec<String> = Vec::new();
let mut messages_filenames: Vec<String> = Vec::new();
let mut file_names: Vec<String> = Vec::new();
let mut text: Vec<String> = args[1..].to_vec();
let mut handles:Vec<JoinHandle<()>> = Vec::new();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
@ -20,7 +19,6 @@ fn main() {
file_names.push(arg.to_string());
objects_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_objects.rs");
messages_filenames.push(file_names.last().unwrap().trim_end_matches(".xml").to_string() + "_messages.rs");
handles.push(thread::spawn(move || {
println!("{:?}", arg);
if arg.to_string().contains(".xml") {
@ -118,10 +116,10 @@ fn parse(doc: &Document) -> oop::Family {
if f.value() ==real_family.get_name() {
for genus in real_family.get_genera().as_mut_slice() {
if let Some(g) = child2.attribute_node("genus") {
if g.value() == genus.clone().get_name() {
for species in genus.clone().get_species().as_mut_slice() {
if g.value() == genus.get_name() {
for species in genus.get_species().as_mut_slice() {
if let Some(s) = child2.attribute_node("species") {
if s.value() == species.clone().get_name() {
if s.value() == species.get_name() {
species.push_object(oop::Object::new(child2.attribute_node("class").unwrap().value().to_string(), child2.attribute_node("abrv").unwrap().value().to_string(), child2.attribute_node("version").unwrap().value().to_string(), Vec::new()))
}
}
@ -155,11 +153,11 @@ fn parse(doc: &Document) -> oop::Family {
if s.value() ==real_family.get_name(){
for genus in real_family.get_genera().as_mut_slice() {
if let Some(g) = child2.attribute_node("genus") {
if g.value() == genus.clone().get_name() {
for species in genus.clone().get_species().as_mut_slice() {
if g.value() == genus.get_name() {
for species in genus.get_species().as_mut_slice() {
if let Some(s) = child2.attribute_node("species") {
if s.value() == species.clone().get_name() {
for object in species.clone().get_objects().as_mut_slice() {
if s.value() == species.get_name() {
for object in species.get_objects().as_mut_slice() {
object.push_object_member(oop::ObjectMember::new(child4.attribute_node("type").unwrap().value().to_string(), child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("minversion").unwrap().value().to_string(), child4.attribute_node("maxversion").unwrap().value().to_string(), Vec::new()));
}
}
@ -196,19 +194,19 @@ fn parse(doc: &Document) -> oop::Family {
if f.value() ==real_family.get_name() {
for genus in real_family.get_genera().as_mut_slice() {
if let Some(g) = child2.attribute_node("genus") {
if g.value() == genus.clone().get_name() {
for species in genus.clone().get_species().as_mut_slice() {
if g.value() == genus.get_name() {
for species in genus.get_species().as_mut_slice() {
if let Some(s) = child2.attribute_node("species") {
if s.value() == species.clone().get_name() {
for object in species.clone().get_objects().as_mut_slice() {
for member in object.clone().get_members().as_mut_slice() {
if s.value() == species.get_name() {
for object in species.get_objects().as_mut_slice() {
for member in object.get_members().as_mut_slice() {
if let Some(m) = child3.attribute_node("name") {
if m.value() == member.clone().get_name() {
if m.value() == member.get_name() {
if child4.has_attribute("defaultvalue") {
member.clone().get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string()));
member.get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), child4.attribute_node("defaultvalue").unwrap().value().to_string()));
}
else {
member.clone().get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), String::new()));
member.get_enumerations().push(oop::MemberEnumeration::new(child4.attribute_node("name").unwrap().value().to_string(), String::new()));
}
}
}

View file

@ -25,16 +25,17 @@ impl Family {
return self.name.clone()
}
pub fn set_name(&mut self, name: String){
/*pub fn set_name(&mut self, name: String){
if self.name.len() == 0 {
self.name = name
}
}*/
pub fn get_genera(&mut self) -> &mut Vec<Genus>{
return &mut self.genera
}
pub fn get_genera(&self) -> Vec<Genus>{
return self.genera.clone()
}
#[allow(unused)]
pub fn get_messages(&self) -> Vec<Vec<String>>{
return self.messages.clone()
}
@ -67,8 +68,8 @@ impl Genus {
return self.name.clone()
}
pub fn get_species(&self) -> Vec<Species>{
return self.species.clone()
pub fn get_species(&mut self) -> &mut Vec<Species>{
return &mut self.species
}
pub fn push_species(&mut self, species: Species) {
@ -92,12 +93,13 @@ impl Species {
return self.name.clone()
}
#[allow(unused)]
pub fn get_default_value(&self) -> String{
return self.default_value.clone()
}
pub fn get_objects(&self) -> Vec<Object>{
return self.objects.clone()
pub fn get_objects(&mut self) -> &mut Vec<Object>{
return &mut self.objects
}
pub fn push_object(&mut self, object: Object) {
@ -118,20 +120,24 @@ impl Object {
Self { name, abrv, version, members }
}
#[allow(unused)]
pub fn get_name(&self) -> String{
return self.name.clone()
}
#[allow(unused)]
pub fn get_abrv(&self) -> String{
return self.abrv.clone()
}
#[allow(unused)]
pub fn get_version(&self) -> String{
return self.version.clone()
}
pub fn get_members(&self) -> Vec<ObjectMember>{
return self.members.clone()
#[allow(unused)]
pub fn get_members(&mut self) -> &mut Vec<ObjectMember>{
return &mut self.members
}
pub fn push_object_member(&mut self, member: ObjectMember) {
@ -157,22 +163,27 @@ impl ObjectMember {
return self.name.clone()
}
#[allow(unused)]
pub fn get_member_type(&self) -> String{
return self.member_type.clone()
}
#[allow(unused)]
pub fn get_minversion(&self) -> String{
return self.minversion.clone()
}
#[allow(unused)]
pub fn get_maxversion(&self) -> String{
return self.maxversion.clone()
}
pub fn get_enumerations(&self) -> Vec<MemberEnumeration>{
return self.enumerations.clone()
#[allow(unused)]
pub fn get_enumerations(&mut self) -> &mut Vec<MemberEnumeration>{
return &mut self.enumerations
}
#[allow(unused)]
pub fn push_member_enumeration(&mut self, enumeration: MemberEnumeration) {
self.enumerations.push(enumeration);
}
@ -189,10 +200,12 @@ impl MemberEnumeration {
Self { name, default_value }
}
#[allow(unused)]
pub fn get_name(&self) -> String{
return self.name.clone()
}
#[allow(unused)]
pub fn get_default_value(&self) -> String{
return self.default_value.clone()
}
@ -213,22 +226,27 @@ impl Messages {
Self { requests, responses, commands, statuses, streams, error: String::from("") }
}
#[allow(unused)]
pub fn get_requests(&self) -> Vec<String>{
return self.requests.clone()
}
#[allow(unused)]
pub fn get_responses(&self) -> Vec<String>{
return self.responses.clone()
}
#[allow(unused)]
pub fn get_commands(&self) -> Vec<String>{
return self.commands.clone()
}
#[allow(unused)]
pub fn get_statuses(&self) -> Vec<String>{
return self.statuses.clone()
}
#[allow(unused)]
pub fn get_streams(&self) -> Vec<String>{
return self.streams.clone()
}