/*
 * @(#)mclbase.h    generated by: makeheader 5.1.5  Mon Jun 28 17:24:02 2010
 *
 *		built from:	../../src/include/copyright.h
 *				../../src/include/pragma_interface.h
 *				LastError.cpp
 *				MessageManager.cpp
 *				app_state.cpp
 *				mclException.cpp
 *				mclFileUtilities.cpp
 *				mclOutputHandler.cpp
 *				mclPathMacros.cpp
 *				mclProxy.cpp
 *				mclRuntimePathMacros.cpp
 *				mclStatic.cpp
 *				mclStrUtils.cpp
 *				mxarray_utils.cpp
 *				runmain.cpp
 */

#if defined(_MSC_VER)
# pragma once
#endif
#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))
# pragma once
#endif

#ifndef mclbase_h
#define mclbase_h


/*
 * Copyright 1984-2003 The MathWorks, Inc.
 * All Rights Reserved.
 */



/* Copyright 2003-2006 The MathWorks, Inc. */

/* Only define EXTERN_C if it hasn't been defined already. This allows
 * individual modules to have more control over managing their exports.
 */
#ifndef EXTERN_C

#ifdef __cplusplus
  #define EXTERN_C extern "C"
#else
  #define EXTERN_C extern
#endif

#endif


EXTERN_C void mclSetLastErrIdAndMsg(const char* newid, const char* newmsg);

 
EXTERN_C const char* mclGetLastErrorMessage();

 
/* Get stack trace string when error happens
*/
EXTERN_C int mclGetStackTrace(char*** stack);

 
/* Free the stack trace string allocated earlier 
*/
EXTERN_C int mclFreeStackTrace(char*** stack, int nStackDepth);


#include <stdarg.h>
#include <string.h>
#include <wchar.h>
#include "tmwtypes.h"


EXTERN_C bool mclIsMCRInitialized();


EXTERN_C bool mclIsJVMEnabled();


EXTERN_C const char* mclGetLogFileName();


EXTERN_C bool mclIsNoDisplaySet();


EXTERN_C bool mclInitializeApplication(const char** options, size_t count);


EXTERN_C void mclInhibitShutdown(void);


EXTERN_C void mclUninhibitShutdown(void);


EXTERN_C bool mclTerminateApplication(void);


EXTERN_C bool mclIsMcc();


#ifdef __cplusplus
extern "C" {
#endif

#ifndef mclOutputHandler_cpp

    /**
     * C style puts function pointer
     */
    typedef int (*mclOutputHandlerFcn)(const char *s);
    
    /**
     * Defines the interface for a stateful text output function.
     */
    typedef struct mclOutputHandler_methods_struct {
        int (*print)(void*, const char*);
        void (*dispose)(void*);
    } mclOutputHandler_methods;
    
    /**
     * Represents an output function.
     */
    typedef struct mclOutputHandler_struct {
        mclOutputHandler_methods* methods;
        void* context;
    } mclOutputHandler;

    typedef mclOutputHandler* mclOutputHandlerPtr;

#endif /* mclOutputHandler_cpp */

#ifdef __cplusplus
}

#ifndef mclOutputHandler_cpp

/**
 * Abstract base class for output handler adapter classes.
 */
class mclOutputHandlerBase
{
public:
    virtual ~mclOutputHandlerBase () {}
    virtual int print (const char*) = 0;
};

#endif /* mclOutputHandler_cpp */



#ifndef mclOutputHandler_cpp

/**
 * Adapts any output function type to mclOutputHandler.
 */
template<typename F>
class mclOutputHandlerAdapter : public mclOutputHandlerBase
{
private:
    F output_function;
    
public:
    explicit mclOutputHandlerAdapter (F const& f)
        : output_function(f)
    {
    }
    
    int print (const char* str) 
    {
        return output_function(str);
    }
};

#endif /* mclOutputHandler_cpp */


EXTERN_C mclOutputHandler_methods* mclGetOutputHandlerBaseMethods();


#ifndef mclOutputHandler_cpp

/**
 * Adapt a puts-style function to a mclOutputHandler.  TODO - document pitfalls
 */
template<typename F>
mclOutputHandler mclMakeOutputHandler(F const& fcn)
{
    mclOutputHandler handler = { 
        mclGetOutputHandlerBaseMethods(), 
        new mclOutputHandlerAdapter<F>(fcn) 
    };
    return handler;
}

#endif /* mclOutputHandler_cpp */

#endif /* __cplusplus */


EXTERN_C mclOutputHandler mclMakeOutputHandler(mclOutputHandlerFcn fcn);


#include <string.h>


/* Extract the path from a file name specified by either absolute or
 * relative path. For example:
 *
 *   /home/foo/bar.exe -> /home/foo
 *   ./bar.exe -> <full path to cwd>/bar.exe
 *   bar.exe -> <empty string>
 *
 * Returns a pointer to the memory passed in by the caller. 
 */
EXTERN_C void separatePathName(const char *fullname, char *buf, size_t bufLen);


typedef void* HMCRINSTANCE;


EXTERN_C bool mclFreeStrArray(char **array, size_t elements);


#include "matrix.h"


EXTERN_C void mclFreeArrayList(int nargs, mxArray** ppxArgs);


EXTERN_C mxArray *mclCreateCellArrayFromArrayList(int narray, mxArray *parray[]);


EXTERN_C mxArray* mclCreateSharedCopy(mxArray* px);


EXTERN_C mxArray* mclCreateEmptyArray(void);


EXTERN_C mxArray* mclCreateSimpleFunctionHandle(mxFunctionPtr fcn);


EXTERN_C mxArray* mclMxSerialize(const mxArray * pa);


EXTERN_C mxArray *mclMxDeserialize(const void *ps, size_t len);


/* Main functions passed to mclRunMain must be of this type. This typedef
 * must be placed OUTSIDE of an extern "C" block to ensure that it has the
 * right linkage in the automatically generated MCLMCRRT proxy API. See
 * mclmcrrt/GenLibProxyAPI.pl for more details.
 */
typedef int (*mclMainFcnType)(int, const char **);


EXTERN_C int mclRunMain(mclMainFcnType run_main,
               int argc,
               const char **argv);

#endif /* mclbase_h */
