Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new macros #37

Merged
merged 17 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dcl_data_structures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,13 @@ shall be licensed under the MIT licence, without any additional terms or conditi

This project is licensed under the [MIT license](LICENSE).

## 👮️ Security

For details about security, please read
the [security policy](https://github.com/deepcausality-rs/deep_causality/blob/main/SECURITY.md).

## 💻 Author

* Marvin Hansen, [Emet-Labs](https://emet-labs.com/).
* [Marvin Hansen](https://github.com/marvin-hansen).
* Github GPG key ID: 369D5A0B210D39BC
* GPG Fingerprint: 4B18 F7B2 04B9 7A72 967E 663E 369D 5A0B 210D 39BC
2 changes: 1 addition & 1 deletion deep_causality/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub use crate::types::csm_types::CSM;
pub use crate::types::csm_types::csm_action::CausalAction;
pub use crate::types::csm_types::csm_state::CausalState;
// Model types
pub use crate::types::model_types::model::Model;
pub use crate::types::model_types::Model;
// Reasoning types
pub use crate::types::reasoning_types::assumption::Assumption;
pub use crate::types::reasoning_types::causaloid::Causaloid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
use deep_causality_macros::{Constructor, Getters};

// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.

use crate::prelude::Datable;

mod adjustable;
mod display;
mod identifiable;

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Getters, Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct AdjustableData<T>
where T: Copy + Default,
{
#[getter(name = data_id)] // Rename ID getter to prevent conflict impl with identifiable
id: u64,
data: T,
}

impl<T> AdjustableData<T>
where T: Copy + Default,
{
pub fn new(id: u64, data: T) -> Self
{
Self { id, data }
}
}

impl<T> AdjustableData<T>
where T: Copy + Default,
{
pub fn data(&self) -> T {
self.data
}
}

// Type tag required for context.
impl<T> Datable for AdjustableData<T> where T: Copy + Default {}
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
use deep_causality_macros::{Constructor, Getters};

// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.

use crate::prelude::{Temporal, TimeScale};

mod identifiable;
mod display;
mod adjustable;
mod display;
mod identifiable;

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Getters, Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct AdjustableTime<T>
where T: Copy + Default,
{
#[getter(name = time_id)] // Rename ID getter to prevent conflict impl with identifiable
id: u64,
time_scale: TimeScale,
time_unit: T,
}

impl<T> AdjustableTime<T>
where T: Copy + Default,
{
pub fn new(id: u64, time_scale: TimeScale, time_unit: T) -> Self {
Self { id, time_scale, time_unit }
}
}

impl<T> AdjustableTime<T>
where T: Copy + Default,
{
pub fn id(&self) -> u64 {
self.id
}
pub fn time_scale(&self) -> TimeScale {
self.time_scale
}
pub fn time_unit(&self) -> T {
self.time_unit
}
}

// Type tag required for context.
impl<T> Temporal for AdjustableTime<T>
where T: Copy + Default {}
impl<T> Temporal for AdjustableTime<T> where T: Copy + Default {}
20 changes: 4 additions & 16 deletions deep_causality/src/types/context_types/node_types/dateoid.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.


use std::fmt::{Display, Formatter};

use deep_causality_macros::{Constructor, Getters};

use crate::prelude::{Datable, Identifiable};

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Getters, Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct Dataoid
{
#[getter(name = data_id)] // Rename ID getter to prevent conflict impl with identifiable
id: u64,
data: i32,
}


impl Dataoid
{
pub fn new(id: u64, data_range: i32) -> Self {
Self { id, data: data_range }
}
pub fn data(&self) -> i32 {
self.data
}
}

// Optional. Override only when needed.
// impl Adjustable for Dataoid {}

impl Datable for Dataoid {}


Expand Down
11 changes: 3 additions & 8 deletions deep_causality/src/types/context_types/node_types/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.
use std::fmt::{Display, Formatter};

use deep_causality_macros::Constructor;

use crate::protocols::identifiable::Identifiable;

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct Root {
id: u64,
}

impl Root
{
pub fn new(id: u64) -> Self {
Self { id }
}
}

impl Identifiable for Root
{
fn id(&self) -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.
use std::fmt::{Display, Formatter};

use deep_causality_macros::Constructor;

use crate::prelude::{Identifiable, SpaceTemporal, Spatial, Temporable, Temporal, TimeScale};

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct SpaceTempoid {
id: u64,
time_scale: TimeScale,
Expand All @@ -14,24 +16,16 @@ pub struct SpaceTempoid {
z: i64,
}

impl SpaceTempoid {
pub fn new(id: u64, time_scale: TimeScale, time_unit: u32, x: i64, y: i64, z: i64) -> Self {
Self { id, time_scale, time_unit, x, y, z }
}
}

impl Identifiable for SpaceTempoid
{
fn id(&self) -> u64 {
self.id
}
}

// Optional. Override only when needed.
// impl Adjustable for SpaceTempoid {}

impl Temporal for SpaceTempoid {}


impl Temporable for SpaceTempoid
{
fn time_scale(&self) -> TimeScale {
Expand Down Expand Up @@ -71,12 +65,7 @@ impl SpaceTemporal for SpaceTempoid
impl Display for SpaceTempoid {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "SpaceTempoid: id={}, time_scale={}, time_unit={}, x={}, y={}, z={}",
self.id,
self.time_scale,
self.time_unit,
self.x,
self.y,
self.z,
self.id, self.time_scale, self.time_unit, self.x, self.y, self.z,
)
}
}
20 changes: 4 additions & 16 deletions deep_causality/src/types/context_types/node_types/spaceoid.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.

use std::fmt::{Display, Formatter};

use deep_causality_macros::Constructor;

use crate::prelude::{Identifiable, Spatial};

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct Spaceoid
{
id: u64,
Expand All @@ -14,16 +15,6 @@ pub struct Spaceoid
z: i64,
}

impl Spaceoid
{
pub fn new(id: u64, x: i64, y: i64, z: i64) -> Self {
Self { id, x, y, z }
}
}

// Optional. Override only when needed.
// impl Adjustable for Spaceoid {}


impl Identifiable for Spaceoid
{
Expand Down Expand Up @@ -52,10 +43,7 @@ impl Spatial for Spaceoid
impl Display for Spaceoid {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Spaceoid: id={}, x={}, y={}, z={}",
self.id,
self.x,
self.y,
self.z
self.id, self.x, self.y, self.z
)
}
}
18 changes: 3 additions & 15 deletions deep_causality/src/types/context_types/node_types/tempoid.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.

use std::fmt::Display;

use deep_causality_macros::Constructor;

use crate::prelude::{Identifiable, Temporable, Temporal, TimeScale};

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
#[derive(Constructor, Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub struct Tempoid
{
id: u64,
time_scale: TimeScale,
time_unit: u32,
}

impl Tempoid
{
pub fn new(id: u64, time_scale: TimeScale, time_unit: u32) -> Self {
Self {
id,
time_scale,
time_unit,
}
}
}

impl Identifiable for Tempoid {
fn id(&self) -> u64 {
self.id
}
}

// Optional. Override only when needed.
// impl Adjustable for Tempoid {}

impl Temporal for Tempoid {}

impl Temporable for Tempoid
Expand Down
18 changes: 2 additions & 16 deletions deep_causality/src/types/csm_types/csm_action.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
// SPDX-License-Identifier: MIT
// Copyright (c) "2023" . The DeepCausality Authors. All Rights Reserved.
use deep_causality_macros::{Constructor, Getters};

use crate::prelude::ActionError;

#[derive(Clone, Debug)]
#[derive(Getters, Constructor, Clone, Debug)]
pub struct CausalAction {
action: fn() -> Result<(), ActionError>,
descr: &'static str,
version: usize,
}

impl CausalAction
{
pub fn new(action: fn() -> Result<(), ActionError>, descr: &'static str, version: usize) -> Self {
Self { action, descr, version }
}

pub fn descr(&self) -> &'static str {
self.descr
}

pub fn version(&self) -> usize {
self.version
}
}

impl CausalAction
{
pub fn fire(&self) -> Result<(), ActionError>
Expand Down
Loading
Loading