%% Insert External C++ Code Into Stateflow Charts for Code Generation
% This example shows how to use Stateflow(R) to integrate external C++ code 
% into a model.

%% Open Model

model='rtwdemo_sfcpp';
open_system(model);

%% 
% To setup a C++ compiler, on the command line, enter |mex -setup|.

%% Integrate C++ Code
% 
% 1. Create C-style wrapper functions or access macros for each method called from the C action language.
%%
%Open example wrapper functions.
filename=fullfile(matlabroot, 'toolbox', 'rtw', 'rtwdemos', 'custom_cpp_src', 'adder_cpp.cpp');
eval('edit(filename)');
clear filename;   

filename=fullfile(matlabroot, 'toolbox', 'rtw', 'rtwdemos', 'custom_cpp_src', 'adder_cpp.h');
eval('edit(filename)');
clear filename; 

%%
% 2. On the Configuration Parameters dialog box *Code Generation > Custom Code*
% pane, enter the S-Function source files and include directories.
%%
%Open Configuration Parameters dialog box                             
configSet = getActiveConfigSet(model);
openDialog(configSet);

%%
% 3. On the Configuration Parameters dialog box *Simulation Target > Custom Code*
% pane, enter the S-Function source files and include directories.
%%
%Open Configuration Parameters dialog box                              
configSet = getActiveConfigSet(model);
openDialog(configSet);

%% Generate C++ Code
%
% On the Configuration Parameters dialog box *Code Generation* pane, set
% *Language* to |C++|. To generate code, select *Build*.
%%
%Open Configuration Parameters dialog box                                       
configSet = getActiveConfigSet(model);
openDialog(configSet);
clear model;

%% See Also
% * <matlab:helpview(fullfile(docroot,'rtw','helptargets.map'),'rtw_language_support'); Language Considerations>
% * <matlab:helpview(fullfile(docroot,'rtw','helptargets.map'),'rtw_cpp_limitations'); C++ Language Limitations>

%% Close Model

rtwdemoclean;
close_system('rtwdemo_sfcpp',0); 

%% 
% Copyright 2012 The MathWorks, Inc.
