SHARE
TWEET

Untitled

a guest Dec 7th, 2014 428 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Created by Hugh Perkins 2014
  2. # You can freely use this, but appreciate you give me credit for the idea
  3. #
  4. # simply add it to your header file like:
  5. #
  6. #    // [[[cog
  7. #    // import cog_addheaders
  8. #    // cog_addheaders.add()
  9. #    // ]]]
  10. #    // [[[end]]]
  11. #
  12. # ... and run cog on the header file, to generate the header declarations
  13.  
  14. import cog
  15.  
  16. def add():
  17. #    debug = open('debug.txt', 'a' )
  18. #    debug.write( 'foo\n')
  19. #    debug.write( 'infile [' + cog.inFile + ']\n' )
  20.  
  21.     infile = cog.inFile
  22.     cppfile = infile.replace('.h','.cpp')
  23.     splitinfile = infile.split('/')
  24.     infilename = splitinfile[ len(splitinfile) - 1 ]
  25.     classname = infilename.replace('.h','')
  26.     #cog.outl( '// classname: ' + classname )
  27.     #cog.outl( '// cppfile: ' + cppfile )
  28.     f = open( cppfile, 'r')
  29.     line = f.readline()
  30.     cog.outl('')
  31.     while( line != '' ):
  32.        # cog.outl(line)
  33.        if( line.find( classname + '::' ) >= 0 ):
  34.            fnheader = line.replace( classname + '::', '' )
  35.            fnheader = fnheader.replace( '{', '' )
  36.            fnheader = fnheader.replace( ':', '' )
  37.            fnheader = fnheader.strip().replace( ')', ');' )
  38.            fnheader = fnheader.strip().replace( ';const', 'const;' )
  39.            fnheader = fnheader.strip().replace( '; const', ' const;' )
  40.            cog.outl( fnheader );
  41.        line = f.readline()
  42.     f.close()
  43.     cog.outl('')
  44.  
  45. #    debug.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top