@@ -451,21 +451,8 @@ class program
451
451
static program create_with_source_file (const std::string &file,
452
452
const context &context)
453
453
{
454
- // open file stream
455
- std::ifstream stream (file.c_str ());
456
-
457
- if (stream.fail ()){
458
- BOOST_THROW_EXCEPTION (std::ios_base::failure (" failed to create stream." ));
459
- }
460
-
461
- // read source
462
- std::string source (
463
- (std::istreambuf_iterator<char >(stream)),
464
- std::istreambuf_iterator<char >()
465
- );
466
-
467
454
// create program
468
- return create_with_source (source , context);
455
+ return create_with_source (read_source_file (file) , context);
469
456
}
470
457
471
458
// / Creates a new program with \p files in \p context.
@@ -704,6 +691,22 @@ class program
704
691
return prog;
705
692
}
706
693
694
+ // / Create a new program with \p file in \p context and builds it with \p options.
695
+ /* *
696
+ * In case BOOST_COMPUTE_USE_OFFLINE_CACHE macro is defined,
697
+ * the compiled binary is stored for reuse in the offline cache located in
698
+ * $HOME/.boost_compute on UNIX-like systems and in %APPDATA%/boost_compute
699
+ * on Windows.
700
+ */
701
+ static program build_with_source_file (
702
+ const std::string &file,
703
+ const context &context,
704
+ const std::string &options = std::string()
705
+ )
706
+ {
707
+ return build_with_source (read_source_file (file), context, options);
708
+ }
709
+
707
710
private:
708
711
#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
709
712
// Saves program binaries for future reuse.
@@ -745,6 +748,22 @@ class program
745
748
}
746
749
#endif // BOOST_COMPUTE_USE_OFFLINE_CACHE
747
750
751
+ static std::string read_source_file (const std::string &file)
752
+ {
753
+ // open file stream
754
+ std::ifstream stream (file.c_str ());
755
+
756
+ if (stream.fail ()){
757
+ BOOST_THROW_EXCEPTION (std::ios_base::failure (" failed to create stream." ));
758
+ }
759
+
760
+ // read source
761
+ return std::string (
762
+ (std::istreambuf_iterator<char >(stream)),
763
+ std::istreambuf_iterator<char >()
764
+ );
765
+ }
766
+
748
767
private:
749
768
cl_program m_program;
750
769
};
0 commit comments