1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#!/usr/bin/env python3
# this script takes TasmanianSparseGridWrapC.cpp and parces out
# all the methods, then puts them in TasmanianSparseGrid.h
# methods must be defined on a single line and start with type + tsg
# e.g., void tsg... or void *tsg
with open("../../SparseGrids/TasmanianSparseGrid.hpp") as tsghpp:
lTsgHpp = tsghpp.readlines()
with open("../../SparseGrids/TasmanianSparseGridWrapC.cpp") as tsgcpp:
lTsgCpp = tsgcpp.readlines()
lTsgH =[]
iStage = 0
for sLine in lTsgHpp:
sLine = sLine.replace('\n', '')
if (iStage == 0): # copyright statement
lTsgH.append(sLine + "\n")
if ("*/" in sLine):
iStage = 1
elif (iStage == 1): # ifndef statement
lTsgH.append("\n")
lTsgH.append("#ifndef __TASMANIAN_SPARSE_GRID_H\n")
lTsgH.append("#define __TASMANIAN_SPARSE_GRID_H\n")
lTsgH.append("\n")
lTsgH.append("// ------------ C Interface for TasmanianSparseGrid -------------- //\n")
lTsgH.append("// NOTE: you need to explicitly call the constructor and destructor\n")
lTsgH.append("// in all cases, void *grid is a pointer to a C++ class\n")
lTsgH.append("\n")
iStage = 2
iStage = 0
for sLine in lTsgCpp:
if (iStage == 0):
if ('extern "C"' in sLine):
iStage = 1
elif (iStage == 1):
# if this is the definition of a function
if (sLine.startswith("//")):
lTsgH.append(sLine)
elif (("void* tsg" in sLine) or
("void *tsg" in sLine) or
("void * tsg" in sLine) or
("void tsg" in sLine) or
("int* tsg" in sLine) or
("int *tsg" in sLine) or
("int * tsg" in sLine) or
("int tsg" in sLine) or
("double* tsg" in sLine) or
("double *tsg" in sLine) or
("double * tsg" in sLine) or
("double tsg" in sLine) or
("char* tsg" in sLine) or
("char *tsg" in sLine) or
("char * tsg" in sLine) or
("char tsg" in sLine)):
sDef = sLine.split("{")[0] + ";"
lTsgH.append(sDef + "\n")
#print(sDef)
lTsgH.append("\n")
lTsgH.append("#endif\n")
with open("TasmanianSparseGrid.h", 'w') as outp:
outp.writelines(lTsgH)
|