Home > src > geckomat > model_adapter > ModelAdapterManager.m

ModelAdapterManager

PURPOSE ^

Abstract Base class for adapters for different species

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

Abstract Base class for adapters for different species

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %Abstract Base class for adapters for different species
0002 classdef ModelAdapterManager 
0003     methods(Static)
0004         function adapter = getAdapter(adapterPath, addToMatlabPath)
0005             if nargin < 2
0006                 addToMatlabPath = true;
0007             end
0008             
0009             [adapterFolder, adapterClassName, extension] = fileparts(adapterPath);
0010             if ~strcmp(extension, '.m')
0011                 error('Please provide the full path to the adapter file, including the file extension.');
0012             else
0013                 s = pathsep;
0014                 pathStr = [s, path, s];
0015                 onPath = contains(pathStr, [s, adapterFolder, s], 'IgnoreCase', ispc);
0016                 % Check if the folder is on the path
0017                 if ~onPath
0018                     if addToMatlabPath
0019                         addpath(adapterFolder);
0020                     else
0021                         printOrange(['WARNING: The adapter will not be on the MATLAB path, since addToMatlabPath is false\n' ...
0022                                      'and it is not currently on the path. Either set addToMatlabPath to true, fix this\n'...
0023                                      'manually before calling this function or make sure it is in current directory (not\n'...
0024                                      'recommended). If the class is not reachable throughout the entire GECKO use there will\n'...
0025                                      'be errors throughout.\n']);
0026                     end
0027                 end
0028 
0029             end
0030             adapter = feval(adapterClassName);
0031         end
0032         
0033         function out = getDefault()
0034             out = ModelAdapterManager.setGetDefault();
0035         end
0036         
0037         function adapter = setDefault(adapterPath, addToMatlabPath)
0038             if nargin < 1 || isempty(adapterPath)
0039                 adapter = ModelAdapterManager.setGetDefault(adapterPath);
0040                 return
0041             end
0042             if nargin < 2
0043                 addToMatlabPath = true;
0044             end
0045             adapter = ModelAdapterManager.setGetDefault(ModelAdapterManager.getAdapter(adapterPath, addToMatlabPath));
0046         end
0047         
0048     end
0049     methods(Static,Access = private)
0050         % This is how they recommend defining static variables in Matlab
0051         function out = setGetDefault(val)
0052             persistent defaultAdapter; %will be empty initially
0053             if nargin
0054                 defaultAdapter = val;
0055             end
0056             out = defaultAdapter;
0057         end
0058     end
0059 end

Generated by m2html © 2005