use crate::core::area;
use crate::core::area::Area;
use std::fmt;
pub trait Code {
fn get_type(&self) -> u8;
fn get_hangul_count(&self) -> usize;
fn get_dot_count(&self) -> usize;
fn get_area(&self) -> &Area;
fn get_area_count(&self) -> usize;
}
#[derive(Clone)]
pub struct OptCode {
type_: u8,
hangul_count: usize,
dot_count: usize,
area_count: usize,
area: Area,
}
impl OptCode {
pub fn new(
type_: u8,
hangul_count: usize,
dot_count: usize,
area_count: usize,
area: Area,
) -> OptCode {
OptCode {
type_,
hangul_count,
dot_count,
area_count,
area,
}
}
}
impl Code for OptCode {
fn get_type(&self) -> u8 {
self.type_
}
fn get_hangul_count(&self) -> usize {
self.hangul_count
}
fn get_dot_count(&self) -> usize {
self.dot_count
}
fn get_area(&self) -> &Area {
&self.area
}
fn get_area_count(&self) -> usize {
self.area_count
}
}
#[derive(Clone)]
pub struct UnOptCode {
type_: u8,
hangul_count: usize,
dot_count: usize,
loc: (usize, usize),
area: Area,
code: String,
}
impl UnOptCode {
pub fn new(
type_: u8,
hangul_count: usize,
dot_count: usize,
loc: (usize, usize),
area: Area,
code: String,
) -> UnOptCode {
UnOptCode {
type_,
hangul_count,
dot_count,
loc,
area,
code,
}
}
pub fn get_location(&self) -> (usize, usize) {
self.loc
}
pub fn get_raw(&self) -> String {
self.code.clone()
}
}
impl fmt::Debug for UnOptCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut area = String::new();
area::area_to_string_debug(&mut area, &self.area);
write!(
f,
"type: {}, cnt1: {}, cnt2: {}, area: {:?}",
self.type_, self.hangul_count, self.dot_count, area
)
}
}
impl Code for UnOptCode {
fn get_type(&self) -> u8 {
self.type_
}
fn get_hangul_count(&self) -> usize {
self.hangul_count
}
fn get_dot_count(&self) -> usize {
self.dot_count
}
fn get_area(&self) -> &Area {
&self.area
}
fn get_area_count(&self) -> usize {
self.hangul_count * self.dot_count
}
}