MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / HeaderDatabase

Class HeaderDatabase

tools/meta_codegen/framework/database.py:15–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class HeaderDatabase:
16 def __init__(self, module_db: 'ModuleDatabase') -> None:
17 self.module_db: 'ModuleDatabase' = module_db
18
19 # header file path
20 self.meta_path: str = ""
21 self.relative_meta_path: str = ""
22 self.relative_target_header_path: str = ""
23 self.include_header_path: str = ""
24 self.file_id: str = ""
25
26 # all data
27 self.records: List[cpp.Record] = []
28 self.enums: List[cpp.Enumeration] = []
29 self.functions: List[cpp.Function] = []
30
31 # name to data
32 self.__name_to_record: Dict[str, cpp.Record] = {}
33 self.__name_to_enum: Dict[str, cpp.Enumeration] = {}
34
35 def get_records(self):
36 return self.records
37
38 def get_enums(self):
39 return self.enums
40
41 def get_functions(self):
42 return self.functions
43
44 def load_header(self, meta_file_path: str, config: config.CodegenConfig):
45 self.meta_path = os.path.normpath(meta_file_path).replace(os.sep, "/")
46 self.relative_meta_path = os.path.relpath(self.meta_path, self.module_db.meta_dir).replace(os.sep, "/")
47 self.relative_target_header_path = re.sub(r"(.*?)\.(.*?)\.meta", r"\g<1>.generated.\g<2>", self.relative_meta_path).replace(os.sep, "/")
48 self.file_id = f"FID_{self.module_db.module_name}_" + re.sub(r'\W+', '_', self.relative_meta_path)
49
50 # load raw data
51 raw_json: sc.JsonObject
52 with open(meta_file_path, encoding="utf-8") as f:
53 raw_json = json.load(f, object_pairs_hook=sc.json_object_pairs_hook)
54
55 # extract cpp types
56 unique_dict = raw_json.unique_dict()
57 records = unique_dict["records"].unique_dict()
58 functions = unique_dict["functions"]
59 enums = unique_dict["enums"].unique_dict()
60
61 # load records
62 for (record_name, record_data) in records.items():
63 record = cpp.Record(record_name)
64 record.load_from_raw_json(record_data)
65 self.records.append(record)
66 self.__name_to_record[record.name] = record
67
68 # load functions
69 for function_data in functions:
70 function = cpp.Function()
71 function.load_from_raw_json(function_data)
72 self.functions.append(function)

Callers 1

loadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected