@@ -451,21 +451,8 @@ class program
451451 static program create_with_source_file (const std::string &file,
452452 const context &context)
453453 {
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-
467454 // create program
468- return create_with_source (source , context);
455+ return create_with_source (read_source_file (file) , context);
469456 }
470457
471458 // / Creates a new program with \p files in \p context.
@@ -704,6 +691,22 @@ class program
704691 return prog;
705692 }
706693
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+
707710private:
708711#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
709712 // Saves program binaries for future reuse.
@@ -745,6 +748,22 @@ class program
745748 }
746749#endif // BOOST_COMPUTE_USE_OFFLINE_CACHE
747750
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+
748767private:
749768 cl_program m_program;
750769};
0 commit comments