oo-bindgen 0.8.0

DSL-based binding geneator for C, C++, Java, and C#
Documentation
use crate::model::*;

/// Some types have a C -> C++ conversion that is context independent
pub(crate) trait ToCpp {
    fn to_cpp(&self, expr: String) -> String;
}

impl ToCpp for DurationType {
    fn to_cpp(&self, expr: String) -> String {
        match self {
            DurationType::Milliseconds => format!("::convert::from_milli_sec_u64({expr})"),
            DurationType::Seconds => format!("::convert::from_sec_u64({expr})"),
        }
    }
}

impl<D> ToCpp for Handle<Enum<D>>
where
    D: DocReference,
{
    fn to_cpp(&self, expr: String) -> String {
        format!("::convert::to_cpp({expr})")
    }
}

impl ToCpp for Primitive {
    fn to_cpp(&self, expr: String) -> String {
        match self {
            Self::Bool => expr,
            Self::U8 => expr,
            Self::S8 => expr,
            Self::U16 => expr,
            Self::S16 => expr,
            Self::U32 => expr,
            Self::S32 => expr,
            Self::U64 => expr,
            Self::S64 => expr,
            Self::Float => expr,
            Self::Double => expr,
        }
    }
}

impl ToCpp for BasicType {
    fn to_cpp(&self, expr: String) -> String {
        match self {
            Self::Primitive(x) => x.to_cpp(expr),
            Self::Duration(x) => x.to_cpp(expr),
            Self::Enum(x) => x.to_cpp(expr),
        }
    }
}

impl ToCpp for StringType {
    fn to_cpp(&self, expr: String) -> String {
        format!("std::string({expr})")
    }
}

impl ToCpp for ClassDeclarationHandle {
    fn to_cpp(&self, expr: String) -> String {
        format!("::convert::to_cpp({expr})")
    }
}