diff --git a/libdonet/src/dcarray.rs b/libdonet/src/dcarray.rs index 36108d4..1abffdd 100644 --- a/libdonet/src/dcarray.rs +++ b/libdonet/src/dcarray.rs @@ -20,7 +20,7 @@ use crate::dctype::{DCTypeDefinition, DCTypeDefinitionInterface, DCTypeEnum}; use crate::hashgen::DCHashGenerator; pub struct DCArrayType { - parent: DCTypeDefinition, + _dcarray_parent: DCTypeDefinition, element_type: Option, array_size: u16, array_range: Option, @@ -40,7 +40,7 @@ pub trait DCArrayTypeInterface { impl DCArrayTypeInterface for DCArrayType { fn new(element_type: Option, size: Option) -> Self { let mut new_array_type: Self = Self { - parent: DCTypeDefinition::new(), + _dcarray_parent: DCTypeDefinition::new(), element_type: element_type, array_size: 0_u16, array_range: size, @@ -137,11 +137,11 @@ impl DCArrayTypeInterface for DCArrayType { impl std::ops::Deref for DCArrayType { type Target = DCTypeDefinition; fn deref(&self) -> &Self::Target { - &self.parent + &self._dcarray_parent } } impl std::ops::DerefMut for DCArrayType { fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.parent + &mut self._dcarray_parent } } diff --git a/libdonet/src/dcatomic.rs b/libdonet/src/dcatomic.rs new file mode 100644 index 0000000..570c834 --- /dev/null +++ b/libdonet/src/dcatomic.rs @@ -0,0 +1,30 @@ +// DONET SOFTWARE +// Copyright (c) 2024, Donet Authors. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License version 3. +// You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use crate::dcfield::DCField; + +struct DCAtomicField { + _dcatomicfield_parent: DCField, +} + +/// See issue #22. +impl std::ops::Deref for DCAtomicField { + type Target = DCField; + fn deref(&self) -> &Self::Target { + &self._dcatomicfield_parent + } +} diff --git a/libdonet/src/dcfield.rs b/libdonet/src/dcfield.rs index 9f40737..567c29e 100644 --- a/libdonet/src/dcfield.rs +++ b/libdonet/src/dcfield.rs @@ -15,20 +15,26 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +use crate::datagram::Datagram; use crate::dckeyword::{DCKeywordList, DCKeywordListInterface, IdentifyKeyword}; use crate::dclass::DClass; use crate::dcstruct::DCStruct; +use crate::dctype::{DCTypeDefinition, DCTypeDefinitionInterface}; use crate::globals; use crate::hashgen::DCHashGenerator; use std::sync::{Arc, Mutex}; +/// A field of a Distributed Class. The DCField struct is a base for +/// struct and dclass fields. In the DC language, there are three types +/// of field declarations, which are: parameter, atomic, and molecular. #[derive(Debug)] pub struct DCField { - parent: DCKeywordList, - class: Option>>, + _dcfield_parent: DCKeywordList, + dclass: Option>>, _struct: Option>>, // needs '_' due to reserved keyword field_name: String, field_id: globals::FieldId, + field_type: DCTypeDefinition, parent_is_dclass: bool, default_value_stale: bool, has_default_value: bool, @@ -38,14 +44,21 @@ pub struct DCField { pub trait DCFieldInterface { fn new(name: &str, id: globals::FieldId) -> Self; - fn generate_hash(&self, hashgen: &mut DCHashGenerator); + fn dcfield_generate_hash(&self, hashgen: &mut DCHashGenerator); + + fn get_field_id(&self) -> globals::FieldId; + fn get_dclass(&self) -> Arc>; fn set_field_id(&mut self, id: globals::FieldId); fn set_field_name(&mut self, name: String); + fn set_default_value(&mut self, value: Vec); fn set_parent_struct(&mut self, parent: Arc>); fn set_parent_dclass(&mut self, parent: Arc>); + fn has_default_value(&self) -> bool; + fn validate_ranges(&self, packed_data: &Datagram) -> bool; + // Inline functions for Panda historical keywords fn is_required(&self) -> bool; fn is_broadcast(&self) -> bool; @@ -58,14 +71,21 @@ pub trait DCFieldInterface { fn is_airecv(&self) -> bool; } +impl DCField { + fn refresh_default_value(&self) { + todo!() + } +} + impl DCFieldInterface for DCField { fn new(name: &str, id: globals::FieldId) -> Self { Self { - parent: DCKeywordList::new(), - class: None, + _dcfield_parent: DCKeywordList::new(), + dclass: None, _struct: None, field_name: name.to_owned(), field_id: id, + field_type: DCTypeDefinition::new(), parent_is_dclass: false, default_value_stale: false, has_default_value: false, @@ -74,11 +94,19 @@ impl DCFieldInterface for DCField { } } - fn generate_hash(&self, hashgen: &mut DCHashGenerator) { + fn dcfield_generate_hash(&self, hashgen: &mut DCHashGenerator) { self.dckeywordlist_generate_hash(hashgen); // TODO! } + fn get_field_id(&self) -> globals::FieldId { + todo!() + } + + fn get_dclass(&self) -> Arc> { + todo!() + } + #[inline(always)] fn set_field_id(&mut self, id: globals::FieldId) { self.field_id = id @@ -89,6 +117,10 @@ impl DCFieldInterface for DCField { self.field_name = name } + fn set_default_value(&mut self, value: Vec) { + todo!() + } + fn set_parent_struct(&mut self, parent: Arc>) { todo!() } @@ -97,6 +129,14 @@ impl DCFieldInterface for DCField { todo!() } + fn has_default_value(&self) -> bool { + todo!() + } + + fn validate_ranges(&self, packed_data: &Datagram) -> bool { + todo!() + } + #[inline(always)] fn is_required(&self) -> bool { self.has_keyword(IdentifyKeyword::ByName("required".to_owned())) @@ -148,6 +188,6 @@ impl DCFieldInterface for DCField { impl std::ops::Deref for DCField { type Target = DCKeywordList; fn deref(&self) -> &Self::Target { - &self.parent + &self._dcfield_parent } } diff --git a/libdonet/src/dclass.rs b/libdonet/src/dclass.rs index a858838..7360f71 100644 --- a/libdonet/src/dclass.rs +++ b/libdonet/src/dclass.rs @@ -46,8 +46,8 @@ pub trait DClassInterface { fn set_parent(&mut self, parent: Arc>); fn get_name(&mut self) -> String; - fn get_class_id(&mut self) -> globals::DClassId; - fn set_class_id(&mut self, id: globals::DClassId); + fn get_dclass_id(&mut self) -> globals::DClassId; + fn set_dclass_id(&mut self, id: globals::DClassId); fn get_num_parents(&mut self) -> usize; fn get_parent(&mut self, index: usize) -> Option>>; fn has_constructor(&mut self) -> bool; @@ -82,11 +82,11 @@ impl DClassInterface for DClass { self.class_name.clone() } - fn get_class_id(&mut self) -> globals::DClassId { + fn get_dclass_id(&mut self) -> globals::DClassId { self.class_id } - fn set_class_id(&mut self, id: globals::DClassId) { + fn set_dclass_id(&mut self, id: globals::DClassId) { self.class_id = id; } diff --git a/libdonet/src/dcmolecular.rs b/libdonet/src/dcmolecular.rs new file mode 100644 index 0000000..344b23c --- /dev/null +++ b/libdonet/src/dcmolecular.rs @@ -0,0 +1,30 @@ +// DONET SOFTWARE +// Copyright (c) 2024, Donet Authors. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License version 3. +// You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use crate::dcfield::DCField; + +struct DCMolecularField { + _dcmolecularfield_parent: DCField, +} + +/// See issue #22. +impl std::ops::Deref for DCMolecularField { + type Target = DCField; + fn deref(&self) -> &Self::Target { + &self._dcmolecularfield_parent + } +} diff --git a/libdonet/src/dcnumeric.rs b/libdonet/src/dcnumeric.rs index 7f1f030..3fe77d4 100644 --- a/libdonet/src/dcnumeric.rs +++ b/libdonet/src/dcnumeric.rs @@ -100,7 +100,7 @@ impl DCNumericRange { // ---------- Numeric Type ---------- // pub struct DCNumericType { - parent: DCTypeDefinition, + _dcnumeric_parent: DCTypeDefinition, divisor: u16, // These are the original range and modulus values from the file, unscaled by the divisor. orig_modulus: f64, @@ -161,7 +161,7 @@ impl DCNumericType { impl DCNumericTypeInterface for DCNumericType { fn new(base_type: DCTypeEnum) -> Self { Self { - parent: { + _dcnumeric_parent: { let mut parent_struct = DCTypeDefinition::new(); parent_struct.data_type = base_type; @@ -269,6 +269,6 @@ impl DCNumericTypeInterface for DCNumericType { impl std::ops::Deref for DCNumericType { type Target = DCTypeDefinition; fn deref(&self) -> &Self::Target { - &self.parent + &self._dcnumeric_parent } } diff --git a/libdonet/src/dcparameter.rs b/libdonet/src/dcparameter.rs new file mode 100644 index 0000000..b2d035b --- /dev/null +++ b/libdonet/src/dcparameter.rs @@ -0,0 +1,30 @@ +// DONET SOFTWARE +// Copyright (c) 2024, Donet Authors. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License version 3. +// You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use crate::dcfield::DCField; + +struct DCParameterField { + _dcparameterfield_parent: DCField, +} + +/// See issue #22. +impl std::ops::Deref for DCParameterField { + type Target = DCField; + fn deref(&self) -> &Self::Target { + &self._dcparameterfield_parent + } +} diff --git a/libdonet/src/dcparser.rs b/libdonet/src/dcparser.rs index 5001541..bac47ca 100644 --- a/libdonet/src/dcparser.rs +++ b/libdonet/src/dcparser.rs @@ -97,7 +97,7 @@ parser! { use dclass::DClassInterface; let next_class_id: usize = dc_file.get_num_dclasses(); - dclass.set_class_id(next_class_id.try_into().unwrap()); + dclass.set_dclass_id(next_class_id.try_into().unwrap()); dc_file.add_dclass(dclass); }, diff --git a/libdonet/src/dctype.rs b/libdonet/src/dctype.rs index 07dba1f..46d61a8 100644 --- a/libdonet/src/dctype.rs +++ b/libdonet/src/dctype.rs @@ -23,7 +23,7 @@ use strum_macros::EnumIs; * to keep compatibility with Astron's DC hash inputs. */ #[repr(u8)] // 8-bit alignment, unsigned -#[derive(Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq)] #[rustfmt::skip] pub enum DCTypeEnum { // Numeric Types @@ -43,7 +43,7 @@ pub enum DCTypeEnum { TInvalid = 21, } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct DCTypeDefinition { alias: Option, pub data_type: DCTypeEnum, diff --git a/libdonet/src/lib.rs b/libdonet/src/lib.rs index ab03ef7..b01ac75 100644 --- a/libdonet/src/lib.rs +++ b/libdonet/src/lib.rs @@ -59,12 +59,15 @@ cfg_if! { cfg_if! { if #[cfg(feature = "dcfile")] { pub mod dcarray; + pub mod dcatomic; pub mod dcfield; pub mod dcfile; pub mod dckeyword; pub mod dclass; pub mod dclexer; + pub mod dcmolecular; pub mod dcnumeric; + pub mod dcparameter; pub mod dcparser; pub mod dcstruct; pub mod dctype;