parameters: ( swigPath )
docstring: Generates StlContainers interface which wraps std::string, std::pair,
         std::vector, std::function and creates template specializations for pairs and vectors
docstring_summary: Generates StlContainers interface which wraps std::string, std::pair,
         std::vector, std::function and creates template specializations for pairs and vectors
docstring_tokens: Generates StlContainers interface which wraps std :: string std :: pair std :: vector std :: function and creates template specializations for pairs and vectors
function: def generateStlContainersInterface( swigPath ):
      '''Generates StlContainers interface which wraps std::string, std::pair,
         std::vector, std::function and creates template specializations for pairs and vectors'''
      with SwigModuleGenerator( 'StlContainers',
              os.path.join( swigPath, 'StlContainers.i' ) ) as mg:
          mg.addAutoGenWarning()
          mg.addSwigModuleHeadline()
          with SwigAsIsScope( mg ):
              mg.addCppInclude( '<functional>', '// for std::function' )
  
  
          mg.write( '\n// swig wrappers for STL containers\n' )
          mg.addSwigInclude( '<std_string.i>' )
          mg.addSwigInclude( '<std_pair.i>' )
          mg.addSwigInclude( '<std_vector.i>' )
      
          functionTypes = {'DP': 'function<double(const std::vector<double> &, double)>',
                           'CKS': 'function<std::vector<unsigned int>(const std::vector<double>&)>',
                           'CML': 'function<unsigned int( unsigned int, unsigned int, const std::vector<double> &)>'}
          for name, spec in functionTypes.items():
              # Find brackets defining function arguments
              firstBracketIdx = spec.find('(')
              lastBracketIdx = spec.rfind(')')
              assert firstBracketIdx != -1
              assert lastBracketIdx != -1
              assert firstBracketIdx < lastBracketIdx
              
              # Use to extract function arguments and return type
              functionArgs = spec[firstBracketIdx + 1:lastBracketIdx]
              functionRet = spec[9:firstBracketIdx]
              
              # Rename this std::function specialisation
              mg.addSwigRename('std::' + spec, name + 'Function')
              
              mg.addSwigRename(
                      'std::' + spec + '::operator()',
                      '__call__',
                      '// rename operator() as __call__ so that it works correctly in python' )
                      
              # Write SWIG-parsable version of std::function specialisation
              mg.write('namespace std{\n'
                       '    struct ' + spec + ' {\n'
                       '        // copy ctor\n' +
                       '        {0}( const std::{0}&);\n'.format( spec ) +
                       '        ' + functionRet + ' operator()(' + functionArgs + ') const;\n'
                       '    };\n'
                       '}\n' )
  
          mg.write( '\n// add template specifications for various STL containers\n' )
          mg.addSwigTemplate( 'std::vector<std::string>', 'StringVector' )
  
          # These are all data types supported by numpy SWIG interface (at least by default) plus long double
          npDTypes = (
                  'signed char', 'unsigned char',
                  'short', 'unsigned short',
                  'int', 'unsigned int',
                  'long', 'unsigned long',
                  'long long', 'unsigned long long',
                  'float', 'double', 'long double'
          )
  
          for npDType in npDTypes:
              camelDT = ''.join( x.capitalize() for x in npDType.split() ) + 'Vector'
              mg.addSwigTemplate( 'std::vector<{}>'.format(npDType), camelDT )
function_tokens: def generateStlContainersInterface ( swigPath ) : with SwigModuleGenerator ( 'StlContainers' , os . path . join ( swigPath , 'StlContainers.i' ) ) as mg : mg . addAutoGenWarning ( ) mg . addSwigModuleHeadline ( ) with SwigAsIsScope ( mg ) : mg . addCppInclude ( '<functional>' , '// for std::function' ) mg . write ( '\n// swig wrappers for STL containers\n' ) mg . addSwigInclude ( '<std_string.i>' ) mg . addSwigInclude ( '<std_pair.i>' ) mg . addSwigInclude ( '<std_vector.i>' ) functionTypes = { 'DP' : 'function<double(const std::vector<double> &, double)>' , 'CKS' : 'function<std::vector<unsigned int>(const std::vector<double>&)>' , 'CML' : 'function<unsigned int( unsigned int, unsigned int, const std::vector<double> &)>' } for name , spec in functionTypes . items ( ) : # Find brackets defining function arguments firstBracketIdx = spec . find ( '(' ) lastBracketIdx = spec . rfind ( ')' ) assert firstBracketIdx != - 1 assert lastBracketIdx != - 1 assert firstBracketIdx < lastBracketIdx # Use to extract function arguments and return type functionArgs = spec [ firstBracketIdx + 1 : lastBracketIdx ] functionRet = spec [ 9 : firstBracketIdx ] # Rename this std::function specialisation mg . addSwigRename ( 'std::' + spec , name + 'Function' ) mg . addSwigRename ( 'std::' + spec + '::operator()' , '__call__' , '// rename operator() as __call__ so that it works correctly in python' ) # Write SWIG-parsable version of std::function specialisation mg . write ( 'namespace std{\n' '    struct ' + spec + ' {\n' '        // copy ctor\n' + '        {0}( const std::{0}&);\n' . format ( spec ) + '        ' + functionRet + ' operator()(' + functionArgs + ') const;\n' '    };\n' '}\n' ) mg . write ( '\n// add template specifications for various STL containers\n' ) mg . addSwigTemplate ( 'std::vector<std::string>' , 'StringVector' ) # These are all data types supported by numpy SWIG interface (at least by default) plus long double npDTypes = ( 'signed char' , 'unsigned char' , 'short' , 'unsigned short' , 'int' , 'unsigned int' , 'long' , 'unsigned long' , 'long long' , 'unsigned long long' , 'float' , 'double' , 'long double' ) for npDType in npDTypes : camelDT = '' . join ( x . capitalize ( ) for x in npDType . split ( ) ) + 'Vector' mg . addSwigTemplate ( 'std::vector<{}>' . format ( npDType ) , camelDT )