• CGAL 获取相关功能的依赖头文件


    CGAL 获取相关功能的依赖头文件

    由于CGAL是header include only。只需要头文件就可以实现相关的功能。有时候为了实现一个简单的功能, 在研究具体实现的时候能够知道这个功能对应的头文件有哪些,就可以大概知道涉及到了哪些模块,可以从哪几个地方入手进行深入学习。于是此处给处理基于python,头文件依赖获取的示例脚本,如下:

    import os
    import re
    
    # Parameters
    include_paths = [
        "C:/dev/CGAL-5.0.2/include/"
    ]
    
    root_file = "./test.cpp"
    out_file = "./out.txt"
    
    # Global variables
    include_patterns = [
        re.compile(r'.*#include.*<(.*)>.*'),
        re.compile(r'.*#include.*"(.*)"')
    ]
    
    all_dependent_files = []
    
    def get_all_include_in_one_file(filename):
        print(filename)
        if filename in all_dependent_files:
            return []
        all_dependent_files.append(filename)
        dependent_files = []
        with open(filename, 'r', encoding='utf8') as fid:
            for line in fid:
                line = line.strip()
                if line.find("#include") == -1:
                    continue
                include_file = ""
                for pattern in include_patterns:
                    match = pattern.match(line)
                    if match:
                        include_file = match.group(1)
                        break
                if include_file == "":
                    continue
                
                dependent_files.append(include_file)
        return dependent_files
    
    
    def parse_header_files(filename):
        dependent_files = get_all_include_in_one_file(filename)
        if len(dependent_files) == 0:
            return
        for include_file in dependent_files:
            for include_path in include_paths:
                parse_file = os.path.join(include_path, include_file)
                if not os.path.isfile(parse_file):
                    print(parse_file + " is not file")
                else:
                    parse_header_files(parse_file)
    
    
    parse_header_files(root_file)
    
    with open(out_file, 'w', encoding="utf8") as fid:
        for line in all_dependent_files:
            fid.write(line + "
    ")
    
  • 相关阅读:
    资源 | 辟谣平台
    数据分析常用思维
    数据分析常用工具
    杂谈 | 标准化和个性化
    杂谈 | 学以致用
    杂谈 | 工具思维的陷阱
    杂谈 | 习得性无助&习得性乐观
    spark连接mysql
    spark累加器
    java操作excel数据写入map集合并按照value排序
  • 原文地址:https://www.cnblogs.com/grass-and-moon/p/13094125.html
Copyright © 2020-2023  润新知