Skip to content

Commit

Permalink
libdonet: Split DC elements from dcfile.rs to independent files
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrdz committed Dec 5, 2023
1 parent 545784b commit 31722ae
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 31 deletions.
44 changes: 44 additions & 0 deletions libdonet/src/dcfield.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// DONET SOFTWARE
// Copyright (c) 2023, 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::dclass::DClass;
use crate::dcstruct::DCStruct;
use crate::globals;
use std::sync::{Arc, Mutex}; // thread safe

// --------- Field ---------- //

pub struct DCField {
class: Option<Arc<Mutex<DClass>>>,
_struct: Option<Arc<Mutex<DCStruct>>>,
field_name: String,
field_id: globals::FieldId,
parent_is_dclass: bool,
default_value_stale: bool,
has_default_value: bool,
default_value: Vec<u8>, // stored as byte array
bogus_field: bool,
}

pub trait DCFieldInterface {
fn new(name: &str, id: globals::FieldId) -> Self;
fn generate_hash(&mut self);
fn set_field_id(&mut self, id: globals::FieldId);
fn set_field_name(&mut self, name: String);
fn set_parent_struct(&mut self, parent: Arc<Mutex<DCStruct>>);
fn set_parent_dclass(&mut self, parent: Arc<Mutex<DClass>>);
}
32 changes: 2 additions & 30 deletions libdonet/src/dcfile.rs → libdonet/src/dclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,10 @@
// 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;
use crate::globals;
use multimap::MultiMap;
use std::sync::{Arc, Mutex}; // thread safe

// --------- Field ---------- //

pub struct DCField {
class: Option<Arc<Mutex<DClass>>>,
_struct: Option<Arc<Mutex<DCStruct>>>,
field_name: String,
field_id: globals::FieldId,
parent_is_dclass: bool,
default_value_stale: bool,
has_default_value: bool,
default_value: Vec<u8>, // stored as byte array
bogus_field: bool,
}

pub trait DCFieldInterface {
fn new(name: &str, id: globals::FieldId) -> Self;
fn generate_hash(&mut self);
fn set_field_id(&mut self, id: globals::FieldId);
fn set_field_name(&mut self, name: String);
fn set_parent_struct(&mut self, parent: Arc<Mutex<DCStruct>>);
fn set_parent_dclass(&mut self, parent: Arc<Mutex<DClass>>);
}

// ---------- Struct ---------- //

pub struct DCStruct {}

// ---------- DClass ---------- //
use std::sync::{Arc, Mutex};

pub type FieldName2Field = MultiMap<String, Arc<Mutex<DCField>>>;
pub type FieldIndex2Field = MultiMap<globals::FieldId, Arc<Mutex<DCField>>>;
Expand Down
18 changes: 18 additions & 0 deletions libdonet/src/dcstruct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// DONET SOFTWARE
// Copyright (c) 2023, 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.

pub struct DCStruct {}
4 changes: 3 additions & 1 deletion libdonet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

pub mod byte_order;
pub mod datagram;
pub mod dcfile;
pub mod dcfield;
pub mod dclass;
pub mod dclexer;
pub mod dcparser;
pub mod dcstruct;
pub mod globals;

0 comments on commit 31722ae

Please sign in to comment.