示例#1
0
def create_enum_of_dict(fname, mode='', cpptrajsrc=CPPTRAJSRC):
    #cpptrajsrc = os.environ['AMBERHOME'] + "AmberTools/src/cpptraj/src/"
    fname_full = cpptrajsrc + fname

    indent = " " * 4
    tmpindent = " " * 4
    classlist = find_class(cpptrajsrc)
    cpp = CppHeaderParser.CppHeader(fname_full)

    make_dict = False
    if mode == 'dict':
        make_dict = True
        tmpindent = ""
    else:
        make_dict = False

    # make assumption that there's only one class in header file
    #classname = list(cpp.classes.keys())[0]
    # use -1 for MetaData, else 0
    classname = list(cpp.classes.keys())[-1]
    print(cpp.classes[classname]['enums'])
    if cpp.classes[classname]['enums']['public']:
        print(classname)
        for enumlist in cpp.classes[classname]['enums']['public']:
            print("\n")
            if make_dict:
                print("from %s cimport *" % fname)
            else:
                print('cdef extern from "%s":' % fname)
            enumname = enumlist['name']
            enumext = classname + "::" + enumname
            if not make_dict:
                print(indent + 'ctypedef enum %s "%s":' % (enumname, enumext))
            else:
                enumname = enumname.replace("Type", "")
                print("%sDict = {" % enumname)
            for enumvar in enumlist['values']:
                enumvarname = enumvar['name']
                enumvarnameext = classname + "::" + enumvarname
                if not make_dict:
                    print(indent * 2 + '%s "%s"' %
                          (enumvarname, enumvarnameext))
                else:
                    print(indent + '"%s" : %s, ' % (enumvarname, enumvarname))
            if make_dict:
                print(indent + "}")
示例#2
0
def create_enum_of_dict(fname, mode='', cpptrajsrc=CPPTRAJSRC):
    #cpptrajsrc = os.environ['AMBERHOME'] + "AmberTools/src/cpptraj/src/"
    fname_full = cpptrajsrc + fname

    indent = " " * 4
    tmpindent = " " * 4
    classlist = find_class(cpptrajsrc)
    cpp = CppHeaderParser.CppHeader(fname_full)

    make_dict = False
    if mode == 'dict':
        make_dict = True
        tmpindent = ""
    else:
        make_dict = False

    # make assumption that there's only one class in header file
    #classname = list(cpp.classes.keys())[0]
    # use -1 for MetaData, else 0
    classname = list(cpp.classes.keys())[-1]
    print(cpp.classes[classname]['enums'])
    if cpp.classes[classname]['enums']['public']:
        print(classname)
        for enumlist in cpp.classes[classname]['enums']['public']:
            print("\n")
            if make_dict:
                print("from %s cimport *" % fname)
            else:
                print('cdef extern from "%s":' % fname)
            enumname = enumlist['name']
            enumext = classname + "::" + enumname
            if not make_dict:
                print(indent + 'ctypedef enum %s "%s":' % (enumname, enumext))
            else:
                enumname = enumname.replace("Type", "")
                print("%sDict = {" % enumname)
            for enumvar in enumlist['values']:
                enumvarname = enumvar['name']
                enumvarnameext = classname + "::" + enumvarname
                if not make_dict:
                    print(indent * 2 + '%s "%s"' % (enumvarname, enumvarnameext))
                else:
                    print(indent + '"%s" : %s, ' % (enumvarname, enumvarname))
            if make_dict:
                print(indent + "}")
示例#3
0
# (c) 2014 Hai Nguyen
import os
import CppHeaderParser
from util import print_blank_line, Line_codegen
from util import find_class
import sys

print sys.argv[:]
cpptrajsrc = os.environ["CPPTRAJHOME"] + "/src/"
filename = cpptrajsrc + sys.argv[1]
indent = " " * 4
classlist = find_class(cpptrajsrc)
cpp = CppHeaderParser.CppHeader(filename)

# format: PARM : "PARM",
enum_to_string = True
try:
    if sys.argv[2] and sys.argv[2] == '-se':
        # 'se' = 'string_to_enum'
        enum_to_string = False
except:
    pass

for classname in cpp.classes.keys():
    #create enum
    if cpp.classes[classname]['enums']['public']:
        for enumlist in cpp.classes[classname]['enums']['public']:
            print indent + "# %s" % sys.argv[1]
            enumname = enumlist['name']
            if 'Type' in edictname:
                edictname = edictname.replace("Type", "")
示例#4
0
# (c) 2014 Hai Nguyen

# TODO: should re-write, looks ugly
import os
import CppHeaderParser
from util import print_blank_line, Line_codegen
from util import find_class
import sys

#cpptrajsrc = os.environ['AMBERHOME'] + "/AmberTools/src/cpptraj/src/"
cpptrajsrc = os.environ['CPPTRAJHOME'] + "/src/"
filename = cpptrajsrc + sys.argv[1]
short_filename = filename.split("/")[-1]
indent = " " * 4
classlist = find_class(cpptrajsrc)
cpp = CppHeaderParser.CppHeader(filename)

# check if need extract line for Action_*.pyx or Analysis_*.pyx classes
need_extra_line = False
if short_filename.startswith("Action") or short_filename.startswith("Analysis"):
    need_extra_line = True
    # get Action's name from short_filename
    # Action_Rmsd.h --> Action_Rmsd
    action = short_filename.split(".")[0]
    # actionroot = "Action" or "Analysis"?
    actionroot = action.split("_")[0]

# print header line "c++" so Cython know it is c++ code
# (adding to setup.py seems not work)
print("# distutils: language = c++")