Home > functions > internal > dsGetParentNamespace.m

dsGetParentNamespace

PURPOSE ^

GETPARENTNAMESPACE - determine parent namespace from namespace specified in namespace

SYNOPSIS ^

function parent = dsGetParentNamespace(namespace, varargin)

DESCRIPTION ^

GETPARENTNAMESPACE - determine parent namespace from namespace specified in namespace

 Usage:
   parent = dsGetParentNamespace(namespace)

 Input:
   - namespace: current namespace of object

 Output:
   - parent: parent namespace containing the current namespace

 Examples:
   parent=dsGetParentNamespace('pop')
   parent=dsGetParentNamespace('pop_mech')
   parent=dsGetParentNamespace('pop_pop')
   parent=dsGetParentNamespace('pop_pop_mech')
   parent=dsGetParentNamespace('mech')
   parent=dsGetParentNamespace('')

 See also: dsPropagateNamespaces

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function parent = dsGetParentNamespace(namespace, varargin)
0002 %GETPARENTNAMESPACE - determine parent namespace from namespace specified in namespace
0003 %
0004 % Usage:
0005 %   parent = dsGetParentNamespace(namespace)
0006 %
0007 % Input:
0008 %   - namespace: current namespace of object
0009 %
0010 % Output:
0011 %   - parent: parent namespace containing the current namespace
0012 %
0013 % Examples:
0014 %   parent=dsGetParentNamespace('pop')
0015 %   parent=dsGetParentNamespace('pop_mech')
0016 %   parent=dsGetParentNamespace('pop_pop')
0017 %   parent=dsGetParentNamespace('pop_pop_mech')
0018 %   parent=dsGetParentNamespace('mech')
0019 %   parent=dsGetParentNamespace('')
0020 %
0021 % See also: dsPropagateNamespaces
0022 
0023 %% auto_gen_test_data_flag argin
0024 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0025 if options.auto_gen_test_data_flag
0026   varargs = varargin;
0027   varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0028   varargs(end+1:end+2) = {'unit_test_flag',1};
0029   argin = [{namespace}, varargs]; % specific to this function
0030 end
0031 
0032 
0033 if isempty(namespace) && isnumeric(namespace)
0034   namespace='';
0035 end
0036 if ~isempty(namespace) && namespace(end)=='_'
0037   namespace=namespace(1:end-1);
0038 end
0039 if ~isempty(namespace)
0040   parts=regexp(namespace,'_','split');
0041 else
0042   parts=[];
0043 end
0044 
0045 switch length(parts)
0046   case 0                          % ''
0047     parent='global';
0048   case 1                          % pop or mech
0049     parent='';
0050   case 2
0051     if isequal(parts{1},parts{2}) % pop_pop
0052       parent='global';
0053     else                          % pop_mech
0054       parent=[parts{1} '_'];
0055     end
0056   case 3                          % pop_pop_mech
0057     parent=[parts{1} '_' parts{2} '_'];
0058   otherwise                       % a_b_c_d_...
0059     parent='';
0060     for i=1:length(parts)-1
0061       parent=[parent parts{i} '_'];
0062     end
0063 end
0064 
0065 %% auto_gen_test_data_flag argout
0066 if options.auto_gen_test_data_flag
0067   argout = {parent}; % specific to this function
0068   
0069   dsUnitSaveAutoGenTestData(argin, argout);
0070 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005