From f2bcde2124107bc22e7d7fb0bc29da3b2c975300 Mon Sep 17 00:00:00 2001 From: Anton Titovets Date: Mon, 9 Dec 2024 10:08:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=92=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tmpl/src/{core => component}/methods.rs | 0 src/addins/tmpl/src/component/mod.rs | 70 +++++++++++++ src/addins/tmpl/src/core/mod.rs | 98 ++++--------------- src/addins/tmpl/src/lib.rs | 2 + src/en/OPI/DT-INF/PROJECT.PMF | 3 +- 5 files changed, 94 insertions(+), 79 deletions(-) rename src/addins/tmpl/src/{core => component}/methods.rs (100%) create mode 100644 src/addins/tmpl/src/component/mod.rs diff --git a/src/addins/tmpl/src/core/methods.rs b/src/addins/tmpl/src/component/methods.rs similarity index 100% rename from src/addins/tmpl/src/core/methods.rs rename to src/addins/tmpl/src/component/methods.rs diff --git a/src/addins/tmpl/src/component/mod.rs b/src/addins/tmpl/src/component/mod.rs new file mode 100644 index 000000000..0de03fe42 --- /dev/null +++ b/src/addins/tmpl/src/component/mod.rs @@ -0,0 +1,70 @@ +mod methods; + +use addin1c::{name, Variant}; + + +// МЕТОДЫ КОМПОНЕНТЫ ------------------------------------------------------------------------------- + +// Синонимы +pub const METHODS: &[&[u16]] = &[ + name!("Метод1") // 0 +]; + +// Число параметров функций компоненты +pub fn get_params_amount(num: usize) -> usize { + match num { + 0 => 1, + _ => 0, + } +} + +// Соответствие функций Rust функциям компоненты +// Вызовы должны быть обернуты в Box::new +pub fn cal_func(obj: &AddIn, num: usize, params: &mut [Variant]) -> Box { + + match num { + 0 => Box::new(methods::send_message(&obj, ¶ms)), + _ => Box::new(false), + } + +} + +// ------------------------------------------------------------------------------------------------- + +// ПОЛЯ КОМПОНЕНТЫ --------------------------------------------------------------------------------- + +// Синонимы +pub const PROPS: &[&[u16]] = &[ + name!("Свойство1"), + name!("Свойство2") +]; + +// Имена и типы +pub struct AddIn { + field1: String, + field2: i32 +} + +// Конструктор +impl AddIn { + + // Значения по умолчанию + pub fn new() -> AddIn { + AddIn { + field1: String::from(""), + field2: 0 + } + } + + // Сюда просто нужно еще раз добавить имена полей + pub fn get_field_ptr(&self, index: usize) -> *const T { + match index { + 0 => &self.field1 as *const _, + 1 => &self.field2 as *const _, + _ => panic!("Index out of bounds"), + } + } + pub fn get_field_ptr_mut(&mut self, index: usize) -> *mut T { self.get_field_ptr(index) as *mut _ } +} + +// ------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/addins/tmpl/src/core/mod.rs b/src/addins/tmpl/src/core/mod.rs index 0f036c70f..9317b270f 100644 --- a/src/addins/tmpl/src/core/mod.rs +++ b/src/addins/tmpl/src/core/mod.rs @@ -1,86 +1,14 @@ -mod getset; -mod methods; +pub mod getset; use addin1c::{name, ParamValue, RawAddin, Variant}; use std::ops::{Index, IndexMut}; -// МЕТОДЫ КОМПОНЕНТЫ ------------------------------------------------------------------------------- +use crate::component::METHODS; +use crate::component::PROPS; +use crate::component::get_params_amount; +use crate::component::cal_func; +use crate::component::AddIn; -// Русские синонимы -const METHODS: &[&[u16]] = &[ - name!("Метод1") -]; - -// Число параметров по индексу -fn get_params_amount(num: usize) -> usize { - match num { - 0 => 1, - _ => 0, - } -} - -fn cal_func(obj: &AddIn, num: usize, params: &mut [Variant]) -> Box { - - match num { - 0 => Box::new(methods::send_message(&obj, ¶ms)), - _ => Box::new(false), - } - -} - -// ------------------------------------------------------------------------------------------------- - -// ПОЛЯ КОМПОНЕНТЫ --------------------------------------------------------------------------------- - -// Русские синонимы -const PROPS: &[&[u16]] = &[ - name!("Свойство1"), - name!("Свойство2") -]; - -// Имена и типы -pub struct AddIn { - field1: String, - field2: i32 -} - -// Значения по умолчанию -impl AddIn { - pub fn new() -> AddIn { - AddIn { - field1: String::from(""), - field2: 0 - } - } -} - -// Индекс -impl Index for AddIn { - type Output = dyn getset::ValueType; - - fn index(&self, index: usize) -> &Self::Output { - match index { - 0 => &self.field1, // Возвращаем ссылку на field1 - 1 => &self.field2, // Возвращаем ссылку на field2 - _ => panic!("Index out of bounds"), - } - } -} - -impl IndexMut for AddIn { - - fn index_mut(&mut self, index: usize) -> &mut Self::Output { - match index { - 0 => &mut self.field1, // Возвращаем изменяемую ссылку на field1 - 1 => &mut self.field2, // Возвращаем изменяемую ссылку на field2 - _ => panic!("Index out of bounds"), - } - } -} - -// ------------------------------------------------------------------------------------------------- - -// ТО, ЧТО ТРОГАТЬ НЕ НУЖНО ------------------------------------------------------------------------ // Обработка удаления объекта impl Drop for AddIn { @@ -115,4 +43,18 @@ impl RawAddin for AddIn { } +impl std::ops::Index for AddIn { + type Output = dyn getset::ValueType; + + fn index(&self, index: usize) -> &Self::Output { + unsafe { &*self.get_field_ptr(index) } + } +} + +impl std::ops::IndexMut for AddIn { + fn index_mut(&mut self, index: usize) -> &mut Self::Output { + unsafe { &mut *self.get_field_ptr_mut(index) } + } +} + diff --git a/src/addins/tmpl/src/lib.rs b/src/addins/tmpl/src/lib.rs index ab8790c22..9f45a8748 100644 --- a/src/addins/tmpl/src/lib.rs +++ b/src/addins/tmpl/src/lib.rs @@ -1,5 +1,7 @@ +pub mod component; mod core; + use std::{ ffi::{c_int, c_long, c_void}, sync::atomic::{AtomicI32, Ordering}, diff --git a/src/en/OPI/DT-INF/PROJECT.PMF b/src/en/OPI/DT-INF/PROJECT.PMF index d72af02b0..90d57fbfd 100644 --- a/src/en/OPI/DT-INF/PROJECT.PMF +++ b/src/en/OPI/DT-INF/PROJECT.PMF @@ -1,3 +1,4 @@ Manifest-Version: 1.0 Runtime-Version: 8.3.15 -Base-Project: OpenIntegrations_ENG +Base-Project: OpenIntegrationsENG +Manifest-Version: 1.0