MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / load_source

Function load_source

deps/GraphBLAS/CUDA/jitify.hpp:554–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552static const std::map<std::string, std::string>& get_jitsafe_headers_map();
553
554inline bool load_source(
555 std::string filename, std::map<std::string, std::string>& sources,
556 std::string current_dir = "",
557 std::vector<std::string> include_paths = std::vector<std::string>(),
558 file_callback_type file_callback = 0,
559 std::map<std::string, std::string>* fullpaths = nullptr,
560 bool search_current_dir = true) {
561 std::istream* source_stream = 0;
562 std::stringstream string_stream;
563 std::ifstream file_stream;
564 // First detect direct source-code string ("my_program\nprogram_code...")
565 size_t newline_pos = filename.find("\n");
566 if (newline_pos != std::string::npos) {
567 std::string source = filename.substr(newline_pos + 1);
568 filename = filename.substr(0, newline_pos);
569 string_stream << source;
570 source_stream = &string_stream;
571 }
572 if (sources.count(filename)) {
573 // Already got this one
574 return true;
575 }
576 if (!source_stream) {
577 std::string fullpath = path_join(current_dir, filename);
578 // Try loading from callback
579 if (!file_callback ||
580 !(source_stream = file_callback(fullpath, string_stream))) {
581#if JITIFY_ENABLE_EMBEDDED_FILES
582 // Try loading as embedded file
583 EmbeddedData embedded;
584 std::string source;
585 try {
586 source.assign(embedded.begin(fullpath), embedded.end(fullpath));
587 string_stream << source;
588 source_stream = &string_stream;
589 } catch (std::runtime_error const&)
590#endif // JITIFY_ENABLE_EMBEDDED_FILES
591 {
592 // Try loading from filesystem
593 bool found_file = false;
594 if (search_current_dir) {
595 file_stream.open(fullpath.c_str());
596 if (file_stream) {
597 source_stream = &file_stream;
598 found_file = true;
599 }
600 }
601 // Search include directories
602 if (!found_file) {
603 for (int i = 0; i < (int)include_paths.size(); ++i) {
604 fullpath = path_join(include_paths[i], filename);
605 file_stream.open(fullpath.c_str());
606 if (file_stream) {
607 source_stream = &file_stream;
608 found_file = true;
609 break;
610 }
611 }

Callers 1

load_programFunction · 0.85

Calls 7

path_joinFunction · 0.85
path_simplifyFunction · 0.85
hash_larson64Function · 0.85
split_stringFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected