MCPcopy Create free account
hub / github.com/carbonengine/trinity / Open

Method Open

shadercompiler/CachingIncludeHandler.cpp:88–176  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Loads an included file. Arguments: fileName - File name to include (can be relative to parent path) parentData - Contents of the parent file as returned by a previous call to Open; used for resolving relative paths rootPath - Custom root path for resolving relative paths ----------------------------

Source from the content-addressed store, hash-verified

86// rootPath - Custom root path for resolving relative paths
87// --------------------------------------------------------------------------------------
88std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::Open( const char* fileName, const char* parentData, const char* rootPath )
89{
90 std::lock_guard scope( m_cs );
91
92 std::string fullPath;
93 if( PathIsRelative( fileName ) )
94 {
95 std::string parentPath;
96 if( parentData == nullptr )
97 {
98 parentPath = rootPath ? rootPath : m_rootPath;
99 }
100 else
101 {
102 auto parent = m_pathFromFile.find( parentData - 1 );
103 if( parent != m_pathFromFile.end() )
104 {
105 parentPath = parent->second;
106 }
107 else
108 {
109 parentPath = "";
110 }
111 }
112 if( auto joined = JoinPath( parentPath.c_str(), fileName ) )
113 {
114 fullPath = *joined;
115 }
116 else
117 {
118 return std::nullopt;
119 }
120 }
121 else
122 {
123 fullPath = fileName;
124 }
125 auto fileFromPath = m_fileFromPath.find( fullPath );
126 if( fileFromPath != m_fileFromPath.end() )
127 {
128 return fileFromPath->second;
129 }
130
131 IncludedFile info;
132 info.fullPath = fullPath;
133
134 FILE* file = nullptr;
135 fopen_s( &file, fullPath.c_str(), "rb" );
136 if( !file )
137 {
138 return std::nullopt;
139 }
140
141 size_t fileSize = 0;
142 struct stat buf;
143 if( stat( fullPath.c_str(), &buf ) == 0 )
144 {
145 info.modifiedTime = buf.st_mtime;

Callers 5

LoadFromDiskMethod · 0.80
GetSourceHashFunction · 0.80
PrintPermutationsFunction · 0.80
mainFunction · 0.80
IncludeFileMethod · 0.80

Calls 6

PathIsRelativeFunction · 0.85
JoinPathFunction · 0.85
fopen_sFunction · 0.85
statClass · 0.85
GetDirPathFunction · 0.85
endMethod · 0.45

Tested by

no test coverage detected