"""Generate Matlab interface for C code to solve a problem using the ALM"""

import os

from muaompc._ldt.codegen.solver.alm.codegen import CCodeGenerator as CCG


class MatlabCodeGenerator(CCG, object):

    """Generate Matlab code to interface with C code of the solver.

    This class overrides the following methods:
    generate_code: generates Matlab specific code on its own directory
    """

    def __init__(self, ccg):
        """Assign to self prefix, path attributes from the given C code.

        This depends on C-code already being generated by C-code
        generation class. This creates the interface to that specific code.

        :param ccg: an instance of the C code generator class for which
        a Matlab interface is to be created
        :type ccg: muaompc._ldt.codegen.solver.alm.codegen.CCodeGenerator
        """
        self.prefix = ccg.prefix
        self.path = ccg.path

    def generate_code(self):
        self._generate_matlab_code()

    def _generate_matlab_code(self):
        include_path = os.path.join('matlab', 'include')
        self._replace_prefix('almmatlab.c', srcdir='matlab', destdir='matlab')
        self._replace_prefix('almmatlab.h', srcdir='matlab', destdir=include_path)

