MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / commit

Method commit

src/attributes.cpp:1897–1934  ·  view source on GitHub ↗

Commit the stream -- is a no-op if the existing code is identical to the generated code. Returns true if data was written and false if it wasn't (throws exception on io error)

Source from the content-addressed store, hash-verified

1895 // to the generated code. Returns true if data was written and false
1896 // if it wasn't (throws exception on io error)
1897 bool ExportsGenerator::commit(const std::string& preamble) {
1898
1899 // get the generated code
1900 std::string code = codeStream_.str();
1901
1902 // if there is no generated code AND the exports file does not
1903 // currently exist then do nothing
1904 if (code.empty() && !FileInfo(targetFile_).exists())
1905 return false; // #nocov
1906
1907 // write header/preamble
1908 std::ostringstream headerStream;
1909 headerStream << commentPrefix_ << " Generated by using "
1910 << "Rcpp::compileAttributes()"
1911 << " -> do not edit by hand" << std::endl;
1912 headerStream << commentPrefix_ << " Generator token: "
1913 << generatorToken() << std::endl << std::endl;
1914 if (!preamble.empty())
1915 headerStream << preamble;
1916
1917 // get generated code and only write it if there was a change
1918 std::string generatedCode = headerStream.str() + code;
1919 if (generatedCode != existingCode_) {
1920 // open the file
1921 std::ofstream ofs(targetFile_.c_str(),
1922 std::ofstream::out | std::ofstream::trunc);
1923 if (ofs.fail())
1924 throw Rcpp::file_io_error(targetFile_); // #nocov
1925
1926 // write generated code and return
1927 ofs << generatedCode;
1928 ofs.close();
1929 return true;
1930 }
1931 else {
1932 return false; // #nocov
1933 }
1934 }
1935
1936 // Remove the generated file entirely
1937 bool ExportsGenerator::remove() {

Callers 1

compileAttributesFunction · 0.80

Calls 12

FileInfoClass · 0.85
file_io_errorClass · 0.85
initializeGlobalsFunction · 0.85
createDirectoryFunction · 0.85
removeFunction · 0.85
emptyMethod · 0.45
existsMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected