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

Method AddPrefix

shadercompiler/CachingIncludeHandler.cpp:178–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::AddPrefix( const char* fileName, const char* prefix )
179{
180 std::lock_guard scope( m_cs );
181
182 std::string fullPath;
183 if( PathIsRelative( fileName ) )
184 {
185 if( auto joined = JoinPath( "", fileName ) )
186 {
187 fullPath = *joined;
188 }
189 else
190 {
191 return std::nullopt;
192 }
193 }
194 else
195 {
196 fullPath = fileName;
197 }
198 FileFromPath::iterator fileFromPath = m_fileFromPath.find( fullPath );
199 if( fileFromPath == m_fileFromPath.end() )
200 {
201 return std::nullopt;
202 }
203
204 auto& info = fileFromPath->second;
205 auto length = strlen( prefix );
206 auto data = malloc( info.size + length + 2 );
207 if( data == NULL )
208 {
209 return std::nullopt;
210 }
211 *static_cast<char*>( data ) = '\n';
212 memcpy( static_cast<char*>( data ) + 1, prefix, length );
213 memcpy( static_cast<char*>( data ) + 1 + length, info.data, info.size + 1 );
214 info.size += length;
215
216 m_pathFromFile[data] = m_pathFromFile[info.data - 1];
217 m_pathFromFile.erase( info.data - 1 );
218 free( (void*)( info.data - 1 ) );
219 info.data = static_cast<const char*>( data ) + 1;
220
221 return info;
222}
223
224// --------------------------------------------------------------------------------------
225// Description:

Callers 1

mainFunction · 0.80

Calls 3

PathIsRelativeFunction · 0.85
JoinPathFunction · 0.85
endMethod · 0.45

Tested by

no test coverage detected